diff --git a/src/types.cpp b/src/types.cpp index fe108225..c7e1f167 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -566,18 +566,12 @@ bool add_capability_richcompare(type_object_base::capability capability, PyTypeO 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_base::capability capability, PyTypeObjec 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_base::capability capability, PyTypeObjec ENABLE_INPLACE_CAPABILITY (inplace_and); ENABLE_INPLACE_CAPABILITY (inplace_or); ENABLE_INPLACE_CAPABILITY (inplace_xor); +#endif default: return false; } diff --git a/test/comprehensive.py b/test/comprehensive.py index b4ae5679..c49a4add 100644 --- a/test/comprehensive.py +++ b/test/comprehensive.py @@ -334,7 +334,8 @@ Special member attributes. Tests courtesy of Barry Scott >> 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 +1070,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 @@ -1226,6 +1190,50 @@ test methodologies for wrapping functions that return a pointer ''' #' +__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 * # pickle requires these derived classes to be