Mercurial > cpython-lru_cache-weakref
diff Objects/exceptions.c @ 78304:68e2690a471d
Issue #1692335: Move initial args assignment to BaseException.__new__
to help pickling of naive subclasses.
| author | Richard Oudkerk <shibturn@gmail.com> |
|---|---|
| date | Sat, 28 Jul 2012 17:45:28 +0100 |
| parents | 1cbab581bf1e |
| children | 91909962d7f5 |
line wrap: on
line diff
--- a/Objects/exceptions.c Sat Jul 28 14:10:02 2012 +0200 +++ b/Objects/exceptions.c Sat Jul 28 17:45:28 2012 +0100 @@ -44,6 +44,12 @@ self->traceback = self->cause = self->context = NULL; self->suppress_context = 0; + if (args) { + self->args = args; + Py_INCREF(args); + return (PyObject *)self; + } + self->args = PyTuple_New(0); if (!self->args) { Py_DECREF(self); @@ -56,12 +62,15 @@ static int BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) { + PyObject *tmp; + if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) return -1; - Py_XDECREF(self->args); + tmp = self->args; self->args = args; Py_INCREF(self->args); + Py_XDECREF(tmp); return 0; }
