[Python-checkins] cpython (2.7): fix parse_syntax_error to clean up its resources
benjamin.peterson
python-checkins at python.org
Tue Apr 3 06:35:50 CEST 2012
http://hg.python.org/cpython/rev/013766e7a6eb
changeset: 76083:013766e7a6eb
branch: 2.7
parent: 76074:2b7aff01ca89
user: Benjamin Peterson <benjamin at python.org>
date: Tue Apr 03 00:30:38 2012 -0400
summary:
fix parse_syntax_error to clean up its resources
files:
Python/pythonrun.c | 56 ++++++++++++++++++++-------------
1 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -989,55 +989,67 @@
return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
lineno, offset, text);
+ *message = NULL;
+
/* new style errors. `err' is an instance */
-
- if (! (v = PyObject_GetAttrString(err, "msg")))
- goto finally;
- *message = v;
-
- if (!(v = PyObject_GetAttrString(err, "filename")))
- goto finally;
- if (v == Py_None)
- *filename = NULL;
- else if (! (*filename = PyString_AsString(v)))
+ *message = PyObject_GetAttrString(err, "msg");
+ if (!*message)
goto finally;
- Py_DECREF(v);
- if (!(v = PyObject_GetAttrString(err, "lineno")))
+ v = PyObject_GetAttrString(err, "filename");
+ if (!v)
+ goto finally;
+ if (v == Py_None) {
+ Py_DECREF(v);
+ *filename = NULL;
+ }
+ else {
+ *filename = PyString_AsString(v);
+ Py_DECREF(v);
+ if (!*filename)
+ goto finally;
+ }
+
+ v = PyObject_GetAttrString(err, "lineno");
+ if (!v)
goto finally;
hold = PyInt_AsLong(v);
Py_DECREF(v);
- v = NULL;
if (hold < 0 && PyErr_Occurred())
goto finally;
*lineno = (int)hold;
- if (!(v = PyObject_GetAttrString(err, "offset")))
+ v = PyObject_GetAttrString(err, "offset");
+ if (!v)
goto finally;
if (v == Py_None) {
*offset = -1;
Py_DECREF(v);
- v = NULL;
} else {
hold = PyInt_AsLong(v);
Py_DECREF(v);
- v = NULL;
if (hold < 0 && PyErr_Occurred())
goto finally;
*offset = (int)hold;
}
- if (!(v = PyObject_GetAttrString(err, "text")))
+ v = PyObject_GetAttrString(err, "text");
+ if (!v)
goto finally;
- if (v == Py_None)
+ if (v == Py_None) {
+ Py_DECREF(v);
*text = NULL;
- else if (! (*text = PyString_AsString(v)))
- goto finally;
- Py_DECREF(v);
+ }
+ else {
+ *text = PyString_AsString(v);
+ Py_DECREF(v);
+ if (!*text)
+ goto finally;
+ }
return 1;
finally:
- Py_XDECREF(v);
+ Py_XDECREF(*message);
return 0;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list