python/dist/src/Objects listobject.c,2.212,2.213

Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21484 Modified Files: listobject.c Log Message: * Simplify and speed-up list_resize(). Relying on the newly documented invariants allows the ob_item != NULL check to be replaced with an assertion. * Added assertions to list_init() which document and verify that the tp_new slot establishes the invariants. This may preclude a future bug if a custom tp_new slot is written. Index: listobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v retrieving revision 2.212 retrieving revision 2.213 diff -C2 -d -r2.212 -r2.213 *** listobject.c 29 Jul 2004 12:40:23 -0000 2.212 --- listobject.c 29 Jul 2004 23:31:29 -0000 2.213 *************** *** 20,26 **** */ ! if (self->allocated >= newsize && ! self->ob_size < newsize + 16 && ! self->ob_item != NULL) { self->ob_size = newsize; return 0; --- 20,25 ---- */ ! if (self->allocated >= newsize && self->ob_size < newsize + 16) { ! assert(self->ob_item != NULL || newsize == 0); self->ob_size = newsize; return 0; *************** *** 2315,2318 **** --- 2314,2322 ---- if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg)) return -1; + + /* Verify list invariants established by PyType_GenericAlloc() */ + assert(0 <= self->ob_size && self->ob_size <= self->allocated); + assert(self->ob_item != NULL || self->allocated == 0); + /* Empty previous contents */ if (self->ob_item != NULL) {
participants (1)
-
rhettingerīŧ users.sourceforge.net