]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/calling_conventions_mf.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / python / test / calling_conventions_mf.cpp
1 //
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
5 //
6 // Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
7 //
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)
11 //
12
13 #if !defined(TEST_INCLUDE_RECURSION)
14
15 #define TEST_INCLUDE_RECURSION
16
17 //------------------------------------------------------------------------------
18 // this section is the main body of the test extension module
19
20 #if defined(_WIN32) && !defined(_WIN64)
21 # define BOOST_PYTHON_ENABLE_CDECL
22 # define BOOST_PYTHON_ENABLE_STDCALL
23 # define BOOST_PYTHON_ENABLE_FASTCALL
24 #endif
25 #include <boost/preprocessor/cat.hpp>
26 #include <boost/preprocessor/stringize.hpp>
27 #include <boost/python.hpp>
28 using namespace boost::python;
29
30 // first define test functions for every calling convention
31
32 #define TEST_DECLARE_FUNCTIONS
33
34 #define TESTED_CALLING_CONVENTION __cdecl
35 #include "calling_conventions_mf.cpp"
36 #undef TESTED_CALLING_CONVENTION
37
38 #define TESTED_CALLING_CONVENTION __stdcall
39 #include "calling_conventions_mf.cpp"
40 #undef TESTED_CALLING_CONVENTION
41
42 #define TESTED_CALLING_CONVENTION __fastcall
43 #include "calling_conventions_mf.cpp"
44 #undef TESTED_CALLING_CONVENTION
45
46 #undef TEST_DECLARE_FUNCTIONS
47
48 // then create a module wrapping the defined functions for every calling convention
49
50 BOOST_PYTHON_MODULE( calling_conventions_mf_ext )
51 {
52
53 #define TEST_WRAP_FUNCTIONS
54
55 #define TESTED_CALLING_CONVENTION __cdecl
56 #include "calling_conventions_mf.cpp"
57 #undef TESTED_CALLING_CONVENTION
58
59 #define TESTED_CALLING_CONVENTION __stdcall
60 #include "calling_conventions_mf.cpp"
61 #undef TESTED_CALLING_CONVENTION
62
63 #define TESTED_CALLING_CONVENTION __fastcall
64 #include "calling_conventions_mf.cpp"
65 #undef TESTED_CALLING_CONVENTION
66
67 #undef TEST_WRAP_FUNCTIONS
68
69 }
70
71 #else // !defined(TEST_INCLUDE_RECURSION)
72
73 //------------------------------------------------------------------------------
74 // this section defines the functions to be wrapped
75
76 # if defined(TEST_DECLARE_FUNCTIONS)
77
78 # if !defined(TESTED_CALLING_CONVENTION)
79 # error "One calling convention must be defined"
80 # endif // !defined(TESTED_CALLING_CONVENTION)
81
82 namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION) {
83
84 struct X
85 {
86 mutable unsigned int hash;
87
88 X(): hash(0) {}
89
90 void TESTED_CALLING_CONVENTION f0() { f1(17); }
91 void TESTED_CALLING_CONVENTION g0() const { g1(17); }
92
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; }
95
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); }
98
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); }
101
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); }
104
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); }
107
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); }
110
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); }
113
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); }
116 };
117
118 } // namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)
119
120 # endif // defined(TEST_DECLARE_FUNCTIONS)
121
122 //------------------------------------------------------------------------------
123 // this section wraps the functions
124
125 # if defined(TEST_WRAP_FUNCTIONS)
126
127 # if !defined(TESTED_CALLING_CONVENTION)
128 # error "One calling convention must be defined"
129 # endif // !defined(TESTED_CALLING_CONVENTION)
130
131 {
132
133 typedef BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::X X;
134
135 class_<X>("X" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION))
136 .def("f0", &X::f0)
137 .def("g0", &X::g0)
138 .def("f1", &X::f1)
139 .def("g1", &X::g1)
140 .def("f2", &X::f2)
141 .def("g2", &X::g2)
142 .def("f3", &X::f3)
143 .def("g3", &X::g3)
144 .def("f4", &X::f4)
145 .def("g4", &X::g4)
146 .def("f5", &X::f5)
147 .def("g5", &X::g5)
148 .def("f6", &X::f6)
149 .def("g6", &X::g6)
150 .def("f7", &X::f7)
151 .def("g7", &X::g7)
152 .def("f8", &X::f8)
153 .def("g8", &X::g8)
154 .def_readonly("hash", &X::hash)
155 ;
156
157 }
158
159 # endif // defined(TEST_WRAP_FUNCTIONS)
160
161 #endif // !defined(TEST_INCLUDE_RECURSION)