summaryrefslogtreecommitdiff
path: root/numpy/core/include
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2018-10-16 06:03:56 +0300
committerGitHub <noreply@github.com>2018-10-16 06:03:56 +0300
commit9af9b14dff1479c1887e6afbf86e9bb6dfed5bf4 (patch)
tree8d8629a6be05a8671a0861326bdc9aa8885e8315 /numpy/core/include
parenta1fd9da3c929d647522446c549c06f6cc60af0c0 (diff)
parent1436f1ee59e772eece00bcf344f405d18a3090f5 (diff)
downloadnumpy-9af9b14dff1479c1887e6afbf86e9bb6dfed5bf4.tar.gz
Merge pull request #12155 from eric-wieser/setref
MAINT: Move NPY_SETREF to somewhere more reusable
Diffstat (limited to 'numpy/core/include')
-rw-r--r--numpy/core/include/numpy/npy_3kcompat.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h
index 808518266..a3c69f44e 100644
--- a/numpy/core/include/numpy/npy_3kcompat.h
+++ b/numpy/core/include/numpy/npy_3kcompat.h
@@ -69,6 +69,16 @@ static NPY_INLINE int PyInt_Check(PyObject *op) {
#define Npy_EnterRecursiveCall(x) Py_EnterRecursiveCall(x)
#endif
+/* Py_SETREF was added in 3.5.2, and only if Py_LIMITED_API is absent */
+#if PY_VERSION_HEX < 0x03050200
+ #define Py_SETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = (op2); \
+ Py_DECREF(_py_tmp); \
+ } while (0)
+#endif
+
/*
* PyString -> PyBytes
*/
@@ -141,20 +151,14 @@ static NPY_INLINE int PyInt_Check(PyObject *op) {
static NPY_INLINE void
PyUnicode_ConcatAndDel(PyObject **left, PyObject *right)
{
- PyObject *newobj;
- newobj = PyUnicode_Concat(*left, right);
- Py_DECREF(*left);
+ Py_SETREF(*left, PyUnicode_Concat(*left, right));
Py_DECREF(right);
- *left = newobj;
}
static NPY_INLINE void
PyUnicode_Concat2(PyObject **left, PyObject *right)
{
- PyObject *newobj;
- newobj = PyUnicode_Concat(*left, right);
- Py_DECREF(*left);
- *left = newobj;
+ Py_SETREF(*left, PyUnicode_Concat(*left, right));
}
/*