]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/calling_conventions.cpp
update sources to ceph Nautilus 14.2.1
[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 #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.cpp"
36 #undef TESTED_CALLING_CONVENTION
37
38 #define TESTED_CALLING_CONVENTION __stdcall
39 #include "calling_conventions.cpp"
40 #undef TESTED_CALLING_CONVENTION
41
42 #define TESTED_CALLING_CONVENTION __fastcall
43 #include "calling_conventions.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_ext )
51 {
52
53 #define TEST_WRAP_FUNCTIONS
54
55 #define TESTED_CALLING_CONVENTION __cdecl
56 #include "calling_conventions.cpp"
57 #undef TESTED_CALLING_CONVENTION
58
59 #define TESTED_CALLING_CONVENTION __stdcall
60 #include "calling_conventions.cpp"
61 #undef TESTED_CALLING_CONVENTION
62
63 #define TESTED_CALLING_CONVENTION __fastcall
64 #include "calling_conventions.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 long TESTED_CALLING_CONVENTION f_0()
85 {
86 return 17041L;
87 }
88
89 long TESTED_CALLING_CONVENTION f_1(long a)
90 {
91 return a;
92 }
93
94 long TESTED_CALLING_CONVENTION f_2(long a, long b)
95 {
96 return a + 10 * b;
97 }
98
99 long TESTED_CALLING_CONVENTION f_3(long a, long b, long c)
100 {
101 return a + 10 * b + 100 * c;
102 }
103
104 long TESTED_CALLING_CONVENTION f_4(long a, long b, long c, long d)
105 {
106 return a + 10 * b + 100 * c + 1000 * d;
107 }
108
109 long TESTED_CALLING_CONVENTION f_5(long a, long b, long c, long d, long e)
110 {
111 return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
112 }
113
114 long TESTED_CALLING_CONVENTION f_6(long a, long b, long c, long d, long e, long f)
115 {
116 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
117 }
118
119 long TESTED_CALLING_CONVENTION f_7(long a, long b, long c, long d, long e, long f, long g)
120 {
121 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
122 }
123
124 long TESTED_CALLING_CONVENTION f_8(long a, long b, long c, long d, long e, long f, long g, long h)
125 {
126 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
127 }
128
129 long TESTED_CALLING_CONVENTION f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
130 {
131 return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
132 }
133
134 } // namespace test##TESTED_CALLING_CONVENTION
135
136 # endif // defined(TEST_DECLARE_FUNCTIONS)
137
138 //------------------------------------------------------------------------------
139 // this section wraps the functions
140
141 # if defined(TEST_WRAP_FUNCTIONS)
142
143 # if !defined(TESTED_CALLING_CONVENTION)
144 # error "One calling convention must be defined"
145 # endif // !defined(TESTED_CALLING_CONVENTION)
146
147 def("f_0" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_0);
148 def("f_1" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_1);
149 def("f_2" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_2);
150 def("f_3" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_3);
151 def("f_4" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_4);
152 def("f_5" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_5);
153 def("f_6" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_6);
154 def("f_7" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_7);
155 def("f_8" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_8);
156 def("f_9" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION), &BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::f_9);
157
158 # endif // defined(TEST_WRAP_FUNCTIONS)
159
160 #endif // !defined(TEST_INCLUDE_RECURSION)