From: Armin R. <ar...@us...> - 2004-10-26 15:10:40
|
Update of /cvsroot/psyco/psyco/c/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8008/c/Objects Modified Files: pintobject.c plistobject.c plistobject.h Log Message: Support for Python 2.4. It doesn't crash immediately now, but I still have to run the complete test suite to discover remaining problems. Individual changes: * MANIFEST file now up-to-date and in alphabetical order and with more directories than previously * support for 2.4's LIST_APPEND. * support for the LOAD_NAME, STORE_NAME and DELETE_NAME opcodes at the module level -- might enable Psyco to compile module-level loops now, handy for small example scripts (but loops directly in class: statements still cannot be compiled) * fixed the specific bug causing a crash with 2.4, which was that the trace functions of Python can be called in new conditions: when calling or returning from C functions. Psyco correctly ignores these now. * left shifts of integers return longs when they overflow as in 2.4, when Psyco is compiled with 2.4. Index: pintobject.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Objects/pintobject.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** pintobject.c 11 Aug 2004 23:03:38 -0000 1.17 --- pintobject.c 26 Oct 2004 15:10:31 -0000 1.18 *************** *** 336,342 **** } ! #if PY_VERSION_HEX>=0x02040000 ! # warning "left shifts must be able to return longs in Python 2.4" ! #endif static vinfo_t* pint_lshift(PsycoObject* po, vinfo_t* v, vinfo_t* w) { --- 336,341 ---- } ! #if PY_VERSION_HEX < 0x02040000 ! static vinfo_t* pint_lshift(PsycoObject* po, vinfo_t* v, vinfo_t* w) { *************** *** 344,347 **** --- 343,426 ---- } + #else + /* Python 2.4: left shifts can return longs */ + + static long cimpl_int_lshift(long a, long b) + { + long c; + if (b < 0) + return -1; /* error */ + if (a == 0) + return 0; + if (b >= LONG_BIT) + return -1; /* overflow */ + c = a << b; + if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) + return -1; /* overflow */ + return c; + } + + static PyObject* cimpl_ovf_int_lshift(long a, long b) + { + if (b > 0) { + /* cimpl_int_lshift() overflowed */ + PyObject *vv, *ww, *result; + vv = PyLong_FromLong(a); + if (vv == NULL) + return NULL; + ww = PyLong_FromLong(b); + if (ww == NULL) { + Py_DECREF(vv); + return NULL; + } + result = PyNumber_Lshift(vv, ww); + Py_DECREF(vv); + Py_DECREF(ww); + return result; + } + else if (b == 0) { + /* special case '(-1)<<0', which makes cimpl_int_lshift() + return -1 by accident */ + return PyInt_FromLong(a); + } + else { + PyErr_SetString(PyExc_ValueError, "negative shift count"); + return NULL; + } + } + + static vinfo_t* pint_lshift(PsycoObject* po, vinfo_t* v, vinfo_t* w) + { + condition_code_t cc; + vinfo_t* a; + vinfo_t* b; + vinfo_t* x; + CONVERT_TO_LONG(v, a); + CONVERT_TO_LONG(w, b); + x = psyco_generic_call(po, cimpl_int_lshift, + CfPure|CfReturnNormal, + "vv", a, b); + if (x == NULL) + return NULL; + + cc = integer_cmp_i(po, x, -1, Py_EQ); + if (cc == CC_ERROR) { + vinfo_decref(x, po); + return NULL; + } + + if (runtime_condition_f(po, cc)) { + /* overflow */ + vinfo_decref(x, po); + return psyco_generic_call(po, cimpl_ovf_int_lshift, + CfPure|CfReturnRef|CfPyErrIfNull, + "vv", a, b); + } + else + return PsycoInt_FROM_LONG(x); + } + + #endif /* Python 2.4 */ + static vinfo_t* pint_rshift(PsycoObject* po, vinfo_t* v, vinfo_t* w) { Index: plistobject.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Objects/plistobject.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** plistobject.c 11 Aug 2004 23:03:38 -0000 1.16 --- plistobject.c 26 Oct 2004 15:10:31 -0000 1.17 *************** *** 297,300 **** --- 297,309 ---- } + DEFINEFN + bool PsycoList_Append(PsycoObject* po, vinfo_t* v, vinfo_t* vitem) + { + /* use the real PyList_Append */ + return psyco_generic_call(po, PyList_Append, + CfNoReturnValue|CfPyErrIfNonNull, + "vv", v, vitem) != NULL; + } + INITIALIZATIONFN Index: plistobject.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Objects/plistobject.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** plistobject.h 17 Jan 2003 14:41:31 -0000 1.5 --- plistobject.h 26 Oct 2004 15:10:31 -0000 1.6 *************** *** 25,28 **** --- 25,29 ---- EXTERNFN vinfo_t* PsycoList_New(PsycoObject* po, int size, vinfo_t** source); EXTERNFN vinfo_t* PsycoList_SingletonNew(vinfo_t* vitem); + EXTERNFN bool PsycoList_Append(PsycoObject* po, vinfo_t* v, vinfo_t* vitem); /*EXTERNVAR vinfo_t* psyco_empty_list;*/ |