From 2eef5b513edd17e12e15df7f797b1ac7aed77b07 Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Tue, 10 Sep 2019 02:22:12 -0700 Subject: 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. --- numpy/core/_internal.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'numpy') 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): """ -- cgit v1.2.1