summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-11-19 00:56:24 -0800
committerEric Wieser <wieser.eric@gmail.com>2018-11-19 00:57:20 -0800
commitaf95739054cb3707447834861820c4231b1bc5e1 (patch)
tree2a0c4477352e475bddb296f7c1e6d02feca61d68 /numpy/core
parentecaa29b9c9e7a57f5bfc66e4f57a0b5283304549 (diff)
downloadnumpy-af95739054cb3707447834861820c4231b1bc5e1.tar.gz
BUG: Fix regression on np.dtype(ctypes.c_void_p)
Historically, this always returned np.uintp - we should continue to do so, even though other pointer types have never been supported Fixes gh-12416
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_dtype_ctypes.py6
-rw-r--r--numpy/core/tests/test_dtype.py3
2 files changed, 6 insertions, 3 deletions
diff --git a/numpy/core/_dtype_ctypes.py b/numpy/core/_dtype_ctypes.py
index 54b70ac24..0852b1ef2 100644
--- a/numpy/core/_dtype_ctypes.py
+++ b/numpy/core/_dtype_ctypes.py
@@ -70,9 +70,9 @@ def _from_ctypes_scalar(t):
"""
Return the dtype type with endianness included if it's the case
"""
- if t.__ctype_be__ is t:
+ if getattr(t, '__ctype_be__', None) is t:
return np.dtype('>' + t._type_)
- elif t.__ctype_le__ is t:
+ elif getattr(t, '__ctype_le__', None) is t:
return np.dtype('<' + t._type_)
else:
return np.dtype(t._type_)
@@ -106,7 +106,7 @@ def dtype_from_ctypes_type(t):
return _from_ctypes_structure(t)
elif issubclass(t, _ctypes.Union):
return _from_ctypes_union(t)
- elif isinstance(t._type_, str):
+ elif isinstance(getattr(t, '_type_', None), str):
return _from_ctypes_scalar(t)
else:
raise NotImplementedError(
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index a39573495..8cde19612 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -807,6 +807,9 @@ class TestFromCTypes(object):
p_uint8 = ctypes.POINTER(ctypes.c_uint8)
assert_raises(TypeError, np.dtype, p_uint8)
+ def test_void_pointer(self):
+ self.check(ctypes.c_void_p, np.uintp)
+
def test_union(self):
class Union(ctypes.Union):
_fields_ = [