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

jandem at codespeak.net jandem at codespeak.net
Sat Mar 20 19:35:06 CET 2010


Author: jandem
Date: Sat Mar 20 19:35:04 2010
New Revision: 72468

Modified:
   pypy/trunk/pypy/module/cpyext/floatobject.py
   pypy/trunk/pypy/module/cpyext/include/boolobject.h
   pypy/trunk/pypy/module/cpyext/test/test_boolobject.py
Log:
Add Py_RETURN_{TRUE,FALSE} macros and fix style


Modified: pypy/trunk/pypy/module/cpyext/floatobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/floatobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/floatobject.py	Sat Mar 20 19:35:04 2010
@@ -1,5 +1,5 @@
 from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import cpython_api, PyObject, make_ref
+from pypy.module.cpyext.api import cpython_api, PyObject
 
 @cpython_api([lltype.Float], PyObject)
 def PyFloat_FromDouble(space, value):

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 19:35:04 2010
@@ -7,13 +7,16 @@
 extern "C" {
 #endif
 
-
 extern PyObject *PyPy_True;
 #define Py_True PyPy_True
 
 extern PyObject *PyPy_False;
 #define Py_False PyPy_False
 
+/* Macros for returning Py_True or Py_False, respectively */
+#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
+#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
+
 #ifdef __cplusplus
 }
 #endif

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 19:35:04 2010
@@ -11,23 +11,21 @@
             Py_InitModule("foo", methods);
         """
         body = """
-        static PyObject* foo_GetTrue(PyObject* self, PyObject *args)
+        static PyObject* foo_get_true(PyObject* self, PyObject *args)
         {
-            Py_INCREF(Py_True);
-            return Py_True;
+            Py_RETURN_TRUE;
         }
-        static PyObject* foo_GetFalse(PyObject* self, PyObject *args)
+        static PyObject* foo_get_false(PyObject* self, PyObject *args)
         {
-            Py_INCREF(Py_False);
-            return Py_False;
+            Py_RETURN_FALSE;
         }
         static PyMethodDef methods[] = {
-            { "GetTrue", foo_GetTrue, METH_NOARGS },
-            { "GetFalse", foo_GetFalse, METH_NOARGS },
+            { "get_true", foo_get_true, METH_NOARGS },
+            { "get_false", foo_get_false, METH_NOARGS },
             { NULL }
         };
         """
         module = self.import_module(name='foo', init=init, body=body)
         assert 'foo' in sys.modules
-        assert module.GetTrue() == True
-        assert module.GetFalse() == False
+        assert module.get_true() == True
+        assert module.get_false() == False



More information about the Pypy-commit mailing list