Boost logo

Boost :

From: scott snyder (snyder_at_[hidden])
Date: 2001-12-15 17:31:09


>Scott, could you submit a patch that checks the appropriate python version
>macros in the right places? I'd appreciate it lots!

Ok, i think this should do it. Sorry about that.
Tested now with both py 1.5.2 and 2.1.

This patch also fixes a preexisting problem with comprehensive.py that
showed up when i tried to test with 1.5.2: it uses sys.version_info,
but that name isn't present in 1.5.2.

Index: libs/python/src/types.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/python/src/types.cpp,v
retrieving revision 1.6
diff -u -p -r1.6 types.cpp
--- libs/python/src/types.cpp 2001/12/13 18:20:21 1.6
+++ libs/python/src/types.cpp 2001/12/15 22:03:54
@@ -566,18 +566,12 @@ bool add_capability_richcompare(type_obj
     return false;
 }
 
-#if PYTHON_API_VERSION >= 1010
-# define ENABLE_INPLACE_CAPABILITY1 \
- dest->tp_flags |= Py_TPFLAGS_HAVE_INPLACEOPS;
-#else
-# define ENABLE_INPLACE_CAPABILITY1
-#endif
 #define ENABLE_INPLACE_CAPABILITY(field) \
     case type_object_base::number_##field: \
         create_method_table_if_null(dest->tp_as_number); \
         dest->tp_as_number->nb_##field = &do_instance_nb_##field; \
         detail::shared_pod_manager::replace_if_equal(dest->tp_as_number); \
- ENABLE_INPLACE_CAPABILITY1 \
+ dest->tp_flags |= Py_TPFLAGS_HAVE_INPLACEOPS; \
         return true
 
 bool add_capability_inplace(type_object_base::capability capability, PyTypeObject* dest)
@@ -585,6 +579,7 @@ bool add_capability_inplace(type_object_
     assert(dest != 0);
     switch (capability)
     {
+#if PYTHON_API_VERSION >= 1010
         ENABLE_INPLACE_CAPABILITY (inplace_add);
         ENABLE_INPLACE_CAPABILITY (inplace_subtract);
         ENABLE_INPLACE_CAPABILITY (inplace_multiply);
@@ -596,6 +591,7 @@ bool add_capability_inplace(type_object_
         ENABLE_INPLACE_CAPABILITY (inplace_and);
         ENABLE_INPLACE_CAPABILITY (inplace_or);
         ENABLE_INPLACE_CAPABILITY (inplace_xor);
+#endif
         default:
             return false;
     }
Index: libs/python/test/comprehensive.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/python/test/comprehensive.cpp,v
retrieving revision 1.13
diff -u -p -r1.13 comprehensive.cpp
--- libs/python/test/comprehensive.cpp 2001/12/13 18:22:03 1.13
+++ libs/python/test/comprehensive.cpp 2001/12/15 22:04:03
@@ -1093,6 +1113,7 @@ void init_module(boost::python::module_b
     // export non-operator function as heterogeneous reverse-argument operator
     int_class.def(&rmul, "__rmul__");
 
+#if PYTHON_API_VERSION >= 1010
     // inplace operators.
     int_class.def(&int_iadd, "__iadd__");
     int_class.def(&int_isub, "__isub__");
@@ -1105,6 +1126,7 @@ void init_module(boost::python::module_b
     int_class.def(&int_iand, "__iand__");
     int_class.def(&int_ior, "__ior__");
     int_class.def(&int_ixor, "__ixor__");
+#endif
     
 
     boost::python::class_builder<EnumOwner> enum_owner(m, "EnumOwner");
Index: libs/python/test/comprehensive.py
===================================================================
RCS file: /cvsroot/boost/boost/libs/python/test/comprehensive.py,v
retrieving revision 1.12
diff -u -p -r1.12 comprehensive.py
--- libs/python/test/comprehensive.py 2001/12/13 18:23:10 1.12
+++ libs/python/test/comprehensive.py 2001/12/15 22:04:10
@@ -334,7 +342,8 @@ Special member attributes. Tests courtes
     'Docs for DerivedFromBase.fred'
 
>>> import sys
- >>> if sys.version_info[0] < 2 or ( sys.version_info[0] == 2 and
+ >>> if not sys.__dict__.has_key('version_info') or \
+ ... sys.version_info[0] < 2 or ( sys.version_info[0] == 2 and
     ... sys.version_info[1] < 2 ):
     ... assert dir(df) == []
     ... assert dir(db) == []
@@ -1069,43 +1078,6 @@ test inheritB2
     Traceback (innermost last):
     TypeError: bad operand type(s) for pow()
 
- >>> ii = Int(1)
- >>> ii += Int(2)
- >>> ii.i()
- 3
- >>> ii -= Int(1)
- >>> ii.i()
- 2
- >>> ii *= Int(3)
- >>> ii.i()
- 6
- >>> ii /= Int(2)
- >>> ii.i()
- 3
- >>> ii <<= Int(2)
- >>> ii.i()
- 12
- >>> ii >>= Int(1)
- >>> ii.i()
- 6
- >>> ii &= Int(5)
- >>> ii.i()
- 4
- >>> ii |= Int(9)
- >>> ii.i()
- 13
- >>> ii ^= Int(7)
- >>> ii.i()
- 10
- >>> ii %= Int(4)
- >>> ii.i()
- 2
- >>> ii **= Int(3)
- >>> ii.i()
- 8
- >>> ii.j()
- 11
-
 Test operator export to a subclass
 
     # force method table sharing
@@ -1225,6 +1197,50 @@ test methodologies for wrapping function
 
 '''
 #'
+
+__test__ = {}
+import sys
+
+# Inplace ops only exist in python 2.1 or later.
+if sys.hexversion >= 0x02010000:
+ __test__['inplacetests'] = r'''
+ >>> ii = Int(1)
+ >>> ii += Int(2)
+ >>> ii.i()
+ 3
+ >>> ii -= Int(1)
+ >>> ii.i()
+ 2
+ >>> ii *= Int(3)
+ >>> ii.i()
+ 6
+ >>> ii /= Int(2)
+ >>> ii.i()
+ 3
+ >>> ii <<= Int(2)
+ >>> ii.i()
+ 12
+ >>> ii >>= Int(1)
+ >>> ii.i()
+ 6
+ >>> ii &= Int(5)
+ >>> ii.i()
+ 4
+ >>> ii |= Int(9)
+ >>> ii.i()
+ 13
+ >>> ii ^= Int(7)
+ >>> ii.i()
+ 10
+ >>> ii %= Int(4)
+ >>> ii.i()
+ 2
+ >>> ii **= Int(3)
+ >>> ii.i()
+ 8
+ >>> ii.j()
+ 11
+'''
 
 from boost_python_test import *
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk