Created
February 15, 2019 16:12
-
-
Save ibaned/f2127d30346673f291444b0781ce0beb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void dumpPythonStack() { | |
PyFrameObject* frame = PyEval_GetFrame(); | |
if (!frame) { | |
fprintf(stderr, "Got NULL frame...\n"); | |
return; | |
} | |
while (frame) { | |
int lineno = PyFrame_GetLineNumber(frame); | |
PyCodeObject* code = frame->f_code; | |
PyObject* filename = code->co_filename; | |
Py_ssize_t size; | |
char *filename_string; | |
filename_string = PyUnicode_AsUTF8AndSize(filename, &size); | |
if (!filename_string) { | |
fprintf(stderr, "Got NULL filename...\n"); | |
return; | |
} | |
fprintf(stdout, "%s:%d\n", filename_string, lineno); | |
frame = frame->f_back; | |
} | |
fflush(stdout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment