comparison Python/pythonrun.c @ 31771:76053a1dd452 legacy-trunk

Lost reference.
author Armin Rigo <arigo@tunes.org>
date Mon, 22 Mar 2004 20:16:58 +0000
parents 2abc52c3d4c2
children 846b3ee7e106
comparison
equal deleted inserted replaced
31770:ef591e7c34fd 31771:76053a1dd452
1084 } 1084 }
1085 1085
1086 void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) 1086 void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
1087 { 1087 {
1088 int err = 0; 1088 int err = 0;
1089 PyObject *v = value;
1090 PyObject *f = PySys_GetObject("stderr"); 1089 PyObject *f = PySys_GetObject("stderr");
1090 Py_INCREF(value);
1091 if (f == NULL) 1091 if (f == NULL)
1092 fprintf(stderr, "lost sys.stderr\n"); 1092 fprintf(stderr, "lost sys.stderr\n");
1093 else { 1093 else {
1094 if (Py_FlushLine()) 1094 if (Py_FlushLine())
1095 PyErr_Clear(); 1095 PyErr_Clear();
1096 fflush(stdout); 1096 fflush(stdout);
1097 if (tb && tb != Py_None) 1097 if (tb && tb != Py_None)
1098 err = PyTraceBack_Print(tb, f); 1098 err = PyTraceBack_Print(tb, f);
1099 if (err == 0 && 1099 if (err == 0 &&
1100 PyObject_HasAttrString(v, "print_file_and_line")) 1100 PyObject_HasAttrString(value, "print_file_and_line"))
1101 { 1101 {
1102 PyObject *message; 1102 PyObject *message;
1103 const char *filename, *text; 1103 const char *filename, *text;
1104 int lineno, offset; 1104 int lineno, offset;
1105 if (!parse_syntax_error(v, &message, &filename, 1105 if (!parse_syntax_error(value, &message, &filename,
1106 &lineno, &offset, &text)) 1106 &lineno, &offset, &text))
1107 PyErr_Clear(); 1107 PyErr_Clear();
1108 else { 1108 else {
1109 char buf[10]; 1109 char buf[10];
1110 PyFile_WriteString(" File \"", f); 1110 PyFile_WriteString(" File \"", f);
1116 PyOS_snprintf(buf, sizeof(buf), "%d", lineno); 1116 PyOS_snprintf(buf, sizeof(buf), "%d", lineno);
1117 PyFile_WriteString(buf, f); 1117 PyFile_WriteString(buf, f);
1118 PyFile_WriteString("\n", f); 1118 PyFile_WriteString("\n", f);
1119 if (text != NULL) 1119 if (text != NULL)
1120 print_error_text(f, offset, text); 1120 print_error_text(f, offset, text);
1121 v = message; 1121 Py_DECREF(value);
1122 value = message;
1122 /* Can't be bothered to check all those 1123 /* Can't be bothered to check all those
1123 PyFile_WriteString() calls */ 1124 PyFile_WriteString() calls */
1124 if (PyErr_Occurred()) 1125 if (PyErr_Occurred())
1125 err = -1; 1126 err = -1;
1126 } 1127 }
1153 } 1154 }
1154 } 1155 }
1155 else 1156 else
1156 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); 1157 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
1157 if (err == 0) { 1158 if (err == 0) {
1158 if (v != NULL && v != Py_None) { 1159 if (value != Py_None) {
1159 PyObject *s = PyObject_Str(v); 1160 PyObject *s = PyObject_Str(value);
1160 /* only print colon if the str() of the 1161 /* only print colon if the str() of the
1161 object is not the empty string 1162 object is not the empty string
1162 */ 1163 */
1163 if (s == NULL) 1164 if (s == NULL)
1164 err = -1; 1165 err = -1;
1171 } 1172 }
1172 } 1173 }
1173 if (err == 0) 1174 if (err == 0)
1174 err = PyFile_WriteString("\n", f); 1175 err = PyFile_WriteString("\n", f);
1175 } 1176 }
1177 Py_DECREF(value);
1176 /* If an error happened here, don't show it. 1178 /* If an error happened here, don't show it.
1177 XXX This is wrong, but too many callers rely on this behavior. */ 1179 XXX This is wrong, but too many callers rely on this behavior. */
1178 if (err != 0) 1180 if (err != 0)
1179 PyErr_Clear(); 1181 PyErr_Clear();
1180 } 1182 }