[pypy-svn] r73593 - pypy/branch/cpython-extension/pypy/module/cpyext/include

jandem at codespeak.net jandem at codespeak.net
Fri Apr 9 19:23:15 CEST 2010


Author: jandem
Date: Fri Apr  9 19:23:12 2010
New Revision: 73593

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
Log:
add Py_CLEAR macro


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	Fri Apr  9 19:23:12 2010
@@ -42,6 +42,15 @@
 #define Py_XINCREF(ob)  (Py_IncRef(ob))
 #define Py_XDECREF(ob)  (Py_DecRef(ob))
 
+#define Py_CLEAR(op)				\
+        do {                            	\
+                if (op) {			\
+                        PyObject *_py_tmp = (PyObject *)(op);	\
+                        (op) = NULL;		\
+                        Py_DECREF(_py_tmp);	\
+                }				\
+        } while (0)
+
 #define Py_REFCNT(ob)		(((PyObject*)(ob))->ob_refcnt)
 #define Py_TYPE(ob)		(((PyObject*)(ob))->ob_type)
 #define Py_SIZE(ob)		(((PyVarObject*)(ob))->ob_size)



More information about the Pypy-commit mailing list