]> granicus.if.org Git - python/commitdiff
Add PyObject_Not().
authorGuido van Rossum <guido@python.org>
Thu, 9 Apr 1998 17:53:59 +0000 (17:53 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 9 Apr 1998 17:53:59 +0000 (17:53 +0000)
Include/abstract.h
Include/object.h
Objects/object.c

index 975c562280aa4f15415171c09065578f0c70bcf9..3491724e318231285894aadcb174e59125e68dde 100644 (file)
@@ -382,6 +382,18 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
         
        */
 
+     /* Implemented elsewhere:
+
+     int PyObject_Not(PyObject *o);
+
+        Returns 0 if the object, o, is considered to be true, and
+        1 otherwise. This is equivalent to the Python expression:
+        not o
+
+        This function always succeeds.
+        
+       */
+
      PyObject *PyObject_Type Py_PROTO((PyObject *o));
 
        /*
index f2a83d79709ecfd688769cac3f5e6078a7720d91..18cca9f4d411be1b66324d00b3a2cd0e67b52682 100644 (file)
@@ -271,6 +271,7 @@ extern int PyObject_SetAttr Py_PROTO((PyObject *, PyObject *, PyObject *));
 extern int PyObject_HasAttr Py_PROTO((PyObject *, PyObject *));
 extern long PyObject_Hash Py_PROTO((PyObject *));
 extern int PyObject_IsTrue Py_PROTO((PyObject *));
+extern int PyObject_Not Py_PROTO((PyObject *));
 extern int PyCallable_Check Py_PROTO((PyObject *));
 extern int PyNumber_Coerce Py_PROTO((PyObject **, PyObject **));
 extern int PyNumber_CoerceEx Py_PROTO((PyObject **, PyObject **));
index 0de095f7491a72182910b27d9c47662a7f9c3489..aa73740c99fe007e3d79431b6601e71c5dd3e41a 100644 (file)
@@ -470,6 +470,20 @@ PyObject_IsTrue(v)
        return res;
 }
 
+/* equivalent of 'not v' 
+   Return -1 if an error occurred */
+
+int
+PyObject_Not(v)
+       PyObject *v;
+{
+       int res;
+       res = PyObject_IsTrue(v);
+       if (res < 0)
+               return res;
+       return res == 0;
+}
+
 /* Coerce two numeric types to the "larger" one.
    Increment the reference count on each argument.
    Return -1 and raise an exception if no coercion is possible