summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorJim Fulton <jim@zope.com>2004-07-14 19:07:35 (GMT)
committerJim Fulton <jim@zope.com>2004-07-14 19:07:35 (GMT)
commit8c5aeaa2770c958414c0785229a5e038ed97a234 (patch)
treebc24fe9776943d84418c44a8c5ca0e2bb1e6c53c /Include
parent7a0e8bc283590c1db93cbb313650a959d8cc1f31 (diff)
downloadcpython-8c5aeaa2770c958414c0785229a5e038ed97a234.zip
cpython-8c5aeaa2770c958414c0785229a5e038ed97a234.tar.gz
cpython-8c5aeaa2770c958414c0785229a5e038ed97a234.tar.bz2
Implemented a new Py_CLEAR macro. This macro should be used when
decrementing the refcount of variables that might be accessed as a result of calling Python
Diffstat (limited to 'Include')
-rw-r--r--Include/object.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Include/object.h b/Include/object.h
index 555d810..60cf146 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -620,6 +620,15 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
else \
_Py_Dealloc((PyObject *)(op))
+#define Py_CLEAR(op) \
+ do { \
+ if (op) { \
+ PyObject *tmp = (op); \
+ (op) = NULL; \
+ Py_DECREF(tmp); \
+ } \
+ } while (0)
+
/* Macros to use in case the object pointer may be NULL: */
#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)