From: Armin R. <ar...@us...> - 2002-01-04 18:00:03
|
Update of /cvsroot/psyco/psyco/c In directory usw-pr-cvs1:/tmp/cvs-serv23507 Modified Files: psyco.c selective.c Log Message: added error checks Index: psyco.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/psyco.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** psyco.c 2002/01/03 13:27:51 1.11 --- psyco.c 2002/01/04 18:00:00 1.12 *************** *** 562,565 **** --- 562,566 ---- /* Sanity check argument */ if (ticks < 0) { + PyErr_SetString(PyExc_ValueError, "negative ticks"); return NULL; } *************** *** 568,574 **** if (funcs == NULL) { funcs = PyDict_New(); } - - assert(funcs != NULL); /* Set Python profile function to our selective compilation function */ --- 569,575 ---- if (funcs == NULL) { funcs = PyDict_New(); + if (funcs == NULL) + return NULL; } /* Set Python profile function to our selective compilation function */ Index: selective.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/selective.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** selective.c 2002/01/03 15:30:28 1.3 --- selective.c 2002/01/04 18:00:00 1.4 *************** *** 9,12 **** --- 9,13 ---- PyObject *code, *name, *g, *tmp; int value; + int err; /* Only handle function calls for now */ *************** *** 19,24 **** tmp = PyDict_GetItem(funcs, code); if (tmp == NULL) { - PyDict_SetItem(funcs, code, Py_BuildValue("i", 1)); value = 1; } else { value = PyInt_AS_LONG(tmp); --- 20,31 ---- tmp = PyDict_GetItem(funcs, code); if (tmp == NULL) { value = 1; + tmp = PyInt_FromLong(value); + if (tmp == NULL) + return -1; + err = PyDict_SetItem(funcs, code, tmp); + Py_DECREF(tmp); + if (err) + return -1; } else { value = PyInt_AS_LONG(tmp); *************** *** 31,40 **** if (tmp != NULL) { /* Rebind function to a proxy */ ! printf("psyco: compiling function %s\n", PyString_AS_STRING(name)); value = FUN_BOUND; ! PyDict_SetItem(g, name, (PyObject*)psyco_PsycoFunction_New((PyFunctionObject*)tmp, MAX_RECURSION)); } } ! PyDict_SetItem(funcs, code, Py_BuildValue("i", value)); } } --- 38,59 ---- if (tmp != NULL) { /* Rebind function to a proxy */ ! debug_printf(("psyco: compiling function %s\n", PyString_AS_STRING(name))); value = FUN_BOUND; ! tmp = (PyObject*)psyco_PsycoFunction_New((PyFunctionObject*)tmp, MAX_RECURSION); ! if (tmp == NULL) ! return -1; ! err = PyDict_SetItem(g, name, tmp); ! Py_DECREF(tmp); ! if (err) ! return -1; } } ! tmp = PyInt_FromLong(value); ! if (tmp == NULL) ! return -1; ! err = PyDict_SetItem(funcs, code, tmp); ! Py_DECREF(tmp); ! if (err) ! return -1; } } |