Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Add Comment
Please, Sign In to add comment