~jamesh/storm/initialize-globals

« back to all changes in this revision

Viewing changes to storm/cextensions.c

  • Committer: James Henstridge
  • Date: 2012-08-10 10:38:42 UTC
  • Revision ID: james@jamesh.id.au-20120810103842-u0cq1zih361zmwhs
Print the traceback as well as a stack trace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
        /* For some reason, we weren't able to initialise
260
260
         * correctly. Print some debugging information about where the
261
261
         * failure occurred. */
262
 
        fprintf(stderr, "\n\nstorm.cextensions: initialise_globals failed.  Stack trace:\n");
 
262
        fprintf(stderr, "\n\nstorm.cextensions: initialise_globals failed.\n");
 
263
 
 
264
        PyObject *type = NULL, *value = NULL, *traceback = NULL;
 
265
        PyErr_Fetch(&type, &value, &traceback);
 
266
 
 
267
        if (type != NULL) {
 
268
            /* incref the exception context, since Fetch() takes ownership */
 
269
            Py_INCREF(type);
 
270
            Py_XINCREF(value);
 
271
            Py_XINCREF(traceback);
 
272
            PyErr_Restore(type, value, traceback);
 
273
            fprintf(stderr, "Traceback:\n");
 
274
            PyErr_Print();
 
275
        }
 
276
        fprintf(stderr, "Stack:\n");
263
277
        PyObject *traceback_module = PyImport_ImportModule("traceback");
264
278
        PyObject_CallMethod(traceback_module, "print_stack", "");
265
279
        fprintf(stderr, "\n\n");
 
280
        PyErr_Restore(type, value, traceback);
266
281
    }
267
282
 
268
283
    return initialized;