summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorQiming Sun <osirpt.sun@gmail.com>2019-09-10 02:22:12 -0700
committerQiming Sun <osirpt.sun@gmail.com>2019-09-10 02:22:12 -0700
commit2eef5b513edd17e12e15df7f797b1ac7aed77b07 (patch)
treea7ed5775eff727aa69b7b202edefad90a520ff48 /numpy/core
parentb42c2e3f02e6c6d0682ae148923db1b7123c5ac6 (diff)
downloadnumpy-2eef5b513edd17e12e15df7f797b1ac7aed77b07.tar.gz
BUG: Fix _ctypes class cirular reference. (#13808)
In _ctypes class, ctypes.cast() was called twice. It causes circular reference for _ctypes._data due to the CPython bug https://bugs.python.org/issue12836.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_internal.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index b0ea603e1..7ef879554 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -294,8 +294,7 @@ class _ctypes(object):
if ctypes:
self._ctypes = ctypes
# get a void pointer to the buffer, which keeps the array alive
- self._data = _get_void_ptr(array)
- assert self._data.value == ptr
+ self._data = self._ctypes.c_void_p(ptr)
else:
# fake a pointer-like object that holds onto the reference
self._ctypes = _missing_ctypes()
@@ -317,7 +316,9 @@ class _ctypes(object):
The returned pointer will keep a reference to the array.
"""
- return self._ctypes.cast(self._data, obj)
+ ptr = self._ctypes.cast(self._data, obj)
+ ptr._arr = self._arr
+ return ptr
def shape_as(self, obj):
"""