summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2019-08-28 10:01:41 +0300
committermattip <matti.picus@gmail.com>2019-08-28 12:06:05 +0300
commit2accb7cd375f2500b2106167a73d5f452dd60993 (patch)
tree14069426fef9d7fa03b96905486c79cd9d1f8a57 /numpy
parente82544b3ec1badfacda016fdbdd96410efda9376 (diff)
downloadnumpy-2accb7cd375f2500b2106167a73d5f452dd60993.tar.gz
BUG: test, fix regression in converting to ctypes
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_regression.py7
-rw-r--r--numpy/ctypeslib.py15
2 files changed, 16 insertions, 6 deletions
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index c5289f6ac..ce0df2695 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -2500,3 +2500,10 @@ class TestRegression(object):
t = T()
#gh-13659, would raise in broadcasting [x=t for x in result]
np.array([t])
+
+ def test_to_ctypes(self):
+ #gh-14214
+ arr = np.zeros((2 ** 31 + 1,), 'b')
+ assert(arr.size * arr.itemsize > 2 ** 31)
+ c_arr = np.ctypeslib.as_ctypes(arr)
+ assert_equal(c_arr._length_, arr.size)
diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py
index e49f8394f..e7c5c78d3 100644
--- a/numpy/ctypeslib.py
+++ b/numpy/ctypeslib.py
@@ -92,11 +92,11 @@ else:
# Adapted from Albert Strasheim
def load_library(libname, loader_path):
"""
- It is possible to load a library using
+ It is possible to load a library using
>>> lib = ctypes.cdll[<full_path_name>] # doctest: +SKIP
But there are cross-platform considerations, such as library file extensions,
- plus the fact Windows will just load the first library it finds with that name.
+ plus the fact Windows will just load the first library it finds with that name.
NumPy supplies the load_library function as a convenience.
Parameters
@@ -110,12 +110,12 @@ else:
Returns
-------
ctypes.cdll[libpath] : library object
- A ctypes library object
+ A ctypes library object
Raises
------
OSError
- If there is no library with the expected extension, or the
+ If there is no library with the expected extension, or the
library is defective and cannot be loaded.
"""
if ctypes.__version__ < '1.0.1':
@@ -535,7 +535,10 @@ if ctypes is not None:
if readonly:
raise TypeError("readonly arrays unsupported")
- dtype = _dtype((ai["typestr"], ai["shape"]))
- result = as_ctypes_type(dtype).from_address(addr)
+ # can't use `_dtype((ai["typestr"], ai["shape"]))` here, as it overflows
+ # dtype.itemsize (gh-14214)
+ ctype_scalar = as_ctypes_type(ai["typestr"])
+ result_type = _ctype_ndarray(ctype_scalar , ai['shape'])
+ result = result_type.from_address(addr)
result.__keep = obj
return result