Commit 735abadd authored by Segev Finer's avatar Segev Finer Committed by Serhiy Storchaka

bpo-16865: Support arrays >=2GB in ctypes. (GH-3006)

parent d063b84d
import unittest import unittest
from test.support import bigmemtest, _2G
import sys
from ctypes import * from ctypes import *
from ctypes.test import need_symbol from ctypes.test import need_symbol
...@@ -181,5 +183,10 @@ class ArrayTestCase(unittest.TestCase): ...@@ -181,5 +183,10 @@ class ArrayTestCase(unittest.TestCase):
_type_ = c_int _type_ = c_int
_length_ = 1.87 _length_ = 1.87
@unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
@bigmemtest(size=_2G, memuse=1, dry_run=False)
def test_large_array(self, size):
c_char * size
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Support arrays >=2GiB in :mod:`ctypes`. Patch by Segev Finer.
...@@ -1390,8 +1390,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -1390,8 +1390,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
StgDictObject *stgdict; StgDictObject *stgdict;
StgDictObject *itemdict; StgDictObject *itemdict;
PyObject *length_attr, *type_attr; PyObject *length_attr, *type_attr;
long length; Py_ssize_t length;
int overflow;
Py_ssize_t itemsize, itemalign; Py_ssize_t itemsize, itemalign;
/* create the new instance (which is a class, /* create the new instance (which is a class,
...@@ -1413,14 +1412,15 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -1413,14 +1412,15 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_XDECREF(length_attr); Py_XDECREF(length_attr);
goto error; goto error;
} }
length = PyLong_AsLongAndOverflow(length_attr, &overflow); length = PyLong_AsSsize_t(length_attr);
if (overflow) { Py_DECREF(length_attr);
PyErr_SetString(PyExc_OverflowError, if (length == -1 && PyErr_Occurred()) {
"The '_length_' attribute is too large"); if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
Py_DECREF(length_attr); PyErr_SetString(PyExc_OverflowError,
"The '_length_' attribute is too large");
}
goto error; goto error;
} }
Py_DECREF(length_attr);
type_attr = PyObject_GetAttrString((PyObject *)result, "_type_"); type_attr = PyObject_GetAttrString((PyObject *)result, "_type_");
if (!type_attr) { if (!type_attr) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment