Ticket #3833: boost_python_calling_conventions.patch

File boost_python_calling_conventions.patch, 22.7 KB (added by nico_ml@…, 13 years ago)

patch file (svn diff)

  • boost/python/signature.hpp

     
    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//      }
     
    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//      }
     
    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
     
    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// }
     
    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)
     194get_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 \
     
    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)
     218get_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)
     
    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{
  • 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>
     26using 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
     48BOOST_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
     80namespace 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)
  • 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#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>
     26using 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_mf.cpp"
     34#undef TESTED_CALLING_CONVENTION
     35
     36#define TESTED_CALLING_CONVENTION __stdcall
     37#include "calling_conventions_mf.cpp"
     38#undef TESTED_CALLING_CONVENTION
     39
     40#define TESTED_CALLING_CONVENTION __fastcall
     41#include "calling_conventions_mf.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
     48BOOST_PYTHON_MODULE( calling_conventions_mf_ext )
     49{
     50
     51#define TEST_WRAP_FUNCTIONS
     52
     53#define TESTED_CALLING_CONVENTION __cdecl
     54#include "calling_conventions_mf.cpp"
     55#undef TESTED_CALLING_CONVENTION
     56
     57#define TESTED_CALLING_CONVENTION __stdcall
     58#include "calling_conventions_mf.cpp"
     59#undef TESTED_CALLING_CONVENTION
     60
     61#define TESTED_CALLING_CONVENTION __fastcall
     62#include "calling_conventions_mf.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
     80namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION) {
     81
     82struct X
     83{
     84    mutable unsigned int hash;
     85
     86    X(): hash(0) {}
     87
     88    void TESTED_CALLING_CONVENTION f0() { f1(17); }
     89    void TESTED_CALLING_CONVENTION g0() const { g1(17); }
     90
     91    void TESTED_CALLING_CONVENTION f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
     92    void TESTED_CALLING_CONVENTION g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
     93
     94    void TESTED_CALLING_CONVENTION f2(int a1, int a2) { f1(a1); f1(a2); }
     95    void TESTED_CALLING_CONVENTION g2(int a1, int a2) const { g1(a1); g1(a2); }
     96
     97    void TESTED_CALLING_CONVENTION f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
     98    void TESTED_CALLING_CONVENTION g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
     99
     100    void TESTED_CALLING_CONVENTION f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
     101    void TESTED_CALLING_CONVENTION g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
     102
     103    void TESTED_CALLING_CONVENTION f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
     104    void TESTED_CALLING_CONVENTION g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
     105
     106    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); }
     107    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); }
     108
     109    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); }
     110    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); }
     111
     112    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); }
     113    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); }
     114};
     115
     116} // namespace BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)
     117
     118# endif // defined(TEST_DECLARE_FUNCTIONS)
     119
     120//------------------------------------------------------------------------------
     121// this section wraps the functions
     122
     123# if defined(TEST_WRAP_FUNCTIONS)
     124
     125#  if !defined(TESTED_CALLING_CONVENTION)
     126#   error "One calling convention must be defined"
     127#  endif // !defined(TESTED_CALLING_CONVENTION)
     128
     129{
     130 
     131  typedef BOOST_PP_CAT(test, TESTED_CALLING_CONVENTION)::X X;
     132
     133  class_<X>("X" BOOST_PP_STRINGIZE(TESTED_CALLING_CONVENTION))
     134    .def("f0", &X::f0)
     135    .def("g0", &X::g0)
     136    .def("f1", &X::f1)
     137    .def("g1", &X::g1)
     138    .def("f2", &X::f2)
     139    .def("g2", &X::g2)
     140    .def("f3", &X::f3)
     141    .def("g3", &X::g3)
     142    .def("f4", &X::f4)
     143    .def("g4", &X::g4)
     144    .def("f5", &X::f5)
     145    .def("g5", &X::g5)
     146    .def("f6", &X::f6)
     147    .def("g6", &X::g6)
     148    .def("f7", &X::f7)
     149    .def("g7", &X::g7)
     150    .def("f8", &X::f8)
     151    .def("g8", &X::g8)
     152    .def_readonly("hash", &X::hash)
     153    ;
     154
     155}
     156
     157# endif // defined(TEST_WRAP_FUNCTIONS)
     158
     159#endif // !defined(TEST_INCLUDE_RECURSION)
  • libs/python/test/calling_conventions_mf.py

     
     1# Copyright Nicolas Lelong,  2010. Distributed under the Boost
     2# Software License, Version 1.0 (See accompanying
     3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     4"""
     5>>> from calling_conventions_mf_ext import *
     6>>> x = X__cdecl()
     7>>> x.f0()
     8>>> x.g0()
     9>>> x.f1(1)
     10>>> x.g1(1)
     11>>> x.f2(1, 2)
     12>>> x.g2(1, 2)
     13>>> x.f3(1, 2, 3)
     14>>> x.g3(1, 2, 3)
     15>>> x.f4(1, 2, 3, 4)
     16>>> x.g4(1, 2, 3, 4)
     17>>> x.f5(1, 2, 3, 4, 5)
     18>>> x.g5(1, 2, 3, 4, 5)
     19>>> x.f6(1, 2, 3, 4, 5, 6)
     20>>> x.g6(1, 2, 3, 4, 5, 6)
     21>>> x.f7(1, 2, 3, 4, 5, 6, 7)
     22>>> x.g7(1, 2, 3, 4, 5, 6, 7)
     23>>> x.f8(1, 2, 3, 4, 5, 6, 7, 8)
     24>>> x.g8(1, 2, 3, 4, 5, 6, 7, 8)
     25>>> x.hash
     262155
     27>>> x = X__stdcall()
     28>>> x.f0()
     29>>> x.g0()
     30>>> x.f1(1)
     31>>> x.g1(1)
     32>>> x.f2(1, 2)
     33>>> x.g2(1, 2)
     34>>> x.f3(1, 2, 3)
     35>>> x.g3(1, 2, 3)
     36>>> x.f4(1, 2, 3, 4)
     37>>> x.g4(1, 2, 3, 4)
     38>>> x.f5(1, 2, 3, 4, 5)
     39>>> x.g5(1, 2, 3, 4, 5)
     40>>> x.f6(1, 2, 3, 4, 5, 6)
     41>>> x.g6(1, 2, 3, 4, 5, 6)
     42>>> x.f7(1, 2, 3, 4, 5, 6, 7)
     43>>> x.g7(1, 2, 3, 4, 5, 6, 7)
     44>>> x.f8(1, 2, 3, 4, 5, 6, 7, 8)
     45>>> x.g8(1, 2, 3, 4, 5, 6, 7, 8)
     46>>> x.hash
     472155
     48>>> x = X__fastcall()
     49>>> x.f0()
     50>>> x.g0()
     51>>> x.f1(1)
     52>>> x.g1(1)
     53>>> x.f2(1, 2)
     54>>> x.g2(1, 2)
     55>>> x.f3(1, 2, 3)
     56>>> x.g3(1, 2, 3)
     57>>> x.f4(1, 2, 3, 4)
     58>>> x.g4(1, 2, 3, 4)
     59>>> x.f5(1, 2, 3, 4, 5)
     60>>> x.g5(1, 2, 3, 4, 5)
     61>>> x.f6(1, 2, 3, 4, 5, 6)
     62>>> x.g6(1, 2, 3, 4, 5, 6)
     63>>> x.f7(1, 2, 3, 4, 5, 6, 7)
     64>>> x.g7(1, 2, 3, 4, 5, 6, 7)
     65>>> x.f8(1, 2, 3, 4, 5, 6, 7, 8)
     66>>> x.g8(1, 2, 3, 4, 5, 6, 7, 8)
     67>>> x.hash
     682155
     69"""
     70
     71def run(args = None):
     72    import sys
     73    import doctest
     74
     75    if args is not None:
     76        sys.argv = args
     77    return doctest.testmod(sys.modules.get(__name__))
     78   
     79if __name__ == '__main__':
     80    print "running..."
     81    import sys
     82    status = run()[0]
     83    if (status == 0): print "Done."
     84    sys.exit(status)
  • libs/python/test/calling_conventions.py

     
     1# Copyright Nicolas Lelong,  2010. Distributed under the Boost
     2# Software License, Version 1.0 (See accompanying
     3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     4"""
     5>>> from calling_conventions_ext import *
     6>>> f_0__cdecl()
     717041
     8>>> f_1__cdecl(1)
     91
     10>>> f_2__cdecl(1, 2)
     1121
     12>>> f_3__cdecl(1, 2, 3)
     13321
     14>>> f_4__cdecl(1, 2, 3, 4)
     154321
     16>>> f_5__cdecl(1, 2, 3, 4, 5)
     1754321
     18>>> f_6__cdecl(1, 2, 3, 4, 5, 6)
     19654321
     20>>> f_7__cdecl(1, 2, 3, 4, 5, 6, 7)
     217654321
     22>>> f_8__cdecl(1, 2, 3, 4, 5, 6, 7, 8)
     2387654321
     24>>> f_9__cdecl(1, 2, 3, 4, 5, 6, 7, 8, 9)
     25987654321
     26>>> f_0__stdcall()
     2717041
     28>>> f_1__stdcall(1)
     291
     30>>> f_2__stdcall(1, 2)
     3121
     32>>> f_3__stdcall(1, 2, 3)
     33321
     34>>> f_4__stdcall(1, 2, 3, 4)
     354321
     36>>> f_5__stdcall(1, 2, 3, 4, 5)
     3754321
     38>>> f_6__stdcall(1, 2, 3, 4, 5, 6)
     39654321
     40>>> f_7__stdcall(1, 2, 3, 4, 5, 6, 7)
     417654321
     42>>> f_8__stdcall(1, 2, 3, 4, 5, 6, 7, 8)
     4387654321
     44>>> f_9__stdcall(1, 2, 3, 4, 5, 6, 7, 8, 9)
     45987654321
     46>>> f_0__fastcall()
     4717041
     48>>> f_1__fastcall(1)
     491
     50>>> f_2__fastcall(1, 2)
     5121
     52>>> f_3__fastcall(1, 2, 3)
     53321
     54>>> f_4__fastcall(1, 2, 3, 4)
     554321
     56>>> f_5__fastcall(1, 2, 3, 4, 5)
     5754321
     58>>> f_6__fastcall(1, 2, 3, 4, 5, 6)
     59654321
     60>>> f_7__fastcall(1, 2, 3, 4, 5, 6, 7)
     617654321
     62>>> f_8__fastcall(1, 2, 3, 4, 5, 6, 7, 8)
     6387654321
     64>>> f_9__fastcall(1, 2, 3, 4, 5, 6, 7, 8, 9)
     65987654321
     66"""
     67
     68def run(args = None):
     69    import sys
     70    import doctest
     71
     72    if args is not None:
     73        sys.argv = args
     74    return doctest.testmod(sys.modules.get(__name__))
     75   
     76if __name__ == '__main__':
     77    print "running..."
     78    import sys
     79    status = run()[0]
     80    if (status == 0): print "Done."
     81    sys.exit(status)
  • libs/python/test/Jamfile.v2

     
    184184#     bpl-test bienstman5 ;
    185185# }
    186186
     187[ bpl-test calling_conventions ]
     188[ bpl-test calling_conventions_mf ]
     189
    187190# --- unit tests of library components ---
    188191
    189192[ compile indirect_traits_test.cpp ]
  • libs/python/doc/v2/configuration.html

     
    106106        function from being treated as an exported symbol on platforms which
    107107        support that distinction in-code</td>
    108108      </tr>
     109
     110      <tr>
     111        <td valign="top"><code>BOOST_PYTHON_ENABLE_CDECL</code></td>
     112
     113        <td valign="top" align="center"><i>not&nbsp;defined</i></td>
     114
     115        <td valign="top">If defined, allows functions using the <code>__cdecl
     116        </code> calling convention to be wrapped.</td>
     117      </tr>
     118
     119      <tr>
     120        <td valign="top"><code>BOOST_PYTHON_ENABLE_STDCALL</code></td>
     121
     122        <td valign="top" align="center"><i>not&nbsp;defined</i></td>
     123
     124        <td valign="top">If defined, allows functions using the <code>__stdcall
     125        </code> calling convention to be wrapped.</td>
     126      </tr>
     127
     128      <tr>
     129        <td valign="top"><code>BOOST_PYTHON_ENABLE_FASTCALL</code></td>
     130
     131        <td valign="top" align="center"><i>not&nbsp;defined</i></td>
     132
     133        <td valign="top">If defined, allows functions using the <code>__fastcall
     134        </code> calling convention to be wrapped.</td>
     135      </tr>
    109136    </table>
    110137
    111138    <h2><a name="lib-defined-impl"></a>Library Defined Implementation