From c3bd0fcbad03d3432fb65b7a68dc5c58640c0d1f Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 12 Oct 2006 09:07:07 +0000 Subject: [PATCH] Make object comparison operators return object instead of bool, to accomodate strange beasts like numarray arrays that return arrays that can't be used as truth values from their comparison ops. Fix numpy test for portability with old doctest (again!) [SVN r35572] --- doc/v2/object.html | 12 ++++++------ include/boost/python/object_operators.hpp | 16 ++++++++-------- src/object_operators.cpp | 18 ++++++++++++++++++ test/slice.cpp | 1 + 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/doc/v2/object.html b/doc/v2/object.html index 10be8757..a8913c70 100644 --- a/doc/v2/object.html +++ b/doc/v2/object.html @@ -854,12 +854,12 @@ void del(proxy<T> const& x);
 
-template<class L,class R> bool operator>(L const&l,R const&r);
-template<class L,class R> bool operator>=(L const&l,R const&r);
-template<class L,class R> bool operator<(L const&l,R const&r);
-template<class L,class R> bool operator<=(L const&l,R const&r);
-template<class L,class R> bool operator==(L const&l,R const&r);
-template<class L,class R> bool operator!=(L const&l,R const&r);
+template<class L,class R> object operator>(L const&l,R const&r);
+template<class L,class R> object operator>=(L const&l,R const&r);
+template<class L,class R> object operator<(L const&l,R const&r);
+template<class L,class R> object operator<=(L const&l,R const&r);
+template<class L,class R> object operator==(L const&l,R const&r);
+template<class L,class R> object operator!=(L const&l,R const&r);
 
diff --git a/include/boost/python/object_operators.hpp b/include/boost/python/object_operators.hpp index 0515309b..f27f88f8 100644 --- a/include/boost/python/object_operators.hpp +++ b/include/boost/python/object_operators.hpp @@ -73,17 +73,11 @@ object_operators::operator!() const # define BOOST_PYTHON_COMPARE_OP(op, opid) \ template \ -BOOST_PYTHON_BINARY_RETURN(bool) operator op(L const& l, R const& r) \ +BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \ { \ - return PyObject_RichCompareBool( \ + return PyObject_RichCompare( \ object(l).ptr(), object(r).ptr(), opid); \ } -BOOST_PYTHON_COMPARE_OP(>, Py_GT) -BOOST_PYTHON_COMPARE_OP(>=, Py_GE) -BOOST_PYTHON_COMPARE_OP(<, Py_LT) -BOOST_PYTHON_COMPARE_OP(<=, Py_LE) -BOOST_PYTHON_COMPARE_OP(==, Py_EQ) -BOOST_PYTHON_COMPARE_OP(!=, Py_NE) # undef BOOST_PYTHON_COMPARE_OP # define BOOST_PYTHON_BINARY_OPERATOR(op) \ @@ -93,6 +87,12 @@ BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \ { \ return object(l) op object(r); \ } +BOOST_PYTHON_BINARY_OPERATOR(>) +BOOST_PYTHON_BINARY_OPERATOR(>=) +BOOST_PYTHON_BINARY_OPERATOR(<) +BOOST_PYTHON_BINARY_OPERATOR(<=) +BOOST_PYTHON_BINARY_OPERATOR(==) +BOOST_PYTHON_BINARY_OPERATOR(!=) BOOST_PYTHON_BINARY_OPERATOR(+) BOOST_PYTHON_BINARY_OPERATOR(-) BOOST_PYTHON_BINARY_OPERATOR(*) diff --git a/src/object_operators.cpp b/src/object_operators.cpp index 5d8ffd6a..b6f1c5fb 100644 --- a/src/object_operators.cpp +++ b/src/object_operators.cpp @@ -8,6 +8,24 @@ namespace boost { namespace python { namespace api { +# define BOOST_PYTHON_COMPARE_OP(op, opid) \ +BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \ +{ \ + return object( \ + detail::new_reference( \ + PyObject_RichCompare( \ + l.ptr(), r.ptr(), opid)) \ + ); \ +} +BOOST_PYTHON_COMPARE_OP(>, Py_GT) +BOOST_PYTHON_COMPARE_OP(>=, Py_GE) +BOOST_PYTHON_COMPARE_OP(<, Py_LT) +BOOST_PYTHON_COMPARE_OP(<=, Py_LE) +BOOST_PYTHON_COMPARE_OP(==, Py_EQ) +BOOST_PYTHON_COMPARE_OP(!=, Py_NE) +# undef BOOST_PYTHON_COMPARE_OP + + #define BOOST_PYTHON_BINARY_OPERATOR(op, name) \ BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \ { \ diff --git a/test/slice.cpp b/test/slice.cpp index f28e38f5..ebf2afa1 100644 --- a/test/slice.cpp +++ b/test/slice.cpp @@ -1,3 +1,4 @@ +Warning: No xauth data; using fake authentication data for X11 forwarding. #include #include #include