[Python-checkins] python/dist/src/Objects listobject.c,2.105,2.106
nnorwitz@sourceforge.net
nnorwitz@sourceforge.net
Wed, 22 May 2002 16:19:19 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv21543/Objects
Modified Files:
listobject.c
Log Message:
Closes: #556025 seg fault when doing list(xrange(1e9))
A MemoryError is now raised when the list cannot be created.
There is a test, but as the comment says, it really only
works for 32 bit systems. I don't know how to improve
the test for other systems (ie, 64 bit or systems
where the data size != addressable size,
e.g. 64 bit data, but 48 bit addressable memory)
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.105
retrieving revision 2.106
diff -C2 -d -r2.105 -r2.106
*** listobject.c 12 Apr 2002 02:43:59 -0000 2.105
--- listobject.c 22 May 2002 23:19:16 -0000 2.106
***************
*** 45,49 ****
}
! #define NRESIZE(var, type, nitems) PyMem_RESIZE(var, type, roundupsize(nitems))
PyObject *
--- 45,56 ----
}
! #define NRESIZE(var, type, nitems) \
! do { \
! size_t _new_size = roundupsize(nitems); \
! if (_new_size <= ((~(size_t)0) / sizeof(type))) \
! PyMem_RESIZE(var, type, _new_size); \
! else \
! var = NULL; \
! } while (0)
PyObject *
***************
*** 1566,1571 ****
n = 8; /* arbitrary */
NRESIZE(result->ob_item, PyObject*, n);
! if (result->ob_item == NULL)
goto error;
for (i = 0; i < n; i++)
result->ob_item[i] = NULL;
--- 1573,1580 ----
n = 8; /* arbitrary */
NRESIZE(result->ob_item, PyObject*, n);
! if (result->ob_item == NULL) {
! PyErr_NoMemory();
goto error;
+ }
for (i = 0; i < n; i++)
result->ob_item[i] = NULL;