comparison Python/pythonrun.c @ 31774:164ce1bcab6e 2.3

Backport for bug fix of 2.204.
author Armin Rigo <arigo@tunes.org>
date Mon, 22 Mar 2004 20:41:47 +0000
parents bf7df48012cb
children 517e00af13a1
comparison
equal deleted inserted replaced
31773:9d84ced64d10 31774:164ce1bcab6e
1096 } 1096 }
1097 1097
1098 void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) 1098 void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
1099 { 1099 {
1100 int err = 0; 1100 int err = 0;
1101 PyObject *v = value;
1102 PyObject *f = PySys_GetObject("stderr"); 1101 PyObject *f = PySys_GetObject("stderr");
1102 Py_INCREF(value);
1103 if (f == NULL) 1103 if (f == NULL)
1104 fprintf(stderr, "lost sys.stderr\n"); 1104 fprintf(stderr, "lost sys.stderr\n");
1105 else { 1105 else {
1106 if (Py_FlushLine()) 1106 if (Py_FlushLine())
1107 PyErr_Clear(); 1107 PyErr_Clear();
1108 fflush(stdout); 1108 fflush(stdout);
1109 if (tb && tb != Py_None) 1109 if (tb && tb != Py_None)
1110 err = PyTraceBack_Print(tb, f); 1110 err = PyTraceBack_Print(tb, f);
1111 if (err == 0 && 1111 if (err == 0 &&
1112 PyObject_HasAttrString(v, "print_file_and_line")) 1112 PyObject_HasAttrString(value, "print_file_and_line"))
1113 { 1113 {
1114 PyObject *message; 1114 PyObject *message;
1115 const char *filename, *text; 1115 const char *filename, *text;
1116 int lineno, offset; 1116 int lineno, offset;
1117 if (!parse_syntax_error(v, &message, &filename, 1117 if (!parse_syntax_error(value, &message, &filename,
1118 &lineno, &offset, &text)) 1118 &lineno, &offset, &text))
1119 PyErr_Clear(); 1119 PyErr_Clear();
1120 else { 1120 else {
1121 char buf[10]; 1121 char buf[10];
1122 PyFile_WriteString(" File \"", f); 1122 PyFile_WriteString(" File \"", f);
1128 PyOS_snprintf(buf, sizeof(buf), "%d", lineno); 1128 PyOS_snprintf(buf, sizeof(buf), "%d", lineno);
1129 PyFile_WriteString(buf, f); 1129 PyFile_WriteString(buf, f);
1130 PyFile_WriteString("\n", f); 1130 PyFile_WriteString("\n", f);
1131 if (text != NULL) 1131 if (text != NULL)
1132 print_error_text(f, offset, text); 1132 print_error_text(f, offset, text);
1133 v = message; 1133 Py_DECREF(value);
1134 value = message;
1134 /* Can't be bothered to check all those 1135 /* Can't be bothered to check all those
1135 PyFile_WriteString() calls */ 1136 PyFile_WriteString() calls */
1136 if (PyErr_Occurred()) 1137 if (PyErr_Occurred())
1137 err = -1; 1138 err = -1;
1138 } 1139 }
1165 } 1166 }
1166 } 1167 }
1167 else 1168 else
1168 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); 1169 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
1169 if (err == 0) { 1170 if (err == 0) {
1170 if (v != NULL && v != Py_None) { 1171 if (value != Py_None) {
1171 PyObject *s = PyObject_Str(v); 1172 PyObject *s = PyObject_Str(value);
1172 /* only print colon if the str() of the 1173 /* only print colon if the str() of the
1173 object is not the empty string 1174 object is not the empty string
1174 */ 1175 */
1175 if (s == NULL) 1176 if (s == NULL)
1176 err = -1; 1177 err = -1;
1183 } 1184 }
1184 } 1185 }
1185 if (err == 0) 1186 if (err == 0)
1186 err = PyFile_WriteString("\n", f); 1187 err = PyFile_WriteString("\n", f);
1187 } 1188 }
1189 Py_DECREF(value);
1188 /* If an error happened here, don't show it. 1190 /* If an error happened here, don't show it.
1189 XXX This is wrong, but too many callers rely on this behavior. */ 1191 XXX This is wrong, but too many callers rely on this behavior. */
1190 if (err != 0) 1192 if (err != 0)
1191 PyErr_Clear(); 1193 PyErr_Clear();
1192 } 1194 }