Skip to content

Commit 05239ce

Browse files
committed
wrap the nb_bool inquiry to return Py_True or Py_False
1 parent 7d5e366 commit 05239ce

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

graalpython/com.oracle.graal.python.cext/src/typeobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ static PyObject* wrap_objobjproc(objobjproc f, PyObject* a, PyObject* b) {
140140

141141
static PyObject* wrap_inquiry(inquiry f, PyObject* a) {
142142
return PyLong_FromLong(f(a));
143+
144+
static PyObject* wrap_nb_bool(inquiry f, PyObject* a) {
145+
return f(a) ? Py_True : Py_False;
143146
}
144147

145148
/* very special case: operator '**' has an optional third arg */
@@ -363,7 +366,7 @@ int PyType_Ready(PyTypeObject* cls) {
363366
ADD_SLOT("__neg__", numbers->nb_negative, -1);
364367
ADD_SLOT("__pos__", numbers->nb_positive, -1);
365368
ADD_SLOT("__abs__", numbers->nb_absolute, -1);
366-
ADD_SLOT_CONV("__bool__", wrap_inquiry, numbers->nb_bool, -1);
369+
ADD_SLOT_CONV("__bool__", wrap_nb_bool, numbers->nb_bool, -1);
367370
ADD_SLOT("__invert__", numbers->nb_invert, -1);
368371
ADD_SLOT("__lshift__", numbers->nb_lshift, -2);
369372
ADD_SLOT("__rshift__", numbers->nb_rshift, -2);

0 commit comments

Comments
 (0)