@@ -52,16 +52,23 @@ struct most_derived
5252//
5353// template <class RT, class T0... class TN>
5454// inline mpl::vector<RT, T0...TN>
55- // get_signature(RT(*)(T0...TN), void* = 0)
55+ // get_signature(RT(BOOST_PYTHON_FN_CC *)(T0...TN), void* = 0)
5656// {
5757// return mpl::list<RT, T0...TN>();
5858// }
5959//
60+ // where BOOST_PYTHON_FN_CC is a calling convention keyword, can be
61+ //
62+ // empty, for default calling convention
63+ // __cdecl (if BOOST_PYTHON_ENABLE_CDECL is defined)
64+ // __stdcall (if BOOST_PYTHON_ENABLE_STDCALL is defined)
65+ // __fastcall (if BOOST_PYTHON_ENABLE_FASTCALL is defined)
66+ //
6067// And, for an appropriate assortment of cv-qualifications::
6168//
6269// template <class RT, class ClassT, class T0... class TN>
6370// inline mpl::vector<RT, ClassT&, T0...TN>
64- // get_signature(RT(ClassT::*)(T0...TN) cv))
71+ // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv))
6572// {
6673// return mpl::list<RT, ClassT&, T0...TN>();
6774// }
@@ -72,7 +79,7 @@ struct most_derived
7279// , typename most_derived<Target, ClassT>::type&
7380// , T0...TN
7481// >
75- // get_signature(RT(ClassT::*)(T0...TN) cv), Target*)
82+ // get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv), Target*)
7683// {
7784// return mpl::list<RT, ClassT&, T0...TN>();
7885// }
@@ -87,7 +94,8 @@ struct most_derived
8794//
8895// These functions extract the return type, class (for member
8996// functions) and arguments of the input signature and stuff them in
90- // an mpl type sequence. Note that cv-qualification is dropped from
97+ // an mpl type sequence (the calling convention is dropped).
98+ // Note that cv-qualification is dropped from
9199// the "hidden this" argument of member functions; that is a
92100// necessary sacrifice to ensure that an lvalue from_python converter
93101// is used. A pointer is not used so that None will be rejected for
@@ -100,10 +108,64 @@ struct most_derived
100108//
101109// @group {
102110
111+ // 'default' calling convention
112+
113+ # define BOOST_PYTHON_FN_CC
114+
103115# define BOOST_PP_ITERATION_PARAMS_1 \
104116 (3 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
105117
106118# include BOOST_PP_ITERATE()
119+
120+ # undef BOOST_PYTHON_FN_CC
121+
122+ // __cdecl calling convention
123+
124+ # if defined(BOOST_PYTHON_ENABLE_CDECL)
125+
126+ # define BOOST_PYTHON_FN_CC __cdecl
127+ # define BOOST_PYTHON_FN_CC_IS_CDECL
128+
129+ # define BOOST_PP_ITERATION_PARAMS_1 \
130+ (3 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
131+
132+ # include BOOST_PP_ITERATE()
133+
134+ # undef BOOST_PYTHON_FN_CC
135+ # undef BOOST_PYTHON_FN_CC_IS_CDECL
136+
137+ # endif // defined(BOOST_PYTHON_ENABLE_CDECL)
138+
139+ // __stdcall calling convention
140+
141+ # if defined(BOOST_PYTHON_ENABLE_STDCALL)
142+
143+ # define BOOST_PYTHON_FN_CC __stdcall
144+
145+ # define BOOST_PP_ITERATION_PARAMS_1 \
146+ (3 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
147+
148+ # include BOOST_PP_ITERATE()
149+
150+ # undef BOOST_PYTHON_FN_CC
151+
152+ # endif // defined(BOOST_PYTHON_ENABLE_STDCALL)
153+
154+ // __fastcall calling convention
155+
156+ # if defined(BOOST_PYTHON_ENABLE_FASTCALL)
157+
158+ # define BOOST_PYTHON_FN_CC __fastcall
159+
160+ # define BOOST_PP_ITERATION_PARAMS_1 \
161+ (3 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
162+
163+ # include BOOST_PP_ITERATE()
164+
165+ # undef BOOST_PYTHON_FN_CC
166+
167+ # endif // defined(BOOST_PYTHON_ENABLE_FASTCALL)
168+
107169# undef BOOST_PYTHON_LIST_INC
108170
109171// }
@@ -120,17 +182,24 @@ struct most_derived
120182
121183# define N BOOST_PP_ITERATION ()
122184
185+ // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same
186+ // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)',
187+ // we don't define it twice
188+ # if !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
189+
123190template <
124191 class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z (1 , N, class T )>
125192inline BOOST_PYTHON_LIST_INC(N)<
126193 RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1 , N, T)>
127- get_signature(RT(*)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)), void* = 0)
194+ get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)), void* = 0)
128195{
129196 return BOOST_PYTHON_LIST_INC (N)<
130197 RT BOOST_PP_ENUM_TRAILING_PARAMS_Z (1 , N, T)
131198 >();
132199}
133200
201+ # endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
202+
134203# undef N
135204
136205# define BOOST_PP_ITERATION_PARAMS_2 \
@@ -146,7 +215,7 @@ template <
146215 class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1 , N, class T )>
147216inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
148217 RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1 , N, T)>
149- get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)) Q)
218+ get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)) Q)
150219{
151220 return BOOST_PYTHON_LIST_INC (BOOST_PP_INC (N))<
152221 RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z (1 , N, T)
@@ -165,7 +234,7 @@ inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
165234 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1 , N, T)
166235>
167236get_signature(
168- RT (ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)) Q
237+ RT (BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1 , N, T)) Q
169238 , Target*
170239)
171240{
0 commit comments