[pypy-commit] pypy py3.5: Update the macros Py_DECREF and similar to use the CPython 3.5 version.
arigo
pypy.commits at gmail.com
Sun Jul 2 10:25:22 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r91667:6ff399c0c8bd
Date: 2017-07-02 16:23 +0200
http://bitbucket.org/pypy/pypy/changeset/6ff399c0c8bd/
Log: Update the macros Py_DECREF and similar to use the CPython 3.5
version.
diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -37,24 +37,51 @@
#define Py_INCREF(ob) (((PyObject *)(ob))->ob_refcnt++)
#define Py_DECREF(op) \
do { \
- if (--((PyObject *)(op))->ob_refcnt != 0) \
+ PyObject *_py_decref_tmp = (PyObject *)(op); \
+ if (--(_py_decref_tmp)->ob_refcnt != 0) \
; \
else \
- _Py_Dealloc((PyObject *)(op)); \
+ _Py_Dealloc(_py_decref_tmp); \
} while (0)
-#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
-#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
+#define Py_XINCREF(op) \
+ do { \
+ PyObject *_py_xincref_tmp = (PyObject *)(op); \
+ if (_py_xincref_tmp != NULL) \
+ Py_INCREF(_py_xincref_tmp); \
+ } while (0)
+
+#define Py_XDECREF(op) \
+ do { \
+ PyObject *_py_xdecref_tmp = (PyObject *)(op); \
+ if (_py_xdecref_tmp != NULL) \
+ Py_DECREF(_py_xdecref_tmp); \
+ } while (0)
+
#endif
-#define Py_CLEAR(op) \
- do { \
- if (op) { \
- PyObject *_py_tmp = (PyObject *)(op); \
- (op) = NULL; \
- Py_DECREF(_py_tmp); \
- } \
- } while (0)
+#define Py_CLEAR(op) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ if (_py_tmp != NULL) { \
+ (op) = NULL; \
+ Py_DECREF(_py_tmp); \
+ } \
+ } while (0)
+
+#define Py_SETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = (op2); \
+ Py_DECREF(_py_tmp); \
+ } while (0)
+
+#define Py_XSETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = (op2); \
+ Py_XDECREF(_py_tmp); \
+ } while (0)
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
More information about the pypy-commit
mailing list