Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/ctypes/test/test_arrays.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import unittest
from test.support import bigmemtest, _2G
import sys
from ctypes import *

from ctypes.test import need_symbol
Expand Down Expand Up @@ -181,5 +183,10 @@ class T(Array):
_type_ = c_int
_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__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support arrays >=2GiB in :mod:`ctypes`. Patch by Segev Finer.
16 changes: 8 additions & 8 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
StgDictObject *stgdict;
StgDictObject *itemdict;
PyObject *length_attr, *type_attr;
long length;
int overflow;
Py_ssize_t length;
Py_ssize_t itemsize, itemalign;

/* create the new instance (which is a class,
Expand All @@ -1415,14 +1414,15 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_XDECREF(length_attr);
goto error;
}
length = PyLong_AsLongAndOverflow(length_attr, &overflow);
if (overflow) {
PyErr_SetString(PyExc_OverflowError,
"The '_length_' attribute is too large");
Py_DECREF(length_attr);
length = PyLong_AsSsize_t(length_attr);
Py_DECREF(length_attr);
if (length == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_SetString(PyExc_OverflowError,
"The '_length_' attribute is too large");
}
goto error;
}
Py_DECREF(length_attr);

type_attr = PyObject_GetAttrString((PyObject *)result, "_type_");
if (!type_attr) {
Expand Down