Avoid installing Error.__reduce_ex__ on Python 2.4

It is not used by the pickle protocol, and if called manually fails in an
unsettling way, probably because the exceptions were old-style classes.
This commit is contained in:
Daniele Varrazzo 2012-01-14 18:01:15 +00:00
parent 43daba38e7
commit db987250c8

View File

@ -478,7 +478,12 @@ psyco_errors_init(void)
PyObject_SetAttrString(Error, "pgcode", Py_None); PyObject_SetAttrString(Error, "pgcode", Py_None);
PyObject_SetAttrString(Error, "cursor", Py_None); PyObject_SetAttrString(Error, "cursor", Py_None);
/* install __reduce_ex__ on Error to make all the subclasses picklable */ /* install __reduce_ex__ on Error to make all the subclasses picklable.
*
* Don't install it on Py 2.4: it is not used by the pickle
* protocol, and if called manually fails in an unsettling way,
* probably because the exceptions were old-style classes. */
#if PY_VERSION_HEX >= 0x02050000
if (!(descr = PyDescr_NewMethod((PyTypeObject *)Error, if (!(descr = PyDescr_NewMethod((PyTypeObject *)Error,
&psyco_error_reduce_ex_def))) { &psyco_error_reduce_ex_def))) {
goto exit; goto exit;
@ -488,6 +493,7 @@ psyco_errors_init(void)
goto exit; goto exit;
} }
Py_DECREF(descr); Py_DECREF(descr);
#endif
rv = 0; rv = 0;