Commit 0ab6907c authored by Stefan Behnel's avatar Stefan Behnel

several PyPy specific fixes, originally proposed/encouraged by Amaury Forgeot d'Arc

--HG--
extra : rebase_source : a03ca7427bd5c6369583d12f1924b56f944e55aa
parent dd8ac390
...@@ -2102,6 +2102,11 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/ ...@@ -2102,6 +2102,11 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
""", """,
impl = """ impl = """
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#if CYTHON_COMPILING_IN_PYPY
if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { /* cdef classes */
return PyClassMethod_New(method);
}
#else
/* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */ /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
static PyTypeObject *methoddescr_type = NULL; static PyTypeObject *methoddescr_type = NULL;
if (methoddescr_type == NULL) { if (methoddescr_type == NULL) {
...@@ -2119,6 +2124,7 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { ...@@ -2119,6 +2124,7 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#endif #endif
return PyDescr_NewClassMethod(d_type, descr->d_method); return PyDescr_NewClassMethod(d_type, descr->d_method);
} }
#endif
else if (PyMethod_Check(method)) { /* python classes */ else if (PyMethod_Check(method)) { /* python classes */
return PyClassMethod_New(PyMethod_GET_FUNCTION(method)); return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
} }
......
...@@ -200,6 +200,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); ...@@ -200,6 +200,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *local_type, *local_value, *local_tb; PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
local_type = tstate->curexc_type; local_type = tstate->curexc_type;
...@@ -208,25 +209,36 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) ...@@ -208,25 +209,36 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
tstate->curexc_type = 0; tstate->curexc_type = 0;
tstate->curexc_value = 0; tstate->curexc_value = 0;
tstate->curexc_traceback = 0; tstate->curexc_traceback = 0;
#else
PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
PyErr_NormalizeException(&local_type, &local_value, &local_tb); PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
if (unlikely(tstate->curexc_type)) if (unlikely(tstate->curexc_type))
#else
if (unlikely(PyErr_Occurred()))
#endif
goto bad; goto bad;
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
goto bad; goto bad;
#endif #endif
*type = local_type;
*value = local_value;
*tb = local_tb;
Py_INCREF(local_type); Py_INCREF(local_type);
Py_INCREF(local_value); Py_INCREF(local_value);
Py_INCREF(local_tb); Py_INCREF(local_tb);
*type = local_type;
*value = local_value;
*tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
tmp_type = tstate->exc_type; tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value; tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback; tmp_tb = tstate->exc_traceback;
tstate->exc_type = local_type; tstate->exc_type = local_type;
tstate->exc_value = local_value; tstate->exc_value = local_value;
tstate->exc_traceback = local_tb; tstate->exc_traceback = local_tb;
#else
PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
/* Make sure tstate is in a consistent state when we XDECREF /* Make sure tstate is in a consistent state when we XDECREF
these objects (XDECREF may run arbitrary code). */ these objects (XDECREF may run arbitrary code). */
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
...@@ -251,6 +263,7 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); ...@@ -251,6 +263,7 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb);
/////////////// SaveResetException /////////////// /////////////// SaveResetException ///////////////
static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
*type = tstate->exc_type; *type = tstate->exc_type;
*value = tstate->exc_value; *value = tstate->exc_value;
...@@ -258,9 +271,13 @@ static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, ...@@ -258,9 +271,13 @@ static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value,
Py_XINCREF(*type); Py_XINCREF(*type);
Py_XINCREF(*value); Py_XINCREF(*value);
Py_XINCREF(*tb); Py_XINCREF(*tb);
#else
PyErr_GetExcInfo(type, value, tb);
#endif
} }
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->exc_type; tmp_type = tstate->exc_type;
...@@ -272,6 +289,9 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) ...@@ -272,6 +289,9 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value); Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb); Py_XDECREF(tmp_tb);
#else
PyErr_SetExcInfo(type, value, tb);
#endif
} }
/////////////// SwapException.proto /////////////// /////////////// SwapException.proto ///////////////
...@@ -282,6 +302,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, ...@@ -282,6 +302,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->exc_type; tmp_type = tstate->exc_type;
...@@ -291,6 +312,10 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, ...@@ -291,6 +312,10 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
tstate->exc_type = *type; tstate->exc_type = *type;
tstate->exc_value = *value; tstate->exc_value = *value;
tstate->exc_traceback = *tb; tstate->exc_traceback = *tb;
#else
PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
PyErr_SetExcInfo(*type, *value, *tb);
#endif
*type = tmp_type; *type = tmp_type;
*value = tmp_value; *value = tmp_value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment