diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2012-07-28 16:45:28 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2012-07-28 16:45:28 (GMT) |
commit | 5562d9dc5dd9f9a7710a1530a114c215516d4700 (patch) | |
tree | 506ef5c564f175f3760a1aee6b37490d1a67b6d5 /Objects/exceptions.c | |
parent | e4c0799d9c5359b9c5115adf212d452137683c57 (diff) | |
download | cpython-5562d9dc5dd9f9a7710a1530a114c215516d4700.zip cpython-5562d9dc5dd9f9a7710a1530a114c215516d4700.tar.gz cpython-5562d9dc5dd9f9a7710a1530a114c215516d4700.tar.bz2 |
Issue #1692335: Move initial args assignment to BaseException.__new__
to help pickling of naive subclasses.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 5c85f10..b7e11f8 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -44,6 +44,12 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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; } |