[Python-checkins] python/dist/src/Objects listobject.c,2.103.6.1,2.103.6.2
nnorwitz@sourceforge.net
nnorwitz@sourceforge.net
Thu, 23 May 2002 06:02:39 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv12391/Objects
Modified Files:
Tag: release22-maint
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.103.6.1
retrieving revision 2.103.6.2
diff -C2 -d -r2.103.6.1 -r2.103.6.2
*** listobject.c 28 Mar 2002 20:36:50 -0000 2.103.6.1
--- listobject.c 23 May 2002 13:02:35 -0000 2.103.6.2
***************
*** 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;
***************
*** 1715,1719 ****
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
! _PyObject_GC_Del, /* tp_free */
};
--- 1724,1728 ----
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
! _PyObject_GC_Del, /* tp_free */
};