[C++-sig] MSVC calling conventions __stdcall, __fastcall, __cdecl and Boost Python

David Abrahams dave at boost-consulting.com
Tue Apr 22 20:01:17 CEST 2003


"Jeff Brewer" <jeff at brewer.com> writes:

> I am trying to wrap a library that contains methods and functions that
> use explicit calling conventions (__stdcall, __fastcall, __cdecl). My
> example is this:
>
> #include <boost/python.hpp>
> using namespace boost::python;
>
> int __stdcall f()
> {
> 	return 0;
> }
>
> class dog
> {
> public:
> 	int __stdcall f() { return 0; }
> };
>
> BOOST_PYTHON_MODULE(test)
> {
> 	def("f",&f);
>
> 	class_<dog>("dog")
> 		.def("f", &dog::f)
> 	;
> }
>
> Apparently, MSVC treats a int (__stdcall *)() as a totally different
> type than int (*)() type. 

Yup.

> To make this work in Boost.Python, I added some get_signature
> function templates, I added a couple templates to the
> member_function_cast.hpp file and also updated Boost's type_traits
> module to recognize int (__stdcall dog::*)() as a valid member
> function pointer. All of this stuff has ifdef BOOST_MSVC's around
> it.
>
> I guess I have two questions. One, is there any way to tell if I missed
> anything 

Try more examples.  You could try tweaking all of the files in
libs/python/test to use __stdcall somewhere.

> or is there another way of wrapping my functions besides writing
> manual wrappers

There are other wrapping systems ;-)

> (my example seems to compile and run)? Two, does it make sense to
> incorporate changes like these into Boost and Boost.Python? 

Yes, definitely.  It would also be good to handle __fastcall and
extern "C" functions.

> This is very compiler specific stuff, but it seems like anyone
> wrapping Windows APIs or DLLs that use explicit calling conventions
> would run into this problem (I haven't been reading this group very
> long, so forgive me if this topic has already been covered).  I'd be
> happy to contribute my templates.

We have a precedent for this kind of stuff already; see
http://www.boost.org/libs/bind/mem_fn.html#stdcall.  I'd love to see
it handled the same way.

> p.s. I haven't been using Boost Python very long, but I am constantly
> amazed at how well it works and from what little I know about how it
> works (my brain hurts from looking through the template definitions
:).

Mine too :)

> I also appreciate the help on this mailing list.

You're welcome!

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list