summaryrefslogtreecommitdiff
path: root/doc/source/user
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2017-12-07 00:09:40 +0200
committermattip <matti.picus@gmail.com>2017-12-07 00:09:40 +0200
commit1649929d28915da19c02fc14cf8408eb35833eaf (patch)
treefda1af7fb78aa2d8c57edf00330e657eb1a82d09 /doc/source/user
parent5b636c4e22014622f3e85b4630153c110444d3cd (diff)
downloadnumpy-1649929d28915da19c02fc14cf8408eb35833eaf.tar.gz
make example backward compatable
Diffstat (limited to 'doc/source/user')
-rw-r--r--doc/source/user/c-info.how-to-extend.rst11
1 files changed, 10 insertions, 1 deletions
diff --git a/doc/source/user/c-info.how-to-extend.rst b/doc/source/user/c-info.how-to-extend.rst
index 0c7f27e44..1eeb46e4f 100644
--- a/doc/source/user/c-info.how-to-extend.rst
+++ b/doc/source/user/c-info.how-to-extend.rst
@@ -605,7 +605,8 @@ Example
The following example shows how you might write a wrapper that accepts
two input arguments (that will be converted to an array) and an output
argument (that must be an array). The function returns None and
-updates the output array.
+updates the output array. Note the updated use of WRITEBACKIFCOPY semantics
+for NumPy v1.14 and above
.. code-block:: c
@@ -622,7 +623,11 @@ updates the output array.
if (arr1 == NULL) return NULL;
arr2 = PyArray_FROM_OTF(arg2, NPY_DOUBLE, NPY_IN_ARRAY);
if (arr2 == NULL) goto fail;
+ #if NPY_API_VERSION >= 0x0000000c
+ oarr = PyArray_FROM_OTF(out, NPY_DOUBLE, NPY_INOUT_ARRAY2);
+ #else
oarr = PyArray_FROM_OTF(out, NPY_DOUBLE, NPY_INOUT_ARRAY);
+ #endif
if (oarr == NULL) goto fail;
/* code that makes use of arguments */
@@ -637,7 +642,9 @@ updates the output array.
Py_DECREF(arr1);
Py_DECREF(arr2);
+ #if NPY_API_VERSION >= 0x0000000c
PyArray_ResolveWritebackIfCopy(oarr);
+ #endif
Py_DECREF(oarr);
Py_INCREF(Py_None);
return Py_None;
@@ -645,7 +652,9 @@ updates the output array.
fail:
Py_XDECREF(arr1);
Py_XDECREF(arr2);
+ #if NPY_API_VERSION >= 0x0000000c
PyArray_DiscardWritebackIfCopy(oarr);
+ #endif
Py_XDECREF(oarr);
return NULL;
}