Commit 2a0ad4db authored by Martin v. Löwis's avatar Martin v. Löwis

Remove bogus DECREF of self.

Change __str__() functions to METH_O.
Change WindowsError__str__ to use PyTuple_Pack.
parent 1004a533
...@@ -223,12 +223,9 @@ BaseException__init__(PyObject *self, PyObject *args) ...@@ -223,12 +223,9 @@ BaseException__init__(PyObject *self, PyObject *args)
static PyObject * static PyObject *
BaseException__str__(PyObject *self, PyObject *args) BaseException__str__(PyObject *_self, PyObject *self)
{ {
PyObject *out; PyObject *out, *args;
if (!PyArg_ParseTuple(args, "O:__str__", &self))
return NULL;
args = PyObject_GetAttrString(self, "args"); args = PyObject_GetAttrString(self, "args");
if (!args) if (!args)
...@@ -376,7 +373,7 @@ BaseException_methods[] = { ...@@ -376,7 +373,7 @@ BaseException_methods[] = {
/* methods for the BaseException class */ /* methods for the BaseException class */
{"__getitem__", BaseException__getitem__, METH_VARARGS}, {"__getitem__", BaseException__getitem__, METH_VARARGS},
{"__repr__", BaseException__repr__, METH_VARARGS}, {"__repr__", BaseException__repr__, METH_VARARGS},
{"__str__", BaseException__str__, METH_VARARGS}, {"__str__", BaseException__str__, METH_O},
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
{"__unicode__", BaseException__unicode__, METH_VARARGS}, {"__unicode__", BaseException__unicode__, METH_VARARGS},
#endif /* Py_USING_UNICODE */ #endif /* Py_USING_UNICODE */
...@@ -617,17 +614,13 @@ EnvironmentError__init__(PyObject *self, PyObject *args) ...@@ -617,17 +614,13 @@ EnvironmentError__init__(PyObject *self, PyObject *args)
static PyObject * static PyObject *
EnvironmentError__str__(PyObject *self, PyObject *args) EnvironmentError__str__(PyObject *originalself, PyObject *self)
{ {
PyObject *originalself = self;
PyObject *filename; PyObject *filename;
PyObject *serrno; PyObject *serrno;
PyObject *strerror; PyObject *strerror;
PyObject *rtnval = NULL; PyObject *rtnval = NULL;
if (!PyArg_ParseTuple(args, "O:__str__", &self))
return NULL;
filename = PyObject_GetAttrString(self, "filename"); filename = PyObject_GetAttrString(self, "filename");
serrno = PyObject_GetAttrString(self, "errno"); serrno = PyObject_GetAttrString(self, "errno");
strerror = PyObject_GetAttrString(self, "strerror"); strerror = PyObject_GetAttrString(self, "strerror");
...@@ -687,7 +680,7 @@ EnvironmentError__str__(PyObject *self, PyObject *args) ...@@ -687,7 +680,7 @@ EnvironmentError__str__(PyObject *self, PyObject *args)
* but there is no StandardError__str__() function; we happen to * but there is no StandardError__str__() function; we happen to
* know that's just a pass through to BaseException__str__(). * know that's just a pass through to BaseException__str__().
*/ */
rtnval = BaseException__str__(originalself, args); rtnval = BaseException__str__(originalself, self);
finally: finally:
Py_XDECREF(filename); Py_XDECREF(filename);
...@@ -700,7 +693,7 @@ EnvironmentError__str__(PyObject *self, PyObject *args) ...@@ -700,7 +693,7 @@ EnvironmentError__str__(PyObject *self, PyObject *args)
static static
PyMethodDef EnvironmentError_methods[] = { PyMethodDef EnvironmentError_methods[] = {
{"__init__", EnvironmentError__init__, METH_VARARGS}, {"__init__", EnvironmentError__init__, METH_VARARGS},
{"__str__", EnvironmentError__str__, METH_VARARGS}, {"__str__", EnvironmentError__str__, METH_O},
{NULL, NULL} {NULL, NULL}
}; };
...@@ -746,23 +739,21 @@ WindowsError__init__(PyObject *self, PyObject *args) ...@@ -746,23 +739,21 @@ WindowsError__init__(PyObject *self, PyObject *args)
failed: failed:
/* Could not set errno. */ /* Could not set errno. */
Py_XDECREF(o_errcode); Py_XDECREF(o_errcode);
Py_DECREF(self);
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
static PyObject * static PyObject *
WindowsError__str__(PyObject *self, PyObject *args) WindowsError__str__(PyObject *originalself, PyObject *self)
{ {
PyObject *originalself = self;
PyObject *filename; PyObject *filename;
PyObject *serrno; PyObject *serrno;
PyObject *strerror; PyObject *strerror;
PyObject *repr = NULL;
PyObject *fmt = NULL;
PyObject *tuple = NULL;
PyObject *rtnval = NULL; PyObject *rtnval = NULL;
if (!PyArg_ParseTuple(args, "O:__str__", &self))
return NULL;
filename = PyObject_GetAttrString(self, "filename"); filename = PyObject_GetAttrString(self, "filename");
serrno = PyObject_GetAttrString(self, "winerror"); serrno = PyObject_GetAttrString(self, "winerror");
strerror = PyObject_GetAttrString(self, "strerror"); strerror = PyObject_GetAttrString(self, "strerror");
...@@ -770,64 +761,46 @@ WindowsError__str__(PyObject *self, PyObject *args) ...@@ -770,64 +761,46 @@ WindowsError__str__(PyObject *self, PyObject *args)
goto finally; goto finally;
if (filename != Py_None) { if (filename != Py_None) {
PyObject *fmt = PyString_FromString("[Error %s] %s: %s"); fmt = PyString_FromString("[Error %s] %s: %s");
PyObject *repr = PyObject_Repr(filename); repr = PyObject_Repr(filename);
PyObject *tuple = PyTuple_New(3); if (!fmt || !repr)
if (!fmt || !repr || !tuple) {
Py_XDECREF(fmt);
Py_XDECREF(repr);
Py_XDECREF(tuple);
goto finally; goto finally;
}
PyTuple_SET_ITEM(tuple, 0, serrno);
PyTuple_SET_ITEM(tuple, 1, strerror);
PyTuple_SET_ITEM(tuple, 2, repr);
rtnval = PyString_Format(fmt, tuple); tuple = PyTuple_Pack(3, serrno, strerror, repr);
if (!tuple)
goto finally;
Py_DECREF(fmt); rtnval = PyString_Format(fmt, tuple);
Py_DECREF(tuple);
/* already freed because tuple owned only reference */
serrno = NULL;
strerror = NULL;
} }
else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) { else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) {
PyObject *fmt = PyString_FromString("[Error %s] %s"); fmt = PyString_FromString("[Error %s] %s");
PyObject *tuple = PyTuple_New(2); if (!fmt)
if (!fmt || !tuple) {
Py_XDECREF(fmt);
Py_XDECREF(tuple);
goto finally; goto finally;
}
PyTuple_SET_ITEM(tuple, 0, serrno); tuple = PyTuple_Pack(2, serrno, strerror);
PyTuple_SET_ITEM(tuple, 1, strerror); if (!tuple)
goto finally;
rtnval = PyString_Format(fmt, tuple); rtnval = PyString_Format(fmt, tuple);
Py_DECREF(fmt);
Py_DECREF(tuple);
/* already freed because tuple owned only reference */
serrno = NULL;
strerror = NULL;
} }
else else
rtnval = EnvironmentError__str__(originalself, args); rtnval = EnvironmentError__str__(originalself, self);
finally: finally:
Py_XDECREF(filename); Py_XDECREF(filename);
Py_XDECREF(serrno); Py_XDECREF(serrno);
Py_XDECREF(strerror); Py_XDECREF(strerror);
Py_XDECREF(repr);
Py_XDECREF(fmt);
Py_XDECREF(tuple);
return rtnval; return rtnval;
} }
static static
PyMethodDef WindowsError_methods[] = { PyMethodDef WindowsError_methods[] = {
{"__init__", WindowsError__init__, METH_VARARGS}, {"__init__", WindowsError__init__, METH_VARARGS},
{"__str__", WindowsError__str__, METH_VARARGS}, {"__str__", WindowsError__str__, METH_O},
{NULL, NULL} {NULL, NULL}
}; };
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
...@@ -972,15 +945,12 @@ my_basename(char *name) ...@@ -972,15 +945,12 @@ my_basename(char *name)
static PyObject * static PyObject *
SyntaxError__str__(PyObject *self, PyObject *args) SyntaxError__str__(PyObject *_self, PyObject *self)
{ {
PyObject *msg; PyObject *msg;
PyObject *str; PyObject *str;
PyObject *filename, *lineno, *result; PyObject *filename, *lineno, *result;
if (!PyArg_ParseTuple(args, "O:__str__", &self))
return NULL;
if (!(msg = PyObject_GetAttrString(self, "msg"))) if (!(msg = PyObject_GetAttrString(self, "msg")))
return NULL; return NULL;
...@@ -1045,20 +1015,17 @@ SyntaxError__str__(PyObject *self, PyObject *args) ...@@ -1045,20 +1015,17 @@ SyntaxError__str__(PyObject *self, PyObject *args)
static PyMethodDef SyntaxError_methods[] = { static PyMethodDef SyntaxError_methods[] = {
{"__init__", SyntaxError__init__, METH_VARARGS}, {"__init__", SyntaxError__init__, METH_VARARGS},
{"__str__", SyntaxError__str__, METH_VARARGS}, {"__str__", SyntaxError__str__, METH_O},
{NULL, NULL} {NULL, NULL}
}; };
static PyObject * static PyObject *
KeyError__str__(PyObject *self, PyObject *args) KeyError__str__(PyObject *_self, PyObject *self)
{ {
PyObject *argsattr; PyObject *argsattr;
PyObject *result; PyObject *result;
if (!PyArg_ParseTuple(args, "O:__str__", &self))
return NULL;
argsattr = PyObject_GetAttrString(self, "args"); argsattr = PyObject_GetAttrString(self, "args");
if (!argsattr) if (!argsattr)
return NULL; return NULL;
...@@ -1077,14 +1044,14 @@ KeyError__str__(PyObject *self, PyObject *args) ...@@ -1077,14 +1044,14 @@ KeyError__str__(PyObject *self, PyObject *args)
result = PyObject_Repr(key); result = PyObject_Repr(key);
} }
else else
result = BaseException__str__(self, args); result = BaseException__str__(_self, self);
Py_DECREF(argsattr); Py_DECREF(argsattr);
return result; return result;
} }
static PyMethodDef KeyError_methods[] = { static PyMethodDef KeyError_methods[] = {
{"__str__", KeyError__str__, METH_VARARGS}, {"__str__", KeyError__str__, METH_O},
{NULL, NULL} {NULL, NULL}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment