Skip to content

Commit

Permalink
Merge pull request #3377 from neobrain/feature_thunk_flip_nullcheck_o…
Browse files Browse the repository at this point in the history
…rder

Library Forwarding: Flip order of nullptr check and custom repacking
  • Loading branch information
Sonicadvance1 committed Jan 20, 2024
2 parents 3bfb4be + fb15cf0 commit d04f3a2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ThunkLibs/include/common/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ struct repack_wrapper {
~repack_wrapper() {
// TODO: Properly detect opaque types
if constexpr (requires(guest_layout<T> t, decltype(data) h) { t.get_pointer(); (bool)h; *data; }) {
// NOTE: It's assumed that the native host library didn't modify any
// const-pointees, so we skip automatic exit repacking for them.
// However, *custom* repacking must still be applied since it might
// have unrelated side effects (such as deallocation of memory
// reserved on entry)
if (!fex_apply_custom_repacking_exit(*orig_arg.get_pointer(), *data)) {
if constexpr (!std::is_const_v<std::remove_pointer_t<T>>) { // Skip exit-repacking for const pointees
if (data) {
if (data) {
// NOTE: It's assumed that the native host library didn't modify any
// const-pointees, so we skip automatic exit repacking for them.
// However, *custom* repacking must still be applied since it
// might have unrelated side effects (such as deallocation of
// memory reserved on entry)
if (!fex_apply_custom_repacking_exit(*orig_arg.get_pointer(), *data)) {
if constexpr (!std::is_const_v<std::remove_pointer_t<T>>) { // Skip exit-repacking for const pointees
constexpr bool is_compatible = has_compatible_data_layout<T> && std::is_same_v<T, GuestT>;
if constexpr (!is_compatible && std::is_class_v<std::remove_pointer_t<T>>) {
*orig_arg.get_pointer() = to_guest(*data); // TODO: Only if annotated as out-parameter
Expand Down

0 comments on commit d04f3a2

Please sign in to comment.