import unittest
+from test.support import precisionbigmemtest, _2G
+import sys
from ctypes import *
from ctypes.test import need_symbol
t2 = my_int * 1
self.assertIs(t1, t2)
+ @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+ @precisionbigmemtest(size=_2G, memuse=1, dry_run=False)
+ def test_large_array(self, size):
+ a = c_char * size
+
if __name__ == '__main__':
unittest.main()
PyTypeObject *result;
StgDictObject *stgdict;
StgDictObject *itemdict;
- PyObject *proto;
+ PyObject *proto, *length_attr;
PyObject *typedict;
- long length;
-
+ Py_ssize_t length;
Py_ssize_t itemsize, itemalign;
typedict = PyTuple_GetItem(args, 2);
if (!typedict)
return NULL;
- proto = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
- if (!proto || !PyInt_Check(proto)) {
+ length_attr = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
+ if (!length_attr || !_PyAnyInt_Check(length_attr)) {
PyErr_SetString(PyExc_AttributeError,
"class must define a '_length_' attribute, "
"which must be a positive integer");
return NULL;
}
- length = PyInt_AS_LONG(proto);
+ if (PyInt_Check(length_attr)) {
+ length = PyInt_AS_LONG(length_attr);
+ }
+ else {
+ assert(PyLong_Check(length_attr));
+ length = PyLong_AsSsize_t(length_attr);
+ if (length == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "The '_length_' attribute is too large");
+ }
+ return NULL;
+ }
+ }
proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
if (!proto) {