Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59247 - in trunk: boost/python boost/python/object libs/python/doc/v2 libs/python/test libs/spirit/example/qi libs/utility/test
From: dave_at_[hidden]
Date: 2010-01-23 21:08:47


Author: dave
Date: 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
New Revision: 59247
URL: http://svn.boost.org/trac/boost/changeset/59247

Log:
Support different MS calling conventions, thanks to Nicolas Lelong.
Closes #3833.

Text files modified:
   trunk/boost/python/object/make_instance.hpp | 2
   trunk/boost/python/object/pointer_holder.hpp | 11 +++-
   trunk/boost/python/signature.hpp | 83 ++++++++++++++++++++++++++++++++++++---
   trunk/libs/python/doc/v2/configuration.html | 27 +++++++++++++
   trunk/libs/python/test/Jamfile.v2 | 4 +
   trunk/libs/spirit/example/qi/mini_xml1.cpp | 8 ++-
   trunk/libs/utility/test/Jamfile.v2 | 1
   7 files changed, 122 insertions(+), 14 deletions(-)

Modified: trunk/boost/python/object/make_instance.hpp
==============================================================================
--- trunk/boost/python/object/make_instance.hpp (original)
+++ trunk/boost/python/object/make_instance.hpp 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -21,7 +21,7 @@
     template <class Arg>
     static inline PyObject* execute(Arg& x)
     {
- BOOST_STATIC_ASSERT(is_class<T>::value);
+ BOOST_MPL_ASSERT((mpl::or_<is_class<T>, is_union<T> >));
 
         PyTypeObject* type = Derived::get_class_object(x);
 

Modified: trunk/boost/python/object/pointer_holder.hpp
==============================================================================
--- trunk/boost/python/object/pointer_holder.hpp (original)
+++ trunk/boost/python/object/pointer_holder.hpp 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -35,6 +35,8 @@
 
 # include <boost/detail/workaround.hpp>
 
+# include <boost/type_traits/remove_const.hpp>
+
 namespace boost { namespace python {
 
 template <class T> class wrapper;
@@ -122,26 +124,29 @@
 template <class Pointer, class Value>
 void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
 {
+ typedef typename boost::remove_const< Value >::type non_const_value;
+
     if (dst_t == python::type_id<Pointer>()
         && !(null_ptr_only && get_pointer(this->m_p))
     )
         return &this->m_p;
 
- Value* p
+ Value* p0
 # if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
         = static_cast<Value*>( get_pointer(this->m_p) )
 # else
         = get_pointer(this->m_p)
 # endif
         ;
-
+ non_const_value* p = const_cast<non_const_value*>( p0 );
+
     if (p == 0)
         return 0;
     
     if (void* wrapped = holds_wrapped(dst_t, p, p))
         return wrapped;
     
- type_info src_t = python::type_id<Value>();
+ type_info src_t = python::type_id<non_const_value>();
     return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
 }
 

Modified: trunk/boost/python/signature.hpp
==============================================================================
--- trunk/boost/python/signature.hpp (original)
+++ trunk/boost/python/signature.hpp 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -52,16 +52,23 @@
 //
 // template <class RT, class T0... class TN>
 // inline mpl::vector<RT, T0...TN>
-// get_signature(RT(*)(T0...TN), void* = 0)
+// get_signature(RT(BOOST_PYTHON_FN_CC *)(T0...TN), void* = 0)
 // {
 // return mpl::list<RT, T0...TN>();
 // }
 //
+// where BOOST_PYTHON_FN_CC is a calling convention keyword, can be
+//
+// empty, for default calling convention
+// __cdecl (if BOOST_PYTHON_ENABLE_CDECL is defined)
+// __stdcall (if BOOST_PYTHON_ENABLE_STDCALL is defined)
+// __fastcall (if BOOST_PYTHON_ENABLE_FASTCALL is defined)
+//
 // And, for an appropriate assortment of cv-qualifications::
 //
 // template <class RT, class ClassT, class T0... class TN>
 // inline mpl::vector<RT, ClassT&, T0...TN>
-// get_signature(RT(ClassT::*)(T0...TN) cv))
+// get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv))
 // {
 // return mpl::list<RT, ClassT&, T0...TN>();
 // }
@@ -72,7 +79,7 @@
 // , typename most_derived<Target, ClassT>::type&
 // , T0...TN
 // >
-// get_signature(RT(ClassT::*)(T0...TN) cv), Target*)
+// get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(T0...TN) cv), Target*)
 // {
 // return mpl::list<RT, ClassT&, T0...TN>();
 // }
@@ -87,7 +94,8 @@
 //
 // These functions extract the return type, class (for member
 // functions) and arguments of the input signature and stuff them in
-// an mpl type sequence. Note that cv-qualification is dropped from
+// an mpl type sequence (the calling convention is dropped).
+// Note that cv-qualification is dropped from
 // the "hidden this" argument of member functions; that is a
 // necessary sacrifice to ensure that an lvalue from_python converter
 // is used. A pointer is not used so that None will be rejected for
@@ -100,10 +108,64 @@
 //
 // @group {
 
+// 'default' calling convention
+
+# define BOOST_PYTHON_FN_CC
+
 # define BOOST_PP_ITERATION_PARAMS_1 \
     (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
 
 # include BOOST_PP_ITERATE()
+
+# undef BOOST_PYTHON_FN_CC
+
+// __cdecl calling convention
+
+# if defined(BOOST_PYTHON_ENABLE_CDECL)
+
+# define BOOST_PYTHON_FN_CC __cdecl
+# define BOOST_PYTHON_FN_CC_IS_CDECL
+
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
+
+# include BOOST_PP_ITERATE()
+
+# undef BOOST_PYTHON_FN_CC
+# undef BOOST_PYTHON_FN_CC_IS_CDECL
+
+# endif // defined(BOOST_PYTHON_ENABLE_CDECL)
+
+// __stdcall calling convention
+
+# if defined(BOOST_PYTHON_ENABLE_STDCALL)
+
+# define BOOST_PYTHON_FN_CC __stdcall
+
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
+
+# include BOOST_PP_ITERATE()
+
+# undef BOOST_PYTHON_FN_CC
+
+# endif // defined(BOOST_PYTHON_ENABLE_STDCALL)
+
+// __fastcall calling convention
+
+# if defined(BOOST_PYTHON_ENABLE_FASTCALL)
+
+# define BOOST_PYTHON_FN_CC __fastcall
+
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
+
+# include BOOST_PP_ITERATE()
+
+# undef BOOST_PYTHON_FN_CC
+
+# endif // defined(BOOST_PYTHON_ENABLE_FASTCALL)
+
 # undef BOOST_PYTHON_LIST_INC
 
 // }
@@ -120,17 +182,24 @@
 
 # define N BOOST_PP_ITERATION()
 
+ // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same
+ // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)',
+ // we don't define it twice
+# if !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
+
 template <
     class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
 inline BOOST_PYTHON_LIST_INC(N)<
     RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
-get_signature(RT(*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0)
+get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = 0)
 {
     return BOOST_PYTHON_LIST_INC(N)<
             RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
>();
 }
 
+# endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
+
 # undef N
 
 # define BOOST_PP_ITERATION_PARAMS_2 \
@@ -146,7 +215,7 @@
     class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
 inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
     RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)>
-get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
+get_signature(RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q)
 {
     return BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
             RT, ClassT& BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
@@ -165,7 +234,7 @@
     BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, T)
>
 get_signature(
- RT(ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q
+ RT(BOOST_PYTHON_FN_CC ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)) Q
   , Target*
 )
 {

Modified: trunk/libs/python/doc/v2/configuration.html
==============================================================================
--- trunk/libs/python/doc/v2/configuration.html (original)
+++ trunk/libs/python/doc/v2/configuration.html 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -106,6 +106,33 @@
         function from being treated as an exported symbol on platforms which
         support that distinction in-code</td>
       </tr>
+
+ <tr>
+ <td valign="top"><code>BOOST_PYTHON_ENABLE_CDECL</code></td>
+
+ <td valign="top" align="center"><i>not&nbsp;defined</i></td>
+
+ <td valign="top">If defined, allows functions using the <code>__cdecl
+ </code> calling convention to be wrapped.</td>
+ </tr>
+
+ <tr>
+ <td valign="top"><code>BOOST_PYTHON_ENABLE_STDCALL</code></td>
+
+ <td valign="top" align="center"><i>not&nbsp;defined</i></td>
+
+ <td valign="top">If defined, allows functions using the <code>__stdcall
+ </code> calling convention to be wrapped.</td>
+ </tr>
+
+ <tr>
+ <td valign="top"><code>BOOST_PYTHON_ENABLE_FASTCALL</code></td>
+
+ <td valign="top" align="center"><i>not&nbsp;defined</i></td>
+
+ <td valign="top">If defined, allows functions using the <code>__fastcall
+ </code> calling convention to be wrapped.</td>
+ </tr>
     </table>
 
     <h2><a name="lib-defined-impl"></a>Library Defined Implementation

Modified: trunk/libs/python/test/Jamfile.v2
==============================================================================
--- trunk/libs/python/test/Jamfile.v2 (original)
+++ trunk/libs/python/test/Jamfile.v2 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -184,6 +184,9 @@
 # bpl-test bienstman5 ;
 # }
 
+[ bpl-test calling_conventions ]
+[ bpl-test calling_conventions_mf ]
+
 # --- unit tests of library components ---
 
 [ compile indirect_traits_test.cpp ]
@@ -196,6 +199,7 @@
 
 [ compile string_literal.cpp ]
 [ py-compile borrowed.cpp ]
+[ py-compile union.cpp ]
 [ py-compile object_manager.cpp ]
 [ py-compile copy_ctor_mutates_rhs.cpp ]
 

Modified: trunk/libs/spirit/example/qi/mini_xml1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml1.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml1.cpp 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -18,6 +18,7 @@
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_fusion.hpp>
 #include <boost/spirit/include/phoenix_stl.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
 #include <boost/fusion/include/adapt_struct.hpp>
 #include <boost/variant/recursive_variant.hpp>
 #include <boost/foreach.hpp>
@@ -138,6 +139,7 @@
         {
             using qi::lit;
             using qi::lexeme;
+ using qi::raw;
             using ascii::char_;
             using ascii::string;
             using namespace qi::labels;
@@ -145,13 +147,13 @@
             using phoenix::at_c;
             using phoenix::push_back;
 
- text = lexeme[+(char_ - '<') [_val += _1]];
+ text %= lexeme[+(char_ - '<') ] ; // [_val = phoenix::construct<std::string>(begin(_1),end(_1))];
             node = (xml | text) [_val = _1];
 
- start_tag =
+ start_tag %=
                     '<'
>> !lit('/')
- >> lexeme[+(char_ - '>') [_val += _1]]
+ >> raw[lexeme[+(char_ - '>')]]
>> '>'
             ;
 

Modified: trunk/libs/utility/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/test/Jamfile.v2 (original)
+++ trunk/libs/utility/test/Jamfile.v2 2010-01-23 21:08:46 EST (Sat, 23 Jan 2010)
@@ -25,6 +25,7 @@
         [ run ../iterators_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
         [ run next_prior_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
         [ compile-fail ../noncopyable_test.cpp ]
+ [ run noncopyable_adl_barrier.cpp ]
         [ run ../numeric_traits_test.cpp ]
         [ run ../operators_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
         [ compile ../ref_ct_test.cpp ]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk