diff options
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 0749e908496..336c32c8a46 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -59,15 +59,11 @@ 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; - tmp = self->args; - self->args = args; - Py_INCREF(self->args); - Py_XDECREF(tmp); + Py_INCREF(args); + Py_XSETREF(self->args, args); return 0; } @@ -234,7 +230,7 @@ BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb) return -1; } - Py_XINCREF(tb); + Py_INCREF(tb); Py_XSETREF(self->traceback, tb); return 0; } @@ -328,11 +324,10 @@ PyException_GetCause(PyObject *self) { /* Steals a reference to cause */ void -PyException_SetCause(PyObject *self, PyObject *cause) { - PyObject *old_cause = ((PyBaseExceptionObject *)self)->cause; - ((PyBaseExceptionObject *)self)->cause = cause; +PyException_SetCause(PyObject *self, PyObject *cause) +{ ((PyBaseExceptionObject *)self)->suppress_context = 1; - Py_XDECREF(old_cause); + Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause); } PyObject * @@ -344,10 +339,9 @@ PyException_GetContext(PyObject *self) { /* Steals a reference to context */ void -PyException_SetContext(PyObject *self, PyObject *context) { - PyObject *old_context = ((PyBaseExceptionObject *)self)->context; - ((PyBaseExceptionObject *)self)->context = context; - Py_XDECREF(old_context); +PyException_SetContext(PyObject *self, PyObject *context) +{ + Py_XSETREF(((PyBaseExceptionObject *)self)->context, context); } @@ -991,7 +985,7 @@ OSError_init(PyOSErrorObject *self, PyObject *args, PyObject *kwds) return 0; error: - Py_XDECREF(args); + Py_DECREF(args); return -1; } @@ -1071,8 +1065,7 @@ OSError_str(PyOSErrorObject *self) } if (self->myerrno && self->strerror) return PyUnicode_FromFormat("[Errno %S] %S", - self->myerrno ? self->myerrno: Py_None, - self->strerror ? self->strerror: Py_None); + self->myerrno, self->strerror); return BaseException_str((PyBaseExceptionObject *)self); } @@ -2610,7 +2603,9 @@ _PyExc_Init(PyObject *bltinmod) ADD_ERRNO(BlockingIOError, EWOULDBLOCK); POST_INIT(BrokenPipeError); ADD_ERRNO(BrokenPipeError, EPIPE); +#ifdef ESHUTDOWN ADD_ERRNO(BrokenPipeError, ESHUTDOWN); +#endif POST_INIT(ChildProcessError); ADD_ERRNO(ChildProcessError, ECHILD); POST_INIT(ConnectionAbortedError); |