summaryrefslogtreecommitdiff
path: root/numpy/tests
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2018-12-16 10:50:05 -0800
committerAnthony Sottile <asottile@umich.edu>2018-12-16 12:24:05 -0800
commitcec59cc17025352a4159172dbe5077e30eee01a1 (patch)
tree4d4a95bac7313ec7dbc5a790135b51ce499ed335 /numpy/tests
parentc52543e4a7d2ab5d1ae4be7364c51965dc4fdb9e (diff)
downloadnumpy-cec59cc17025352a4159172dbe5077e30eee01a1.tar.gz
BUG: fix segfault in ctypeslib with obj being collected
- https://bugs.python.org/issue35507 - https://stackoverflow.com/q/53757856/812183
Diffstat (limited to 'numpy/tests')
-rw-r--r--numpy/tests/test_ctypeslib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py
index 53b75db07..d389b37a8 100644
--- a/numpy/tests/test_ctypeslib.py
+++ b/numpy/tests/test_ctypeslib.py
@@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function
import sys
import pytest
+import weakref
import numpy as np
from numpy.ctypeslib import ndpointer, load_library, as_array
@@ -260,3 +261,15 @@ class TestAsArray(object):
b = np.ctypeslib.as_array(newpnt, (N,))
# now delete both, which should cleanup both objects
del newpnt, b
+
+ def test_segmentation_fault(self):
+ arr = np.zeros((224, 224, 3))
+ c_arr = np.ctypeslib.as_ctypes(arr)
+ arr_ref = weakref.ref(arr)
+ del arr
+
+ # check the reference wasn't cleaned up
+ assert_(arr_ref() is not None)
+
+ # check we avoid the segfault
+ c_arr[0][0][0]