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
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 @@
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)