diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-10-15 23:24:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-15 23:24:33 +0300 |
commit | 96f32207285423ee14341c2b16e99a46c6da3728 (patch) | |
tree | 16ac874afb9a25693c0f44add0146d1dd98bdd72 /numpy/core/tests | |
parent | 4e11da37bf94a0f496f236e9706205ac81683058 (diff) | |
parent | 53dd7d6a706f5d9e93b41f714b46c6d32b085aec (diff) | |
download | numpy-96f32207285423ee14341c2b16e99a46c6da3728.tar.gz |
Merge pull request #14469 from sunqm/master
BUG: Fix _ctypes class circular reference. (#13808)
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 9b124f603..596707581 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -7975,6 +7975,8 @@ class TestFormat(object): dst = object.__format__(a, '30') assert_equal(res, dst) +from numpy.testing import IS_PYPY + class TestCTypes(object): def test_ctypes_is_available(self): @@ -8041,7 +8043,29 @@ class TestCTypes(object): # but when the `ctypes_ptr` object dies, so should `arr` del ctypes_ptr + if IS_PYPY: + # Pypy does not recycle arr objects immediately. Trigger gc to + # release arr. Cpython uses refcounts. An explicit call to gc + # should not be needed here. + break_cycles() + assert_(arr_ref() is None, "unknowable whether ctypes pointer holds a reference") + + def test_ctypes_as_parameter_holds_reference(self): + arr = np.array([None]).copy() + + arr_ref = weakref.ref(arr) + + ctypes_ptr = arr.ctypes._as_parameter_ + + # `ctypes_ptr` should hold onto `arr` + del arr break_cycles() + assert_(arr_ref() is not None, "ctypes pointer did not hold onto a reference") + + # but when the `ctypes_ptr` object dies, so should `arr` + del ctypes_ptr + if IS_PYPY: + break_cycles() assert_(arr_ref() is None, "unknowable whether ctypes pointer holds a reference") |