Mercurial > cpython-lru_cache-weakref
comparison Python/traceback.c @ 47933:4f804ee772eb legacy-trunk
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> |
|---|---|
| date | Fri, 11 Jul 2008 21:45:06 +0000 |
| parents | 52294af4b663 |
| children | fb80b281e05a |
comparison
equal
deleted
inserted
replaced
| 47932:13e525d974b1 | 47933:4f804ee772eb |
|---|---|
| 121 Py_XDECREF(oldtb); | 121 Py_XDECREF(oldtb); |
| 122 return 0; | 122 return 0; |
| 123 } | 123 } |
| 124 | 124 |
| 125 int | 125 int |
| 126 Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno) | 126 _Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent) |
| 127 { | 127 { |
| 128 int err = 0; | 128 int err = 0; |
| 129 FILE *xfp = NULL; | 129 FILE *xfp = NULL; |
| 130 char linebuf[2000]; | 130 char linebuf[2000]; |
| 131 int i; | 131 int i; |
| 195 it obviously found a newline; else we haven't | 195 it obviously found a newline; else we haven't |
| 196 yet seen a newline, so must continue */ | 196 yet seen a newline, so must continue */ |
| 197 } while (*pLastChar != '\0' && *pLastChar != '\n'); | 197 } while (*pLastChar != '\0' && *pLastChar != '\n'); |
| 198 } | 198 } |
| 199 if (i == lineno) { | 199 if (i == lineno) { |
| 200 char buf[11]; | |
| 200 char *p = linebuf; | 201 char *p = linebuf; |
| 201 while (*p == ' ' || *p == '\t' || *p == '\014') | 202 while (*p == ' ' || *p == '\t' || *p == '\014') |
| 202 p++; | 203 p++; |
| 203 err = PyFile_WriteString(p, f); | 204 |
| 204 if (err == 0 && strchr(p, '\n') == NULL) | 205 /* Write some spaces before the line */ |
| 205 err = PyFile_WriteString("\n", f); | 206 strcpy(buf, " "); |
| 207 assert (strlen(buf) == 10); | |
| 208 while (indent > 0) { | |
| 209 if(indent < 10) | |
| 210 buf[indent] = '\0'; | |
| 211 err = PyFile_WriteString(buf, f); | |
| 212 if (err != 0) | |
| 213 break; | |
| 214 indent -= 10; | |
| 215 } | |
| 216 | |
| 217 if (err == 0) | |
| 218 err = PyFile_WriteString(p, f); | |
| 219 if (err == 0 && strchr(p, '\n') == NULL) | |
| 220 err = PyFile_WriteString("\n", f); | |
| 206 } | 221 } |
| 207 fclose(xfp); | 222 fclose(xfp); |
| 208 return err; | 223 return err; |
| 209 } | 224 } |
| 210 | 225 |
| 220 #define FMT " File \"%.500s\", line %d, in %.500s\n" | 235 #define FMT " File \"%.500s\", line %d, in %.500s\n" |
| 221 PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name); | 236 PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name); |
| 222 err = PyFile_WriteString(linebuf, f); | 237 err = PyFile_WriteString(linebuf, f); |
| 223 if (err != 0) | 238 if (err != 0) |
| 224 return err; | 239 return err; |
| 225 return Py_DisplaySourceLine(f, filename, lineno); | 240 return _Py_DisplaySourceLine(f, filename, lineno, 4); |
| 226 } | 241 } |
| 227 | 242 |
| 228 static int | 243 static int |
| 229 tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) | 244 tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) |
| 230 { | 245 { |
