[pypy-commit] pypy remove-PYPY_NOT_MAIN_FILE: Split debug_traceback: .h and .c.
amauryfa
noreply at buildbot.pypy.org
Tue Oct 2 16:37:47 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57725:6fc70071ea32
Date: 2012-10-02 14:59 +0200
http://bitbucket.org/pypy/pypy/changeset/6fc70071ea32/
Log: Split debug_traceback: .h and .c.
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -911,6 +911,7 @@
srcdir / 'mem.c',
srcdir / 'profiling.c',
srcdir / 'debug_print.c',
+ srcdir / 'debug_traceback.c',
srcdir / 'thread.c',
srcdir / 'asm.c',
srcdir / 'instrument.c',
diff --git a/pypy/translator/c/src/debug_traceback.c b/pypy/translator/c/src/debug_traceback.c
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/debug_traceback.c
@@ -0,0 +1,71 @@
+#include "common_header.h"
+#include "structdef.h"
+#include "forwarddecl.h"
+#include "preimpl.h"
+#include "src/debug_traceback.h"
+#include <stdio.h>
+
+int pypydtcount = 0;
+struct pypydtentry_s pypy_debug_tracebacks[PYPY_DEBUG_TRACEBACK_DEPTH];
+
+void pypy_debug_traceback_print(void)
+{
+ int i;
+ int skipping;
+ void *my_etype = RPyFetchExceptionType();
+ struct pypydtpos_s *location;
+ void *etype;
+ int has_loc;
+
+ /* This code parses the pypy_debug_tracebacks array. See example
+ at the start of the file. */
+ fprintf(stderr, "RPython traceback:\n");
+ skipping = 0;
+ i = pypydtcount;
+ while (1)
+ {
+ i = (i - 1) & (PYPY_DEBUG_TRACEBACK_DEPTH-1);
+ if (i == pypydtcount)
+ {
+ fprintf(stderr, " ...\n");
+ break;
+ }
+
+ location = pypy_debug_tracebacks[i].location;
+ etype = pypy_debug_tracebacks[i].exctype;
+ has_loc = location != NULL && location != PYPYDTPOS_RERAISE;
+
+ if (skipping && has_loc && etype == my_etype)
+ skipping = 0; /* found the matching "f:17, &KeyError */
+
+ if (!skipping)
+ {
+ if (has_loc)
+ fprintf(stderr, " File \"%s\", line %d, in %s\n",
+ location->filename, location->lineno, location->funcname);
+ else
+ {
+ /* line "NULL, &KeyError" or "RERAISE, &KeyError" */
+ if (!my_etype)
+ my_etype = etype;
+ if (etype != my_etype)
+ {
+ fprintf(stderr, " Note: this traceback is "
+ "incomplete or corrupted!\n");
+ break;
+ }
+ if (location == NULL) /* found the place that raised the exc */
+ break;
+ skipping = 1; /* RERAISE: skip until "f:17, &KeyError" */
+ }
+ }
+ }
+}
+
+void pypy_debug_catch_fatal_exception(void)
+{
+ pypy_debug_traceback_print();
+ fprintf(stderr, "Fatal RPython error: %s\n",
+ RPyFetchExceptionType()->ov_name->items);
+ abort();
+}
diff --git a/pypy/translator/c/src/debug_traceback.h b/pypy/translator/c/src/debug_traceback.h
--- a/pypy/translator/c/src/debug_traceback.h
+++ b/pypy/translator/c/src/debug_traceback.h
@@ -65,76 +65,3 @@
void pypy_debug_traceback_print(void);
void pypy_debug_catch_fatal_exception(void);
-
-
-/************************************************************/
-
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-
-int pypydtcount = 0;
-struct pypydtentry_s pypy_debug_tracebacks[PYPY_DEBUG_TRACEBACK_DEPTH];
-
-void pypy_debug_traceback_print(void)
-{
- int i;
- int skipping;
- void *my_etype = RPyFetchExceptionType();
- struct pypydtpos_s *location;
- void *etype;
- int has_loc;
-
- /* This code parses the pypy_debug_tracebacks array. See example
- at the start of the file. */
- fprintf(stderr, "RPython traceback:\n");
- skipping = 0;
- i = pypydtcount;
- while (1)
- {
- i = (i - 1) & (PYPY_DEBUG_TRACEBACK_DEPTH-1);
- if (i == pypydtcount)
- {
- fprintf(stderr, " ...\n");
- break;
- }
-
- location = pypy_debug_tracebacks[i].location;
- etype = pypy_debug_tracebacks[i].exctype;
- has_loc = location != NULL && location != PYPYDTPOS_RERAISE;
-
- if (skipping && has_loc && etype == my_etype)
- skipping = 0; /* found the matching "f:17, &KeyError */
-
- if (!skipping)
- {
- if (has_loc)
- fprintf(stderr, " File \"%s\", line %d, in %s\n",
- location->filename, location->lineno, location->funcname);
- else
- {
- /* line "NULL, &KeyError" or "RERAISE, &KeyError" */
- if (!my_etype)
- my_etype = etype;
- if (etype != my_etype)
- {
- fprintf(stderr, " Note: this traceback is "
- "incomplete or corrupted!\n");
- break;
- }
- if (location == NULL) /* found the place that raised the exc */
- break;
- skipping = 1; /* RERAISE: skip until "f:17, &KeyError" */
- }
- }
- }
-}
-
-void pypy_debug_catch_fatal_exception(void)
-{
- pypy_debug_traceback_print();
- fprintf(stderr, "Fatal RPython error: %s\n",
- RPyFetchExceptionType()->ov_name->items);
- abort();
-}
-
-#endif /* PYPY_MAIN_IMPLEMENTATION_FILE */
More information about the pypy-commit
mailing list