From: Robert Bradshaw Date: Sat, 20 Oct 2007 19:18:21 +0000 (-0700) Subject: merge (including cwitty's change to get_exception_utility_code) X-Git-Tag: 0.9.6.14~29^2~119 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=06b9e15c03dec8b8b16faedf97d945a108c4a3dd;p=cython.git merge (including cwitty's change to get_exception_utility_code) --- 06b9e15c03dec8b8b16faedf97d945a108c4a3dd diff --cc Cython/Compiler/Nodes.py index 8c20c1c2,eba442bd..d4df57c7 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@@ -3331,40 -3424,32 +3424,38 @@@ static int __Pyx_InitStrings(__Pyx_Stri #------------------------------------------------------------------------------------ - c_api_import_code = [ + get_exception_utility_code = [ """ - static int __Pyx_InitCApi(PyObject *module); /*proto*/ - static int __Pyx_ImportModuleCApi(__Pyx_CApiTabEntry *t); /*proto*/ + static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ """,""" - static int __Pyx_ImportModuleCApi(__Pyx_CApiTabEntry *t) { - __Pyx_CApiTabEntry *api_t; - while (t->s) { - if (*t->s == '\\0') - continue; /* shortcut for erased string entries */ - api_t = %(API_TAB)s; - while ((api_t->s) && (strcmp(api_t->s, t->s) < 0)) - ++api_t; - if ((!api_t->p) || (strcmp(api_t->s, t->s) != 0)) { - PyErr_Format(PyExc_ValueError, - "Unknown function name in C API: %%s", t->s); - return -1; - } - *t->p = api_t->p; - ++t; - } + static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { ++ PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_Get(); + PyErr_Fetch(type, value, tb); + PyErr_NormalizeException(type, value, tb); + if (PyErr_Occurred()) + goto bad; + Py_INCREF(*type); + Py_INCREF(*value); + Py_INCREF(*tb); - Py_XDECREF(tstate->exc_type); - Py_XDECREF(tstate->exc_value); - Py_XDECREF(tstate->exc_traceback); ++ tmp_type = tstate->exc_type; ++ tmp_value = tstate->exc_value; ++ tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; ++ /* Make sure tstate is in a consistent state when we XDECREF ++ these objects (XDECREF may run arbitrary code). */ ++ Py_XDECREF(tmp_type); ++ Py_XDECREF(tmp_value); ++ Py_XDECREF(tmp_tb); return 0; + bad: + Py_XDECREF(*type); + Py_XDECREF(*value); + Py_XDECREF(*tb); + return -1; } + """] - static int __Pyx_InitCApi(PyObject *module) { - int result; - PyObject* cobj = PyCObject_FromVoidPtr(&__Pyx_ImportModuleCApi, NULL); - if (!cobj) - return -1; - - result = PyObject_SetAttrString(module, "_import_c_api", cobj); - Py_DECREF(cobj); - return result; - } - """ % {'API_TAB' : Naming.c_api_tab_cname} - ] #------------------------------------------------------------------------------------