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

[Sketch] Support for __stdcall members #194

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

OskiKervinen-MF
Copy link
Contributor

When compiling 32-bit executables, the Visual Studio compiler (MSVC) uses the calling convention ___thiscall for member functions. Since FakeIt says nothing about calling conventions, this is what it works with.

Unfortunately COM interfaces use the __stdcall convention, so FakeIt cannot be used to mock COM interfaces, because all the mock templates use the default convention. (There is no such problem in x64, because both COM and normal objects use __cdecl.)

This MR creates support for varying calling conventions, primarily focusing on my need: supporting mocking of COM interfaces.

The thing is, 32-bit is not hugely relevant in this day and age, so I cannot justify spending the time to polish this large a change to a state where it would be actually merge-worthy. The most glaring omission here is that I probably didn't add quite enough ifdefs here to make this even compile on compilers other than MSVC. I'm creating this MR more as a way to publish this sketch to the people in need of this, in #71 and #78, than with the actual belief that this would be good enough to be merged.

That being said, if the maintainer does see some fairly short path to making this a thing they would actually want in the codebase, I may get around to addressing feedback some day. I'm just explicitly unmaking the promise to do so; and acknowledging that in this day and age supporting 32-bit COM objects may not be worth the extra complexity.

Fails to compile in 32-bit mode.
Added a front stub method that uses remove_func_cv to
remove const and volatile, so the actual logic layer only needs
one copy of each case.
I used a macro to avoid copy pasting the thousand methods multiple times.
I didn't realize such a thing existed.
The changes had lost the T vs C relationship. This should make it work again.
The code before this branch was giving a T member pointer
to UniqueMethodMockContext constructor, which accepted a
C method pointer, so I presume it is safe to cast from one to the other.
They worked, because __thiscall and __cdecl are the default when
they are used at all, but it's better to be explicit.
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.

1 participant