Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility fixups #12977

Merged
merged 4 commits into from
Nov 26, 2022
Merged

Utility fixups #12977

merged 4 commits into from
Nov 26, 2022

Conversation

Nekotekina
Copy link
Member

@Nekotekina Nekotekina commented Nov 24, 2022

Implemented some TODOs and some new functionality: tool to avoid UB and able to replace misused reinterpret_cast and utils::bless. Done by avoiding referencing trivial objects in memory or arrays and just use memcpy on reads and writes.

Copy link
Contributor

@elad335 elad335 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a templated struct overriding operator*() for seemless transision. (returning a memory operations wrapping object) I thought about doing it in vm::ptr in the past.

@Nekotekina
Copy link
Member Author

I think vm::ref is suitable for this, with minor additions.

constexpr aref& operator=(const T& value) const
{
write_to_ptr<T>(value, m_ptr);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks

@Nekotekina Nekotekina changed the title Utility fixups [NEED TESTUtility fixups Nov 25, 2022
@Nekotekina
Copy link
Member Author

I guess I'll repurpose vm::ref in another PR

}

template <typename T, typename U>
constexpr void write_to_ptr(const T& value, U&& array, usz pos = 0)
Copy link
Contributor

@elad335 elad335 Nov 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapping argument places is more consistent with vm::writeX methods.

It can also have an overload which takes a single argument of array referece paired with index. So you can write wtite_to_ptr({array, 1}, data)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, fixed

@MSuih
Copy link
Member

MSuih commented Nov 25, 2022

Tested a handful of games, they work just fine

Doing std::bit_cast on a "span".
Should be usable in constexpr.
@Nekotekina Nekotekina merged commit fa74d3e into RPCS3:master Nov 26, 2022
@Nekotekina Nekotekina changed the title [NEED TESTUtility fixups Utility fixups Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants