From: Armin R. <ar...@us...> - 2005-02-28 08:43:12
|
Update of /cvsroot/psyco/psyco/c In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19500/c Modified Files: mergepoints.c mergepoints.h psyco.c Log Message: psyco.setfilter(func or None) -> previous filter or None Set a global filter function: func(co) will be called once per code object 'co' considered by Psyco. If it returns False, the code object will not be compiled. Index: mergepoints.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/mergepoints.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** mergepoints.c 1 Dec 2004 18:57:59 -0000 1.28 --- mergepoints.c 28 Feb 2005 08:43:03 -0000 1.29 *************** *** 670,673 **** --- 670,674 ---- ("unsupported opcode %d at %s:%d\n", (int) op, PyCodeObject_NAME(co), i)); + negative_exit: PyMem_FREE(instrnodes); Py_INCREF(Py_None); *************** *** 735,738 **** --- 736,753 ---- } while (modif); + /* check with the user-defined filter function, if any */ + if (psyco_codeobj_filter_fn != NULL) + { + int res; + PyObject* o = PyObject_CallFunction(psyco_codeobj_filter_fn, "O", + (PyObject*) co); + res = o == NULL ? -1 : PyObject_IsTrue(o); + Py_XDECREF(o); + if (res < 0) + PyErr_WriteUnraisable(psyco_codeobj_filter_fn); + if (res <= 0) + goto negative_exit; + } + /* set and count merge points */ /* a confluence point is an instruction with more than one incoming path */ *************** *** 936,937 **** --- 951,954 ---- return PyCodeStats_MergePoints(PyCodeStats_Get(co), module); } + + DEFINEVAR PyObject* psyco_codeobj_filter_fn = NULL; Index: mergepoints.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/mergepoints.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** mergepoints.h 1 Dec 2004 18:57:59 -0000 1.8 --- mergepoints.h 28 Feb 2005 08:43:03 -0000 1.9 *************** *** 83,86 **** --- 83,89 ---- } + /* A user-defined filter function to prevent compilation of some code objs */ + EXTERNVAR PyObject* psyco_codeobj_filter_fn; + #endif /* _MERGEPOINTS_H */ Index: psyco.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/psyco.c,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** psyco.c 30 Dec 2004 22:04:58 -0000 1.51 --- psyco.c 28 Feb 2005 08:43:03 -0000 1.52 *************** *** 9,12 **** --- 9,13 ---- #include "alarm.h" #include "timing.h" + #include "mergepoints.h" #define PSYCO_INITIALIZATION *************** *** 487,490 **** --- 488,518 ---- } + static PyObject* Psyco_setfilter(PyObject* self, PyObject* args) + { + PyObject* func; + PyObject* prev; + + if (!PyArg_ParseTuple(args, "O", &func)) + return NULL; + + if (func == Py_None) + func = NULL; + else { + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, + "setfilter() arg must be callable"); + return NULL; + } + Py_INCREF(func); + } + prev = psyco_codeobj_filter_fn; + psyco_codeobj_filter_fn = func; + if (prev == NULL) { + prev = Py_None; + Py_INCREF(prev); + } + return prev; + } + /* replacement for sys._getframe() (together with _getframe() in support.py) */ static PyObject* Psyco_getframe(PyObject* self, PyObject* args) *************** *** 917,920 **** --- 945,955 ---- Accessing it returns {} and throws a NoLocalsWarning."; + static char setfilter_doc[] = + "setfilter(func or None) -> previous filter or None\n\ + \n\ + Set a global filter function: func(co) will be called once per code object\n\ + 'co' considered by Psyco. If it returns False, the code object will not\n\ + be compiled."; + static PyMethodDef PsycoMethods[] = { {"proxycode", &Psyco_proxycode, METH_VARARGS, proxycode_doc}, *************** *** 944,947 **** --- 979,983 ---- {"memory", &Psyco_memory, METH_VARARGS}, {"cannotcompile",&Psyco_cannotcompile, METH_VARARGS}, + {"setfilter", &Psyco_setfilter, METH_VARARGS, setfilter_doc}, #if 0 {"finalizer", &Psyco_finalizer, METH_VARARGS}, |