[pypy-svn] r72481 - in pypy/trunk/pypy/module/cpyext: . include test

jandem at codespeak.net jandem at codespeak.net
Sat Mar 20 23:10:11 CET 2010


Author: jandem
Date: Sat Mar 20 23:10:09 2010
New Revision: 72481

Modified:
   pypy/trunk/pypy/module/cpyext/boolobject.py
   pypy/trunk/pypy/module/cpyext/include/boolobject.h
   pypy/trunk/pypy/module/cpyext/test/test_boolobject.py
Log:
Add PyBool_Check, the last PyBool_* function.


Modified: pypy/trunk/pypy/module/cpyext/boolobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/boolobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/boolobject.py	Sat Mar 20 23:10:09 2010
@@ -1,6 +1,12 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, PyObject
 
+ at cpython_api([PyObject], rffi.INT)
+def PyBool_Check(space, w_obj):
+    if space.eq_w(space.type(w_obj), space.w_bool):
+        return 1
+    return 0
+
 @cpython_api([rffi.LONG], PyObject)
 def PyBool_FromLong(space, value):
     if value != 0:

Modified: pypy/trunk/pypy/module/cpyext/include/boolobject.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/boolobject.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/boolobject.h	Sat Mar 20 23:10:09 2010
@@ -17,6 +17,7 @@
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
 
+int PyBool_Check(PyObject*);
 PyObject* PyBool_FromLong(long);
 
 #ifdef __cplusplus

Modified: pypy/trunk/pypy/module/cpyext/test/test_boolobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_boolobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_boolobject.py	Sat Mar 20 23:10:09 2010
@@ -36,10 +36,25 @@
             }
             Py_RETURN_TRUE;
         }
+        static PyObject* foo_test_Check(PyObject* self, PyObject *args)
+        {
+            int result = 0;
+            PyObject* f = PyFloat_FromDouble(1.0);
+            
+            if(PyBool_Check(Py_True) &&
+                PyBool_Check(Py_False) &&
+                !PyBool_Check(f)) 
+            {
+                result = 1;
+            }
+            Py_DECREF(f);
+            return PyBool_FromLong(result);
+        }
         static PyMethodDef methods[] = {
             { "get_true", foo_get_true, METH_NOARGS },
             { "get_false", foo_get_false, METH_NOARGS },
             { "test_FromLong", foo_test_FromLong, METH_NOARGS },
+            { "test_Check", foo_test_Check, METH_NOARGS },
             { NULL }
         };
         """
@@ -48,3 +63,4 @@
         assert module.get_true() == True
         assert module.get_false() == False
         assert module.test_FromLong() == True
+        assert module.test_Check() == True



More information about the Pypy-commit mailing list