diff -r da3f4774b939 Objects/exceptions.c --- a/Objects/exceptions.c Mon Mar 11 09:14:09 2013 +0200 +++ b/Objects/exceptions.c Mon Mar 11 13:55:41 2013 +0530 @@ -35,16 +35,22 @@ if (!self) return NULL; /* the dict is created on the fly in PyObject_GenericSetAttr */ - self->message = self->dict = NULL; + self->dict = NULL; - self->args = PyTuple_New(0); - if (!self->args) { + self->message = PyString_FromString(""); + if (!self->message) { Py_DECREF(self); return NULL; } - self->message = PyString_FromString(""); - if (!self->message) { + if(args){ + self->args = args; + Py_INCREF(args); + return (PyObject *) self; + } + + self->args = PyTuple_New(0); + if (!self->args) { Py_DECREF(self); return NULL; } @@ -55,12 +61,14 @@ static int BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) { + PyObject *tmp; if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) return -1; - Py_DECREF(self->args); + tmp = self->args; self->args = args; Py_INCREF(self->args); + Py_XDECREF(tmp); if (PyTuple_GET_SIZE(self->args) == 1) { Py_CLEAR(self->message);