summaryrefslogtreecommitdiffstats
path: root/Python/traceback.c
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-04-12 23:44:07 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-04-12 23:44:07 (GMT)
commite9746890388178bb1e4cdad3c0586bf1862c3727 (patch)
tree77e228e19ac5673aac13dac8292281fc9a3010ab /Python/traceback.c
parente6c03033afc58804cfdb143bef67e9cd37e25507 (diff)
downloadcpython-e9746890388178bb1e4cdad3c0586bf1862c3727.zip
cpython-e9746890388178bb1e4cdad3c0586bf1862c3727.tar.gz
cpython-e9746890388178bb1e4cdad3c0586bf1862c3727.tar.bz2
Re-implement the 'warnings' module in C. This allows for usage of the
'warnings' code in places where it was previously not possible (e.g., the parser). It could also potentially lead to a speed-up in interpreter start-up if the C version of the code (_warnings) is imported over the use of the Python version in key places. Closes issue #1631171.
Diffstat (limited to 'Python/traceback.c')
-rw-r--r--Python/traceback.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 877ca5a..7433997 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -122,16 +122,16 @@ PyTraceBack_Here(PyFrameObject *frame)
return 0;
}
-static int
-tb_displayline(PyObject *f, char *filename, int lineno, char *name)
+int
+Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno)
{
int err = 0;
- FILE *xfp;
+ FILE *xfp = NULL;
char linebuf[2000];
int i;
char namebuf[MAXPATHLEN+1];
- if (filename == NULL || name == NULL)
+ if (filename == NULL)
return -1;
/* This is needed by Emacs' compile command */
#define FMT " File \"%.500s\", line %d, in %.500s\n"
@@ -139,7 +139,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
if (xfp == NULL) {
/* Search tail of filename in sys.path before giving up */
PyObject *path;
- char *tail = strrchr(filename, SEP);
+ const char *tail = strrchr(filename, SEP);
if (tail == NULL)
tail = filename;
else
@@ -175,14 +175,14 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
}
}
}
- PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
- err = PyFile_WriteString(linebuf, f);
- if (xfp == NULL)
- return err;
- else if (err != 0) {
- fclose(xfp);
- return err;
- }
+
+ if (xfp == NULL)
+ return err;
+ if (err != 0) {
+ fclose(xfp);
+ return err;
+ }
+
for (i = 0; i < lineno; i++) {
char* pLastChar = &linebuf[sizeof(linebuf)-2];
do {
@@ -200,22 +200,38 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
char *p = linebuf;
while (*p == ' ' || *p == '\t' || *p == '\014')
p++;
- err = PyFile_WriteString(" ", f);
- if (err == 0) {
- err = PyFile_WriteString(p, f);
- if (err == 0 && strchr(p, '\n') == NULL)
- err = PyFile_WriteString("\n", f);
- }
+ err = PyFile_WriteString(p, f);
+ if (err == 0 && strchr(p, '\n') == NULL)
+ err = PyFile_WriteString("\n", f);
}
fclose(xfp);
return err;
}
static int
-tb_printinternal(PyTracebackObject *tb, PyObject *f, int limit)
+tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)
+{
+ int err = 0;
+ char linebuf[2000];
+
+ if (filename == NULL || name == NULL)
+ return -1;
+ /* This is needed by Emacs' compile command */
+#define FMT " File \"%.500s\", line %d, in %.500s\n"
+ PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
+ err = PyFile_WriteString(linebuf, f);
+ if (err != 0)
+ return err;
+
+ err = PyFile_WriteString(" ", f);
+ return Py_DisplaySourceLine(f, filename, lineno);
+}
+
+static int
+tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
{
int err = 0;
- int depth = 0;
+ long depth = 0;
PyTracebackObject *tb1 = tb;
while (tb1 != NULL) {
depth++;
@@ -242,7 +258,7 @@ PyTraceBack_Print(PyObject *v, PyObject *f)
{
int err;
PyObject *limitv;
- int limit = 1000;
+ long limit = 1000;
if (v == NULL)
return 0;
if (!PyTraceBack_Check(v)) {