Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3d3f96

Browse files
committed
Add PyObject_Not().
1 parent 6b529ae commit c3d3f96

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

Include/abstract.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
382382
383383
*/
384384

385+
/* Implemented elsewhere:
386+
387+
int PyObject_Not(PyObject *o);
388+
389+
Returns 0 if the object, o, is considered to be true, and
390+
1 otherwise. This is equivalent to the Python expression:
391+
not o
392+
393+
This function always succeeds.
394+
395+
*/
396+
385397
PyObject *PyObject_Type Py_PROTO((PyObject *o));
386398

387399
/*

Include/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ extern int PyObject_SetAttr Py_PROTO((PyObject *, PyObject *, PyObject *));
271271
extern int PyObject_HasAttr Py_PROTO((PyObject *, PyObject *));
272272
extern long PyObject_Hash Py_PROTO((PyObject *));
273273
extern int PyObject_IsTrue Py_PROTO((PyObject *));
274+
extern int PyObject_Not Py_PROTO((PyObject *));
274275
extern int PyCallable_Check Py_PROTO((PyObject *));
275276
extern int PyNumber_Coerce Py_PROTO((PyObject **, PyObject **));
276277
extern int PyNumber_CoerceEx Py_PROTO((PyObject **, PyObject **));

Objects/object.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,20 @@ PyObject_IsTrue(v)
470470
return res;
471471
}
472472

473+
/* equivalent of 'not v'
474+
Return -1 if an error occurred */
475+
476+
int
477+
PyObject_Not(v)
478+
PyObject *v;
479+
{
480+
int res;
481+
res = PyObject_IsTrue(v);
482+
if (res < 0)
483+
return res;
484+
return res == 0;
485+
}
486+
473487
/* Coerce two numeric types to the "larger" one.
474488
Increment the reference count on each argument.
475489
Return -1 and raise an exception if no coercion is possible

0 commit comments

Comments
 (0)