mirror of https://github.com/KLayout/klayout.git
Support python 3.11 changes. (#1104)
This commit is contained in:
parent
241815e83c
commit
8705de49f7
|
|
@ -92,14 +92,27 @@ public:
|
||||||
{
|
{
|
||||||
while (frame != NULL) {
|
while (frame != NULL) {
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
int line = PyFrame_GetLineNumber(frame);
|
||||||
|
#else
|
||||||
int line = frame->f_lineno;
|
int line = frame->f_lineno;
|
||||||
|
#endif
|
||||||
std::string fn;
|
std::string fn;
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
if (test_type<std::string> (PyFrame_GetCode(frame)->co_filename, true)) {
|
||||||
|
fn = normalize_path (python2c<std::string> (PyFrame_GetCode(frame)->co_filename));
|
||||||
|
#else
|
||||||
if (test_type<std::string> (frame->f_code->co_filename, true)) {
|
if (test_type<std::string> (frame->f_code->co_filename, true)) {
|
||||||
fn = normalize_path (python2c<std::string> (frame->f_code->co_filename));
|
fn = normalize_path (python2c<std::string> (frame->f_code->co_filename));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
m_stack_trace.push_back (tl::BacktraceElement (fn, line));
|
m_stack_trace.push_back (tl::BacktraceElement (fn, line));
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
frame = PyFrame_GetBack(frame);
|
||||||
|
#else
|
||||||
frame = frame->f_back;
|
frame = frame->f_back;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -444,7 +457,11 @@ PythonInterpreter::get_context (int context, PythonRef &globals, PythonRef &loca
|
||||||
|
|
||||||
PyFrameObject *f = mp_current_frame;
|
PyFrameObject *f = mp_current_frame;
|
||||||
while (f && context > 0) {
|
while (f && context > 0) {
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
f = PyFrame_GetBack(f);
|
||||||
|
#else
|
||||||
f = f->f_back;
|
f = f->f_back;
|
||||||
|
#endif
|
||||||
--context;
|
--context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,8 +471,13 @@ PythonInterpreter::get_context (int context, PythonRef &globals, PythonRef &loca
|
||||||
// (see PyFrame_GetLocals implementation)
|
// (see PyFrame_GetLocals implementation)
|
||||||
PyFrame_FastToLocals (f);
|
PyFrame_FastToLocals (f);
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
globals = PythonRef (PyObject_GetAttrString((PyObject*)f, "f_globals"));
|
||||||
|
locals = PythonRef (PyObject_GetAttrString((PyObject*)f, "f_locals"), false);
|
||||||
|
#else
|
||||||
globals = PythonRef (f->f_globals, false);
|
globals = PythonRef (f->f_globals, false);
|
||||||
locals = PythonRef (f->f_locals, false);
|
locals = PythonRef (f->f_locals, false);
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -634,8 +656,13 @@ PythonInterpreter::trace_func (PyFrameObject *frame, int event, PyObject *arg)
|
||||||
// see below for a description of m_block_exceptions
|
// see below for a description of m_block_exceptions
|
||||||
m_block_exceptions = false;
|
m_block_exceptions = false;
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
int line = PyFrame_GetLineNumber(frame);
|
||||||
|
size_t file_id = prepare_trace (PyFrame_GetCode(frame)->co_filename);
|
||||||
|
#else
|
||||||
int line = frame->f_lineno;
|
int line = frame->f_lineno;
|
||||||
size_t file_id = prepare_trace (frame->f_code->co_filename);
|
size_t file_id = prepare_trace (frame->f_code->co_filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
PythonStackTraceProvider st_provider (frame, m_debugger_scope);
|
PythonStackTraceProvider st_provider (frame, m_debugger_scope);
|
||||||
mp_current_exec_handler->trace (this, file_id, line, &st_provider);
|
mp_current_exec_handler->trace (this, file_id, line, &st_provider);
|
||||||
|
|
@ -666,8 +693,13 @@ PythonInterpreter::trace_func (PyFrameObject *frame, int event, PyObject *arg)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
int line = PyFrame_GetLineNumber(frame);
|
||||||
|
size_t file_id = prepare_trace (PyFrame_GetCode(frame)->co_filename);
|
||||||
|
#else
|
||||||
int line = frame->f_lineno;
|
int line = frame->f_lineno;
|
||||||
size_t file_id = prepare_trace (frame->f_code->co_filename);
|
size_t file_id = prepare_trace (frame->f_code->co_filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string emsg = "<unknown>";
|
std::string emsg = "<unknown>";
|
||||||
if (exc_value) {
|
if (exc_value) {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,11 @@ void check_error ()
|
||||||
if (exc_traceback) {
|
if (exc_traceback) {
|
||||||
PyTracebackObject *traceback = (PyTracebackObject*) exc_traceback.get ();
|
PyTracebackObject *traceback = (PyTracebackObject*) exc_traceback.get ();
|
||||||
for (PyTracebackObject *t = traceback; t; t = t->tb_next) {
|
for (PyTracebackObject *t = traceback; t; t = t->tb_next) {
|
||||||
|
#if PY_VERSION_HEX >= 0x030B0000
|
||||||
|
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (PyFrame_GetCode(t->tb_frame)->co_filename), t->tb_lineno));
|
||||||
|
#else
|
||||||
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (t->tb_frame->f_code->co_filename), t->tb_lineno));
|
backtrace.push_back (tl::BacktraceElement (python2c<std::string> (t->tb_frame->f_code->co_filename), t->tb_lineno));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
std::reverse (backtrace.begin (), backtrace.end ());
|
std::reverse (backtrace.begin (), backtrace.end ());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue