Index: Include/intobject.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/intobject.h,v retrieving revision 2.25 diff -C5 -r2.25 intobject.h *** Include/intobject.h 3 Apr 2002 22:41:50 -0000 2.25 --- Include/intobject.h 27 May 2002 21:19:13 -0000 *************** *** 28,37 **** --- 28,38 ---- extern DL_IMPORT(PyTypeObject) PyInt_Type; #define PyInt_Check(op) PyObject_TypeCheck(op, &PyInt_Type) #define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type) + extern DL_IMPORT(void) PyInt_Init(void); extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int); #ifdef Py_USING_UNICODE extern DL_IMPORT(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int); #endif extern DL_IMPORT(PyObject *) PyInt_FromLong(long); Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.311 diff -C5 -r2.311 ceval.c *** Python/ceval.c 20 May 2002 13:56:11 -0000 2.311 --- Python/ceval.c 27 May 2002 21:19:14 -0000 *************** *** 505,515 **** register int err; /* Error status -- nonzero if error */ register PyObject *x; /* Result object -- NULL if error */ register PyObject *v; /* Temporary objects popped off stack */ register PyObject *w; register PyObject *u; ! register PyObject *t; register PyObject *stream = NULL; /* for PRINT opcodes */ register PyObject **fastlocals, **freevars; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = PyThreadState_GET(); PyCodeObject *co; --- 505,515 ---- register int err; /* Error status -- nonzero if error */ register PyObject *x; /* Result object -- NULL if error */ register PyObject *v; /* Temporary objects popped off stack */ register PyObject *w; register PyObject *u; ! PyObject *t; register PyObject *stream = NULL; /* for PRINT opcodes */ register PyObject **fastlocals, **freevars; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = PyThreadState_GET(); PyCodeObject *co; *************** *** 587,597 **** } tstate->frame = f; co = f->f_code; fastlocals = f->f_localsplus; ! freevars = f->f_localsplus + f->f_nlocals; _PyCode_GETCODEPTR(co, &first_instr); next_instr = first_instr + f->f_lasti; stack_pointer = f->f_stacktop; assert(stack_pointer != NULL); f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ --- 587,597 ---- } tstate->frame = f; co = f->f_code; fastlocals = f->f_localsplus; ! freevars = fastlocals + f->f_nlocals; _PyCode_GETCODEPTR(co, &first_instr); next_instr = first_instr + f->f_lasti; stack_pointer = f->f_stacktop; assert(stack_pointer != NULL); f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ *************** *** 1736,1754 **** w = PyCell_Get(x); if (w == NULL) { if (oparg < f->f_ncells) { v = PyTuple_GetItem(co->co_cellvars, oparg); ! format_exc_check_arg( PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, v); } else { ! v = PyTuple_GetItem( co->co_freevars, oparg - f->f_ncells); ! format_exc_check_arg( PyExc_NameError, UNBOUNDFREE_ERROR_MSG, v); } err = -1; --- 1736,1754 ---- w = PyCell_Get(x); if (w == NULL) { if (oparg < f->f_ncells) { v = PyTuple_GetItem(co->co_cellvars, oparg); ! format_exc_check_arg( PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, v); } else { ! v = PyTuple_GetItem( co->co_freevars, oparg - f->f_ncells); ! format_exc_check_arg( PyExc_NameError, UNBOUNDFREE_ERROR_MSG, v); } err = -1; *************** *** 1985,1994 **** --- 1985,1995 ---- int na = oparg & 0xff; int nk = (oparg>>8) & 0xff; int n = na + 2 * nk; PyObject **pfunc = stack_pointer - n - 1; PyObject *func = *pfunc; + PyObject *self; f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ /* Always dispatch PyCFunction first, because these are presumed to be the most frequent callable object. *************** *** 2006,2018 **** } else x = fast_cfunction(func, &stack_pointer, na); } else { if (PyMethod_Check(func) ! && PyMethod_GET_SELF(func) != NULL) { /* optimize access to bound methods */ - PyObject *self = PyMethod_GET_SELF(func); Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); Py_DECREF(*pfunc); *pfunc = self; --- 2007,2018 ---- } else x = fast_cfunction(func, &stack_pointer, na); } else { if (PyMethod_Check(func) ! && (self = PyMethod_GET_SELF(func)) != NULL) { /* optimize access to bound methods */ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); Py_DECREF(*pfunc); *pfunc = self; *************** *** 2046,2067 **** { int na = oparg & 0xff; int nk = (oparg>>8) & 0xff; int flags = (opcode - CALL_FUNCTION) & 3; int n = na + 2 * nk; ! PyObject **pfunc, *func; if (flags & CALL_FLAG_VAR) n++; if (flags & CALL_FLAG_KW) n++; pfunc = stack_pointer - n - 1; func = *pfunc; f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ if (PyMethod_Check(func) ! && PyMethod_GET_SELF(func) != NULL) { ! PyObject *self = PyMethod_GET_SELF(func); Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); Py_DECREF(*pfunc); *pfunc = self; --- 2046,2066 ---- { int na = oparg & 0xff; int nk = (oparg>>8) & 0xff; int flags = (opcode - CALL_FUNCTION) & 3; int n = na + 2 * nk; ! PyObject **pfunc, *func, *self; if (flags & CALL_FLAG_VAR) n++; if (flags & CALL_FLAG_KW) n++; pfunc = stack_pointer - n - 1; func = *pfunc; f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ if (PyMethod_Check(func) ! && (self = PyMethod_GET_SELF(func)) != NULL) { Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); Py_DECREF(*pfunc); *pfunc = self; *************** *** 2379,2389 **** globals, locals); if (f == NULL) return NULL; fastlocals = f->f_localsplus; ! freevars = f->f_localsplus + f->f_nlocals; if (co->co_argcount > 0 || co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) { int i; int n = argcount; --- 2378,2388 ---- globals, locals); if (f == NULL) return NULL; fastlocals = f->f_localsplus; ! freevars = fastlocals + f->f_nlocals; if (co->co_argcount > 0 || co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) { int i; int n = argcount; Index: Python/pythonrun.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v retrieving revision 2.160 diff -C5 -r2.160 pythonrun.c *** Python/pythonrun.c 23 Apr 2002 20:31:01 -0000 2.160 --- Python/pythonrun.c 27 May 2002 21:19:15 -0000 *************** *** 127,136 **** --- 127,138 ---- Py_FatalError("Py_Initialize: can't make first thread"); (void) PyThreadState_Swap(tstate); _Py_ReadyTypes(); + PyInt_Init(); + interp->modules = PyDict_New(); if (interp->modules == NULL) Py_FatalError("Py_Initialize: can't make modules dictionary"); /* Init codec registry */ Index: Objects/tupleobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v retrieving revision 2.64 diff -C5 -r2.64 tupleobject.c *** Objects/tupleobject.c 12 Apr 2002 03:05:52 -0000 2.64 --- Objects/tupleobject.c 27 May 2002 21:19:16 -0000 *************** *** 24,34 **** #endif PyObject * PyTuple_New(register int size) { - register int i; register PyTupleObject *op; if (size < 0) { PyErr_BadInternalCall(); return NULL; } --- 24,33 ---- *************** *** 69,80 **** } op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL; } ! for (i = 0; i < size; i++) ! op->ob_item[i] = NULL; #if MAXSAVESIZE > 0 if (size == 0) { free_tuples[0] = op; ++num_free_tuples[0]; Py_INCREF(op); /* extra INCREF so that this is never freed */ --- 68,78 ---- } op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL; } ! memset(op->ob_item, 0, sizeof(*op->ob_item) * size); #if MAXSAVESIZE > 0 if (size == 0) { free_tuples[0] = op; ++num_free_tuples[0]; Py_INCREF(op); /* extra INCREF so that this is never freed */ *************** *** 638,649 **** PyObject_GC_Del(v); return -1; } _Py_NewReference((PyObject *) sv); /* Zero out items added by growing */ ! for (i = oldsize; i < newsize; i++) ! sv->ob_item[i] = NULL; *pv = (PyObject *) sv; _PyObject_GC_TRACK(sv); return 0; } --- 636,648 ---- PyObject_GC_Del(v); return -1; } _Py_NewReference((PyObject *) sv); /* Zero out items added by growing */ ! if (newsize > oldsize) ! memset(sv->ob_item, 0, ! sizeof(*sv->ob_item) * (newsize - oldsize)); *pv = (PyObject *) sv; _PyObject_GC_TRACK(sv); return 0; } Index: Objects/listobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v retrieving revision 2.106 diff -C5 -r2.106 listobject.c *** Objects/listobject.c 22 May 2002 23:19:16 -0000 2.106 --- Objects/listobject.c 27 May 2002 21:19:16 -0000 *************** *** 54,64 **** } while (0) PyObject * PyList_New(int size) { - int i; PyListObject *op; size_t nbytes; if (size < 0) { PyErr_BadInternalCall(); return NULL; --- 54,63 ---- *************** *** 78,91 **** else { op->ob_item = (PyObject **) PyMem_MALLOC(nbytes); if (op->ob_item == NULL) { return PyErr_NoMemory(); } } op->ob_size = size; - for (i = 0; i < size; i++) - op->ob_item[i] = NULL; _PyObject_GC_TRACK(op); return (PyObject *) op; } int --- 77,89 ---- else { op->ob_item = (PyObject **) PyMem_MALLOC(nbytes); if (op->ob_item == NULL) { return PyErr_NoMemory(); } + memset(op->ob_item, 0, sizeof(*op->ob_item) * size); } op->ob_size = size; _PyObject_GC_TRACK(op); return (PyObject *) op; } int *************** *** 1574,1585 **** 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; result->ob_size = n; /* Run iterator to exhaustion. */ for (i = 0; ; i++) { PyObject *item = PyIter_Next(it); --- 1572,1582 ---- NRESIZE(result->ob_item, PyObject*, n); if (result->ob_item == NULL) { PyErr_NoMemory(); goto error; } ! memset(result->ob_item, 0, sizeof(*result->ob_item) * n); result->ob_size = n; /* Run iterator to exhaustion. */ for (i = 0; ; i++) { PyObject *item = PyIter_Next(it); Index: Objects/intobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v retrieving revision 2.83 diff -C5 -r2.83 intobject.c *** Objects/intobject.c 28 Apr 2002 16:57:34 -0000 2.83 --- Objects/intobject.c 27 May 2002 21:19:17 -0000 *************** *** 95,106 **** PyObject * PyInt_FromLong(long ival) { register PyIntObject *v; #if NSMALLNEGINTS + NSMALLPOSINTS > 0 ! if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS && ! (v = small_ints[ival + NSMALLNEGINTS]) != NULL) { Py_INCREF(v); #ifdef COUNT_ALLOCS if (ival >= 0) quick_int_allocs++; else --- 95,106 ---- PyObject * PyInt_FromLong(long ival) { register PyIntObject *v; #if NSMALLNEGINTS + NSMALLPOSINTS > 0 ! if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) { ! v = small_ints[ival + NSMALLNEGINTS]; Py_INCREF(v); #ifdef COUNT_ALLOCS if (ival >= 0) quick_int_allocs++; else *************** *** 116,132 **** /* PyObject_New is inlined */ v = free_list; free_list = (PyIntObject *)v->ob_type; PyObject_INIT(v, &PyInt_Type); v->ob_ival = ival; - #if NSMALLNEGINTS + NSMALLPOSINTS > 0 - if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) { - /* save this one for a following allocation */ - Py_INCREF(v); - small_ints[ival + NSMALLNEGINTS] = v; - } - #endif return (PyObject *) v; } static void int_dealloc(PyIntObject *v) --- 116,125 ---- *************** *** 921,930 **** --- 914,943 ---- 0, /* tp_init */ 0, /* tp_alloc */ int_new, /* tp_new */ (freefunc)int_free, /* tp_free */ }; + + void + PyInt_Init(void) + { + PyIntObject *v; + int ival; + #if NSMALLNEGINTS + NSMALLPOSINTS > 0 + for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++) { + if ((free_list = fill_free_list()) == NULL) + return; + /* PyObject_New is inlined */ + v = free_list; + free_list = (PyIntObject *)v->ob_type; + PyObject_INIT(v, &PyInt_Type); + v->ob_ival = ival; + Py_INCREF(v); + small_ints[ival + NSMALLNEGINTS] = v; + } + #endif + } void PyInt_Fini(void) { PyIntObject *p; Index: Objects/frameobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v retrieving revision 2.62 diff -C5 -r2.62 frameobject.c *** Objects/frameobject.c 20 Apr 2002 04:46:55 -0000 2.62 --- Objects/frameobject.c 27 May 2002 21:19:17 -0000 *************** *** 277,287 **** Py_DECREF(f); return NULL; } } else ! Py_XINCREF(builtins); f->f_builtins = builtins; Py_XINCREF(back); f->f_back = back; Py_INCREF(code); f->f_code = code; --- 277,287 ---- Py_DECREF(f); return NULL; } } else ! Py_INCREF(builtins); f->f_builtins = builtins; Py_XINCREF(back); f->f_back = back; Py_INCREF(code); f->f_code = code; *************** *** 315,326 **** f->f_nlocals = code->co_nlocals; f->f_stacksize = code->co_stacksize; f->f_ncells = ncells; f->f_nfreevars = nfrees; ! while (--extras >= 0) ! f->f_localsplus[extras] = NULL; f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees); f->f_stacktop = f->f_valuestack; _PyObject_GC_TRACK(f); return f; --- 315,325 ---- f->f_nlocals = code->co_nlocals; f->f_stacksize = code->co_stacksize; f->f_ncells = ncells; f->f_nfreevars = nfrees; ! memset(f->f_localsplus, 0, sizeof(*f->f_localsplus) * extras); f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees); f->f_stacktop = f->f_valuestack; _PyObject_GC_TRACK(f); return f; Index: Objects/object.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v retrieving revision 2.175 diff -C5 -r2.175 object.c *** Objects/object.c 24 May 2002 19:01:58 -0000 2.175 --- Objects/object.c 27 May 2002 21:19:17 -0000 *************** *** 1381,1405 **** int PyObject_IsTrue(PyObject *v) { int res; if (v == Py_None) ! res = 0; else if (v->ob_type->tp_as_number != NULL && v->ob_type->tp_as_number->nb_nonzero != NULL) res = (*v->ob_type->tp_as_number->nb_nonzero)(v); else if (v->ob_type->tp_as_mapping != NULL && v->ob_type->tp_as_mapping->mp_length != NULL) res = (*v->ob_type->tp_as_mapping->mp_length)(v); else if (v->ob_type->tp_as_sequence != NULL && v->ob_type->tp_as_sequence->sq_length != NULL) res = (*v->ob_type->tp_as_sequence->sq_length)(v); else ! res = 1; ! if (res > 0) ! res = 1; ! return res; } /* equivalent of 'not v' Return -1 if an error occurred */ --- 1381,1403 ---- int PyObject_IsTrue(PyObject *v) { int res; if (v == Py_None) ! return 0; else if (v->ob_type->tp_as_number != NULL && v->ob_type->tp_as_number->nb_nonzero != NULL) res = (*v->ob_type->tp_as_number->nb_nonzero)(v); else if (v->ob_type->tp_as_mapping != NULL && v->ob_type->tp_as_mapping->mp_length != NULL) res = (*v->ob_type->tp_as_mapping->mp_length)(v); else if (v->ob_type->tp_as_sequence != NULL && v->ob_type->tp_as_sequence->sq_length != NULL) res = (*v->ob_type->tp_as_sequence->sq_length)(v); else ! return 1; ! return (res > 0) ? 1 : res; } /* equivalent of 'not v' Return -1 if an error occurred */ *************** *** 1901,1911 **** /* Hack to force loading of cobject.o */ PyTypeObject *_Py_cobject_hack = &PyCObject_Type; /* Hack to force loading of abstract.o */ ! int (*_Py_abstract_hack)(PyObject *) = &PyObject_Size; /* Python's malloc wrappers (see pymem.h) */ void * --- 1899,1909 ---- /* Hack to force loading of cobject.o */ PyTypeObject *_Py_cobject_hack = &PyCObject_Type; /* Hack to force loading of abstract.o */ ! int (*_Py_abstract_hack)(PyObject *) = PyObject_Size; /* Python's malloc wrappers (see pymem.h) */ void *