Skip to content

Conversation

@tristanschneider
Copy link
Contributor

Fix crash in mocked destructors in x86. Destructor mocks use union_cast to cast a member pointer to a void*. When the mock is to be called, those are pulled back out and cast to a non-member function that takes the class. Due to luck and calling convention, this happens to work, but stopped now on x86. Fix the issue by union_casting the object back to the member function it original was rather than a different non-member function. Additionally, apply the previous xcode fix to the headers so running the generation script doesn't erase it: 6b685cb

This is a simplified version of the type of casting it was doing, which works on x64 but crashes now on x86.

		TestS s;
		void (TestS::*mfc)() = &TestS::fn2;
		void* vmfc = fakeit::union_cast<void*>(mfc);
		reinterpret_cast<void(*)(TestS*)>(vmfc)(&s);

…ch] Tests "Minecraft.UnitTest.Runner" and "Vanilla.SharedTests.UnitTest.Runner" are failing in run tests step

Fix crash in mocked destructors in x86. Destructor mocks use union_cast to cast a member pointer to a void*. When the mock is to be called, those are pulled back out and cast to a non-member function that takes the class. Due to luck and calling convention, this happens to work, but stopped now on x86. Fix the issue by union_casting the object back to the member function it original was rather than a different non-member function.
Additionally, apply the previous xcode fix to the headers so running the generation script doesn't erase it:
6b685cb
static void
Assign(ArgumentsTuple<valuelist...> arg_vals, current_arg &&p, arglist&&... args) {
ParamWalker<N - 1>::template Assign(arg_vals, std::forward<arglist>(args)...);
ParamWalker<N - 1>::Assign(arg_vals, std::forward<arglist>(args)...);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is applying from the previous fix that was directly to standalone:
6b685cb

void *dtorPtr = vt.getCookie(dtorCookieIndex);
void(*method)(C *) = reinterpret_cast<void (*)(C *)>(dtorPtr);
method(c);
void(C::*method)() = union_cast<void(C::*)()>(dtorPtr);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the source of the fix, which then gets copied into all the single headers by generate_fakeit_single_header.py --all

@tristanschneider tristanschneider merged commit cf5c534 into master Oct 16, 2025
0 of 10 checks passed
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.

2 participants