2 // adapted from bind_stdcall_mf_test.cpp - test for bind.hpp + __stdcall (free functions)
3 // The purpose of this simple test is to determine if a function can be
4 // called from Python with the various existing calling conventions
6 // Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
8 // Distributed under the Boost Software License, Version 1.0. (See
9 // accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
13 #if !defined(TEST_INCLUDE_RECURSION)
15 #define TEST_INCLUDE_RECURSION
17 //------------------------------------------------------------------------------
18 // this section is the main body of the test extension module
20 #if defined(_WIN32) && !defined(_WIN64)
21 # define BOOST_PYTHON_ENABLE_CDECL
22 # define BOOST_PYTHON_ENABLE_STDCALL
23 # define BOOST_PYTHON_ENABLE_FASTCALL
25 #include <boost/preprocessor/cat.hpp>
26 #include <boost/preprocessor/stringize.hpp>
27 #include <boost/python.hpp>
28 using namespace boost::python
;
30 // first define test functions for every calling convention
32 #define TEST_DECLARE_FUNCTIONS
34 #define TESTED_CALLING_CONVENTION __cdecl
35 #include "calling_conventions_mf.cpp"
36 #undef TESTED_CALLING_CONVENTION
38 #define TESTED_CALLING_CONVENTION __stdcall
39 #include "calling_conventions_mf.cpp"
40 #undef TESTED_CALLING_CONVENTION
42 #define TESTED_CALLING_CONVENTION __fastcall
43 #include "calling_conventions_mf.cpp"
44 #undef TESTED_CALLING_CONVENTION
46 #undef TEST_DECLARE_FUNCTIONS
48 // then create a module wrapping the defined functions for every calling convention
50 BOOST_PYTHON_MODULE( calling_conventions_mf_ext
)
53 #define TEST_WRAP_FUNCTIONS
55 #define TESTED_CALLING_CONVENTION __cdecl
56 #include "calling_conventions_mf.cpp"
57 #undef TESTED_CALLING_CONVENTION
59 #define TESTED_CALLING_CONVENTION __stdcall
60 #include "calling_conventions_mf.cpp"
61 #undef TESTED_CALLING_CONVENTION
63 #define TESTED_CALLING_CONVENTION __fastcall
64 #include "calling_conventions_mf.cpp"
65 #undef TESTED_CALLING_CONVENTION
67 #undef TEST_WRAP_FUNCTIONS
71 #else // !defined(TEST_INCLUDE_RECURSION)
73 //------------------------------------------------------------------------------
74 // this section defines the functions to be wrapped
76 # if defined(TEST_DECLARE_FUNCTIONS)
78 # if !defined(TESTED_CALLING_CONVENTION)
79 # error "One calling convention must be defined"
80 # endif // !defined(TESTED_CALLING_CONVENTION)
82 namespace BOOST_PP_CAT(test
, TESTED_CALLING_CONVENTION
) {
86 mutable unsigned int hash
;
90 void TESTED_CALLING_CONVENTION
f0() { f1(17); }
91 void TESTED_CALLING_CONVENTION
g0() const { g1(17); }
93 void TESTED_CALLING_CONVENTION
f1(int a1
) { hash
= (hash
* 17041 + a1
) % 32768; }
94 void TESTED_CALLING_CONVENTION
g1(int a1
) const { hash
= (hash
* 17041 + a1
* 2) % 32768; }
96 void TESTED_CALLING_CONVENTION
f2(int a1
, int a2
) { f1(a1
); f1(a2
); }
97 void TESTED_CALLING_CONVENTION
g2(int a1
, int a2
) const { g1(a1
); g1(a2
); }
99 void TESTED_CALLING_CONVENTION
f3(int a1
, int a2
, int a3
) { f2(a1
, a2
); f1(a3
); }
100 void TESTED_CALLING_CONVENTION
g3(int a1
, int a2
, int a3
) const { g2(a1
, a2
); g1(a3
); }
102 void TESTED_CALLING_CONVENTION
f4(int a1
, int a2
, int a3
, int a4
) { f3(a1
, a2
, a3
); f1(a4
); }
103 void TESTED_CALLING_CONVENTION
g4(int a1
, int a2
, int a3
, int a4
) const { g3(a1
, a2
, a3
); g1(a4
); }
105 void TESTED_CALLING_CONVENTION
f5(int a1
, int a2
, int a3
, int a4
, int a5
) { f4(a1
, a2
, a3
, a4
); f1(a5
); }
106 void TESTED_CALLING_CONVENTION
g5(int a1
, int a2
, int a3
, int a4
, int a5
) const { g4(a1
, a2
, a3
, a4
); g1(a5
); }
108 void TESTED_CALLING_CONVENTION
f6(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
) { f5(a1
, a2
, a3
, a4
, a5
); f1(a6
); }
109 void TESTED_CALLING_CONVENTION
g6(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
) const { g5(a1
, a2
, a3
, a4
, a5
); g1(a6
); }
111 void TESTED_CALLING_CONVENTION
f7(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
) { f6(a1
, a2
, a3
, a4
, a5
, a6
); f1(a7
); }
112 void TESTED_CALLING_CONVENTION
g7(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
) const { g6(a1
, a2
, a3
, a4
, a5
, a6
); g1(a7
); }
114 void TESTED_CALLING_CONVENTION
f8(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
, int a8
) { f7(a1
, a2
, a3
, a4
, a5
, a6
, a7
); f1(a8
); }
115 void TESTED_CALLING_CONVENTION
g8(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
, int a8
) const { g7(a1
, a2
, a3
, a4
, a5
, a6
, a7
); g1(a8
); }
118 } // namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)
120 # endif // defined(TEST_DECLARE_FUNCTIONS)
122 //------------------------------------------------------------------------------
123 // this section wraps the functions
125 # if defined(TEST_WRAP_FUNCTIONS)
127 # if !defined(TESTED_CALLING_CONVENTION)
128 # error "One calling convention must be defined"
129 # endif // !defined(TESTED_CALLING_CONVENTION)
133 typedef BOOST_PP_CAT(test
, TESTED_CALLING_CONVENTION
)::X X
;
135 class_
<X
>("X" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION
))
154 .def_readonly("hash", &X::hash
)
159 # endif // defined(TEST_WRAP_FUNCTIONS)
161 #endif // !defined(TEST_INCLUDE_RECURSION)