diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-01-05 19:27:54 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-01-05 19:27:54 (GMT) |
commit | 576f132b986b5ee60e4b84d34a519a5edcd8c03e (patch) | |
tree | f048292ddc0b5c3d6a5afc50dc2cd4b28372c655 /Objects/exceptions.c | |
parent | dcf76c9d0ab11f77eaa856ff0583c5c636ddb47d (diff) | |
download | cpython-576f132b986b5ee60e4b84d34a519a5edcd8c03e.zip cpython-576f132b986b5ee60e4b84d34a519a5edcd8c03e.tar.gz cpython-576f132b986b5ee60e4b84d34a519a5edcd8c03e.tar.bz2 |
Issue #20440: Cleaning up the code by using Py_SETREF.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 85f9472..7374368 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_SETREF(self->args, args); 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_SETREF(((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_SETREF(((PyBaseExceptionObject *)self)->context, context); } |