summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2018-11-19 09:13:19 -0800
committerGitHub <noreply@github.com>2018-11-19 09:13:19 -0800
commit403d63749d0c6fe67ed9417a97d2d47de1405405 (patch)
tree54e86177f230c0b7515f1d2d434a2ae4a526b023
parentb0313792953c49629f94fcc79bf14e913ca77f36 (diff)
parentaf95739054cb3707447834861820c4231b1bc5e1 (diff)
downloadnumpy-403d63749d0c6fe67ed9417a97d2d47de1405405.tar.gz
Merge pull request #12417 from eric-wieser/ctypes-bad-errors
BUG: Fix regression on np.dtype(ctypes.c_void_p)
-rw-r--r--numpy/core/_dtype_ctypes.py14
-rw-r--r--numpy/core/tests/test_dtype.py3
2 files changed, 10 insertions, 7 deletions
diff --git a/numpy/core/_dtype_ctypes.py b/numpy/core/_dtype_ctypes.py
index 4d5191aab..0852b1ef2 100644
--- a/numpy/core/_dtype_ctypes.py
+++ b/numpy/core/_dtype_ctypes.py
@@ -66,19 +66,19 @@ def _from_ctypes_structure(t):
return np.dtype(fields, align=True)
-def dtype_from_ctypes_scalar(t):
+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_)
-def dtype_from_ctypes_union(t):
+def _from_ctypes_union(t):
formats = []
offsets = []
names = []
@@ -105,9 +105,9 @@ def dtype_from_ctypes_type(t):
elif issubclass(t, _ctypes.Structure):
return _from_ctypes_structure(t)
elif issubclass(t, _ctypes.Union):
- return dtype_from_ctypes_union(t)
- elif isinstance(t._type_, str):
- return dtype_from_ctypes_scalar(t)
+ return _from_ctypes_union(t)
+ elif isinstance(getattr(t, '_type_', None), str):
+ return _from_ctypes_scalar(t)
else:
raise NotImplementedError(
"Unknown ctypes type {}".format(t.__name__))
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_ = [