Skip to content

Commit d61909d

Browse files
committed
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]
1 parent 1755dad commit d61909d

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

doc/v2/object.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,12 @@ <h2><a name="functions"></a>Functions</h2>
854854
</dl>
855855
<pre>
856856
<a name="comparisons-spec"></a>
857-
template&lt;class L,class R&gt; bool operator&gt;(L const&amp;l,R const&amp;r);
858-
template&lt;class L,class R&gt; bool operator&gt;=(L const&amp;l,R const&amp;r);
859-
template&lt;class L,class R&gt; bool operator&lt;(L const&amp;l,R const&amp;r);
860-
template&lt;class L,class R&gt; bool operator&lt;=(L const&amp;l,R const&amp;r);
861-
template&lt;class L,class R&gt; bool operator==(L const&amp;l,R const&amp;r);
862-
template&lt;class L,class R&gt; bool operator!=(L const&amp;l,R const&amp;r);
857+
template&lt;class L,class R&gt; object operator&gt;(L const&amp;l,R const&amp;r);
858+
template&lt;class L,class R&gt; object operator&gt;=(L const&amp;l,R const&amp;r);
859+
template&lt;class L,class R&gt; object operator&lt;(L const&amp;l,R const&amp;r);
860+
template&lt;class L,class R&gt; object operator&lt;=(L const&amp;l,R const&amp;r);
861+
template&lt;class L,class R&gt; object operator==(L const&amp;l,R const&amp;r);
862+
template&lt;class L,class R&gt; object operator!=(L const&amp;l,R const&amp;r);
863863
</pre>
864864

865865
<dl class="function-semantics">

include/boost/python/object_operators.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,11 @@ object_operators<U>::operator!() const
7373

7474
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
7575
template <class L, class R> \
76-
BOOST_PYTHON_BINARY_RETURN(bool) operator op(L const& l, R const& r) \
76+
BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
7777
{ \
78-
return PyObject_RichCompareBool( \
78+
return PyObject_RichCompare( \
7979
object(l).ptr(), object(r).ptr(), opid); \
8080
}
81-
BOOST_PYTHON_COMPARE_OP(>, Py_GT)
82-
BOOST_PYTHON_COMPARE_OP(>=, Py_GE)
83-
BOOST_PYTHON_COMPARE_OP(<, Py_LT)
84-
BOOST_PYTHON_COMPARE_OP(<=, Py_LE)
85-
BOOST_PYTHON_COMPARE_OP(==, Py_EQ)
86-
BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
8781
# undef BOOST_PYTHON_COMPARE_OP
8882

8983
# define BOOST_PYTHON_BINARY_OPERATOR(op) \
@@ -93,6 +87,12 @@ BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
9387
{ \
9488
return object(l) op object(r); \
9589
}
90+
BOOST_PYTHON_BINARY_OPERATOR(>)
91+
BOOST_PYTHON_BINARY_OPERATOR(>=)
92+
BOOST_PYTHON_BINARY_OPERATOR(<)
93+
BOOST_PYTHON_BINARY_OPERATOR(<=)
94+
BOOST_PYTHON_BINARY_OPERATOR(==)
95+
BOOST_PYTHON_BINARY_OPERATOR(!=)
9696
BOOST_PYTHON_BINARY_OPERATOR(+)
9797
BOOST_PYTHON_BINARY_OPERATOR(-)
9898
BOOST_PYTHON_BINARY_OPERATOR(*)

src/object_operators.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88

99
namespace boost { namespace python { namespace api {
1010

11+
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
12+
BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \
13+
{ \
14+
return object( \
15+
detail::new_reference( \
16+
PyObject_RichCompare( \
17+
l.ptr(), r.ptr(), opid)) \
18+
); \
19+
}
20+
BOOST_PYTHON_COMPARE_OP(>, Py_GT)
21+
BOOST_PYTHON_COMPARE_OP(>=, Py_GE)
22+
BOOST_PYTHON_COMPARE_OP(<, Py_LT)
23+
BOOST_PYTHON_COMPARE_OP(<=, Py_LE)
24+
BOOST_PYTHON_COMPARE_OP(==, Py_EQ)
25+
BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
26+
# undef BOOST_PYTHON_COMPARE_OP
27+
28+
1129
#define BOOST_PYTHON_BINARY_OPERATOR(op, name) \
1230
BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \
1331
{ \

0 commit comments

Comments
 (0)