comparison Python/pythonrun.c @ 76083:013766e7a6eb 2.7

fix parse_syntax_error to clean up its resources
author Benjamin Peterson <benjamin@python.org>
date Tue, 03 Apr 2012 00:30:38 -0400
parents f9fdf519bca5
children 4ebe1ede981e
comparison
equal deleted inserted replaced
76074:2b7aff01ca89 76083:013766e7a6eb
987 /* old style errors */ 987 /* old style errors */
988 if (PyTuple_Check(err)) 988 if (PyTuple_Check(err))
989 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, 989 return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
990 lineno, offset, text); 990 lineno, offset, text);
991 991
992 *message = NULL;
993
992 /* new style errors. `err' is an instance */ 994 /* new style errors. `err' is an instance */
993 995 *message = PyObject_GetAttrString(err, "msg");
994 if (! (v = PyObject_GetAttrString(err, "msg"))) 996 if (!*message)
995 goto finally; 997 goto finally;
996 *message = v; 998
997 999 v = PyObject_GetAttrString(err, "filename");
998 if (!(v = PyObject_GetAttrString(err, "filename"))) 1000 if (!v)
999 goto finally; 1001 goto finally;
1000 if (v == Py_None) 1002 if (v == Py_None) {
1003 Py_DECREF(v);
1001 *filename = NULL; 1004 *filename = NULL;
1002 else if (! (*filename = PyString_AsString(v))) 1005 }
1003 goto finally; 1006 else {
1004 1007 *filename = PyString_AsString(v);
1005 Py_DECREF(v); 1008 Py_DECREF(v);
1006 if (!(v = PyObject_GetAttrString(err, "lineno"))) 1009 if (!*filename)
1010 goto finally;
1011 }
1012
1013 v = PyObject_GetAttrString(err, "lineno");
1014 if (!v)
1007 goto finally; 1015 goto finally;
1008 hold = PyInt_AsLong(v); 1016 hold = PyInt_AsLong(v);
1009 Py_DECREF(v); 1017 Py_DECREF(v);
1010 v = NULL;
1011 if (hold < 0 && PyErr_Occurred()) 1018 if (hold < 0 && PyErr_Occurred())
1012 goto finally; 1019 goto finally;
1013 *lineno = (int)hold; 1020 *lineno = (int)hold;
1014 1021
1015 if (!(v = PyObject_GetAttrString(err, "offset"))) 1022 v = PyObject_GetAttrString(err, "offset");
1023 if (!v)
1016 goto finally; 1024 goto finally;
1017 if (v == Py_None) { 1025 if (v == Py_None) {
1018 *offset = -1; 1026 *offset = -1;
1019 Py_DECREF(v); 1027 Py_DECREF(v);
1020 v = NULL;
1021 } else { 1028 } else {
1022 hold = PyInt_AsLong(v); 1029 hold = PyInt_AsLong(v);
1023 Py_DECREF(v); 1030 Py_DECREF(v);
1024 v = NULL;
1025 if (hold < 0 && PyErr_Occurred()) 1031 if (hold < 0 && PyErr_Occurred())
1026 goto finally; 1032 goto finally;
1027 *offset = (int)hold; 1033 *offset = (int)hold;
1028 } 1034 }
1029 1035
1030 if (!(v = PyObject_GetAttrString(err, "text"))) 1036 v = PyObject_GetAttrString(err, "text");
1037 if (!v)
1031 goto finally; 1038 goto finally;
1032 if (v == Py_None) 1039 if (v == Py_None) {
1040 Py_DECREF(v);
1033 *text = NULL; 1041 *text = NULL;
1034 else if (! (*text = PyString_AsString(v))) 1042 }
1035 goto finally; 1043 else {
1036 Py_DECREF(v); 1044 *text = PyString_AsString(v);
1045 Py_DECREF(v);
1046 if (!*text)
1047 goto finally;
1048 }
1037 return 1; 1049 return 1;
1038 1050
1039 finally: 1051 finally:
1040 Py_XDECREF(v); 1052 Py_XDECREF(*message);
1041 return 0; 1053 return 0;
1042 } 1054 }
1043 1055
1044 void 1056 void
1045 PyErr_Print(void) 1057 PyErr_Print(void)