@@ -41,11 +41,28 @@ T pylong_as(PyObject* obj) {
4141 return PyLong_AsLong (obj);
4242 } else if constexpr (std::is_same_v<T, long long >) {
4343 return PyLong_AsLongLong (obj);
44+ } else if constexpr (std::is_same_v<T, unsigned long >) {
45+ return PyLong_AsUnsignedLong (obj);
46+ } else if constexpr (std::is_same_v<T, unsigned long long >) {
47+ return PyLong_AsUnsignedLongLong (obj);
4448 } else {
4549 static_assert (!sizeof (T*), " pylong_as<T> not implemented for given T" );
4650 }
4751}
4852
53+ template <typename T>
54+ T pylong_as_overflow_and (PyObject* obj, int * overflow) {
55+ if constexpr (std::is_same_v<T, int >) {
56+ return pylong_as_int (obj);
57+ } else if constexpr (std::is_same_v<T, long >) {
58+ return PyLong_AsLongAndOverflow (obj, overflow);
59+ } else if constexpr (std::is_same_v<T, long long >) {
60+ return PyLong_AsLongLongAndOverflow (obj, overflow);
61+ } else {
62+ static_assert (!sizeof (T*), " pylong_as_overflow_and<T> not implemented for given T" );
63+ }
64+ }
65+
4966template <typename T>
5067struct PythonWrapper {
5168 PyObject_HEAD
@@ -75,6 +92,21 @@ void pywrapper_dealloc(PyObject* self) {
7592 Py_TYPE (self)->tp_free (self);
7693}
7794
95+ template <typename T>
96+ PyObject* pywrapper_richcompare_via_operator_equals (PyObject* self, PyObject* other, int op) {
97+ if (!PyObject_TypeCheck (self, &T::pytype) || !PyObject_TypeCheck (other, &T::pytype))
98+ return Py_NewRef (Py_NotImplemented);
99+
100+ T& a = py_unwrap<T>(self);
101+ T& b = py_unwrap<T>(other);
102+
103+ switch (op) {
104+ case Py_EQ: return Py_NewRef (a == b ? Py_True : Py_False);
105+ case Py_NE: return Py_NewRef (a == b ? Py_False : Py_True);
106+ default : return Py_NewRef (Py_NotImplemented);
107+ }
108+ }
109+
78110struct OK_t {};
79111struct ErrorRaised_t {};
80112
0 commit comments