From b384a4aaa907218aebcb9d60e22afcc30301a3c6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 28 Sep 2016 07:53:32 +0300 Subject: Issue #28289: ImportError.__init__ now resets not specified attributes. --- Objects/exceptions.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'Objects/exceptions.c') diff --git a/Objects/exceptions.c b/Objects/exceptions.c index f63f06a145..bc0264a5e9 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -631,19 +631,17 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) } Py_DECREF(empty_tuple); - if (name) { - Py_INCREF(name); - Py_XSETREF(self->name, name); - } - if (path) { - Py_INCREF(path); - Py_XSETREF(self->path, path); - } + Py_XINCREF(name); + Py_XSETREF(self->name, name); + + Py_XINCREF(path); + Py_XSETREF(self->path, path); + if (PyTuple_GET_SIZE(args) == 1) { msg = PyTuple_GET_ITEM(args, 0); Py_INCREF(msg); - Py_XSETREF(self->msg, msg); } + Py_XSETREF(self->msg, msg); return 0; } -- cgit v1.2.1 From 6ed55b2d31ec9afacbecd309d2c3a4c099848a6c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 23 Oct 2016 15:12:25 +0300 Subject: Issue #28511: Use the "U" format instead of "O!" in PyArg_Parse*. --- Objects/exceptions.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'Objects/exceptions.c') diff --git a/Objects/exceptions.c b/Objects/exceptions.c index bc0264a5e9..57a786c022 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1820,18 +1820,10 @@ UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) Py_CLEAR(err->object); Py_CLEAR(err->reason); - if (!PyArg_ParseTuple(args, "O!O!nnO!", - &PyUnicode_Type, &err->encoding, - &PyUnicode_Type, &err->object, - &err->start, - &err->end, - &PyUnicode_Type, &err->reason)) { - err->encoding = err->object = err->reason = NULL; - return -1; - } - - if (PyUnicode_READY(err->object) < -1) { - err->encoding = NULL; + if (!PyArg_ParseTuple(args, "UUnnU", + &err->encoding, &err->object, + &err->start, &err->end, &err->reason)) { + err->encoding = err->object = err->reason = NULL; return -1; } @@ -1935,12 +1927,9 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) Py_CLEAR(ude->object); Py_CLEAR(ude->reason); - if (!PyArg_ParseTuple(args, "O!OnnO!", - &PyUnicode_Type, &ude->encoding, - &ude->object, - &ude->start, - &ude->end, - &PyUnicode_Type, &ude->reason)) { + if (!PyArg_ParseTuple(args, "UOnnU", + &ude->encoding, &ude->object, + &ude->start, &ude->end, &ude->reason)) { ude->encoding = ude->object = ude->reason = NULL; return -1; } @@ -2050,11 +2039,9 @@ UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args, Py_CLEAR(self->object); Py_CLEAR(self->reason); - if (!PyArg_ParseTuple(args, "O!nnO!", - &PyUnicode_Type, &self->object, - &self->start, - &self->end, - &PyUnicode_Type, &self->reason)) { + if (!PyArg_ParseTuple(args, "UnnU", + &self->object, + &self->start, &self->end, &self->reason)) { self->object = self->reason = NULL; return -1; } -- cgit v1.2.1 From bfeec6d871e3db2e0ddfdef01387913bc19cadd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 23 Jan 2017 09:47:21 +0200 Subject: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever possible. Patch is writen with Coccinelle. --- Objects/exceptions.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Objects/exceptions.c') diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 57a786c022..35a8b66e01 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -184,8 +184,7 @@ static PyObject * BaseException_get_args(PyBaseExceptionObject *self) { if (self->args == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } Py_INCREF(self->args); return self->args; @@ -210,8 +209,7 @@ static PyObject * BaseException_get_tb(PyBaseExceptionObject *self) { if (self->traceback == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } Py_INCREF(self->traceback); return self->traceback; -- cgit v1.2.1