]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/calling_conventions.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / test / calling_conventions.cpp
1 //
2 // adapted from bind_stdcall_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 #define BOOST_PYTHON_ENABLE_CDECL
21 #define BOOST_PYTHON_ENABLE_STDCALL
22 #define BOOST_PYTHON_ENABLE_FASTCALL
23 #include <boost/preprocessor/cat.hpp>
24 #include <boost/preprocessor/stringize.hpp>
25 #include <boost/python.hpp>
26 using namespace boost::python;
27
28 // first define test functions for every calling convention
29
30 #define TEST_DECLARE_FUNCTIONS
31
32 #define TESTED_CALLING_CONVENTION __cdecl
33 #include "calling_conventions.cpp"
34 #undef TESTED_CALLING_CONVENTION
35
36 #define TESTED_CALLING_CONVENTION __stdcall
37 #include "calling_conventions.cpp"
38 #undef TESTED_CALLING_CONVENTION
39
40 #define TESTED_CALLING_CONVENTION __fastcall
41 #include "calling_conventions.cpp"
42 #undef TESTED_CALLING_CONVENTION
43
44 #undef TEST_DECLARE_FUNCTIONS
45
46 // then create a module wrapping the defined functions for every calling convention
47
48 BOOST_PYTHON_MODULE( calling_conventions_ext )
49 {
50
51 #define TEST_WRAP_FUNCTIONS
52
53 #define TESTED_CALLING_CONVENTION __cdecl
54 #include "calling_conventions.cpp"
55 #undef TESTED_CALLING_CONVENTION
56
57 #define TESTED_CALLING_CONVENTION __stdcall
58 #include "calling_conventions.cpp"
59 #undef TESTED_CALLING_CONVENTION
60
61 #define TESTED_CALLING_CONVENTION __fastcall
62 #include "calling_conventions.cpp"
63 #undef TESTED_CALLING_CONVENTION
64
65 #undef TEST_WRAP_FUNCTIONS
66
67 }
68
69 #else // !defined(TEST_INCLUDE_RECURSION)
70
71 //------------------------------------------------------------------------------
72 // this section defines the functions to be wrapped
73
74 # if defined(TEST_DECLARE_FUNCTIONS)
75
76 # if !defined(TESTED_CALLING_CONVENTION)
77 # error "One calling convention must be defined"
78 # endif // !defined(TESTED_CALLING_CONVENTION)
79
80 namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION) {
81
82 long TESTED_CALLING_CONVENTION f_0()
83 {
84 return 17041L;
85 }
86
87 long TESTED_CALLING_CONVENTION f_1(long a)
88 {
89 return a;
90 }
91
92 long TESTED_CALLING_CONVENTION f_2(long a, long b)
93 {
94 return a + 10 * b;
95 }
96
97 long TESTED_CALLING_CONVENTION f_3(long a, long b, long c)
98 {
99 return a + 10 * b + 100 * c;
100 }
101
102 long TESTED_CALLING_CONVENTION f_4(long a, long b, long c, long d)
103 {
104 return a + 10 * b + 100 * c + 1000 * d;
105 }
106
107 long TESTED_CALLING_CONVENTION f_5(long a, long b, long c, long d, long e)
108 {
109 return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
110 }
111
112 long TESTED_CALLING_CONVENTION f_6(long a, long b, long c, long d, long e, long f)
113 {
114 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
115 }
116
117 long TESTED_CALLING_CONVENTION f_7(long a, long b, long c, long d, long e, long f, long g)
118 {
119 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
120 }
121
122 long TESTED_CALLING_CONVENTION f_8(long a, long b, long c, long d, long e, long f, long g, long h)
123 {
124 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
125 }
126
127 long TESTED_CALLING_CONVENTION f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
128 {
129 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
130 }
131
132 } // namespace test##TESTED_CALLING_CONVENTION
133
134 # endif // defined(TEST_DECLARE_FUNCTIONS)
135
136 //------------------------------------------------------------------------------
137 // this section wraps the functions
138
139 # if defined(TEST_WRAP_FUNCTIONS)
140
141 # if !defined(TESTED_CALLING_CONVENTION)
142 # error "One calling convention must be defined"
143 # endif // !defined(TESTED_CALLING_CONVENTION)
144
145 def("f_0" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_0);
146 def("f_1" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_1);
147 def("f_2" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_2);
148 def("f_3" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_3);
149 def("f_4" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_4);
150 def("f_5" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_5);
151 def("f_6" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_6);
152 def("f_7" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_7);
153 def("f_8" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_8);
154 def("f_9" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_9);
155
156 # endif // defined(TEST_WRAP_FUNCTIONS)
157
158 #endif // !defined(TEST_INCLUDE_RECURSION)