SHARE
TWEET

Untitled

a guest Feb 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void dumpPythonStack() {
  2.     PyFrameObject* frame = PyEval_GetFrame();
  3.     if (!frame) {
  4.         fprintf(stderr, "Got NULL frame...\n");
  5.         return;
  6.     }
  7.     while (frame) {
  8.         int lineno = PyFrame_GetLineNumber(frame);
  9.         PyCodeObject* code = frame->f_code;
  10.         PyObject* filename = code->co_filename;
  11.         Py_ssize_t size;
  12.         char *filename_string;
  13.         filename_string = PyUnicode_AsUTF8AndSize(filename, &size);
  14.         if (!filename_string) {
  15.             fprintf(stderr, "Got NULL filename...\n");
  16.             return;
  17.         }
  18.         fprintf(stdout, "%s:%d\n", filename_string, lineno);
  19.         frame = frame->f_back;
  20.     }
  21.     fflush(stdout);
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top