summaryrefslogtreecommitdiff
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-01-05 21:27:54 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2016-01-05 21:27:54 +0200
commit93c98b688bef3bf08c027315a744869b590ceef3 (patch)
tree40957d06fc05cda36c06cca475e8bef11999ed78 /Objects/exceptions.c
parentc8a68313d9003cacd48415cca4beb12b7bf386ba (diff)
downloadcpython-93c98b688bef3bf08c027315a744869b590ceef3.tar.gz
Issue #20440: Cleaning up the code by using Py_SETREF.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 85f9472d2a..7374368164 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);
}