diff options
author | Mark Shannon <mark@hotpy.org> | 2023-05-05 16:53:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 16:53:07 (GMT) |
commit | a0df9ee8fc77443510ab7e9ba8fd830f255a8fec (patch) | |
tree | 2af48b491e6dcd471fd16f04e6ae87a85b1097cd /Python | |
parent | 45a9e3834a6ed20ee250e2e5a8583dffcef0eb73 (diff) | |
download | cpython-a0df9ee8fc77443510ab7e9ba8fd830f255a8fec.zip cpython-a0df9ee8fc77443510ab7e9ba8fd830f255a8fec.tar.gz cpython-a0df9ee8fc77443510ab7e9ba8fd830f255a8fec.tar.bz2 |
GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523. (GH-96849)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 3 | ||||
-rw-r--r-- | Python/frame.c | 18 | ||||
-rw-r--r-- | Python/traceback.c | 2 |
3 files changed, 20 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 958689d..56a3b12 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -27,6 +27,7 @@ #include "pycore_dict.h" #include "dictobject.h" #include "pycore_frame.h" +#include "frameobject.h" // _PyInterpreterFrame_GetLine #include "opcode.h" #include "pydtrace.h" #include "setobject.h" @@ -785,7 +786,7 @@ handle_eval_breaker: _PyErr_Format(tstate, PyExc_SystemError, "%U:%d: unknown opcode %d", frame->f_code->co_filename, - _PyInterpreterFrame_GetLine(frame), + PyUnstable_InterpreterFrame_GetLine(frame), opcode); goto error; diff --git a/Python/frame.c b/Python/frame.c index c2c0be3..d792b92 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -144,8 +144,24 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) Py_DECREF(frame->f_funcobj); } +/* Unstable API functions */ + +PyCodeObject * +PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame) +{ + PyCodeObject *code = frame->f_code; + Py_INCREF(code); + return code; +} + +int +PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame) +{ + return _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); +} + int -_PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame) +PyUnstable_InterpreterFrame_GetLine(_PyInterpreterFrame *frame) { int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); return PyCode_Addr2Line(frame->f_code, addr); diff --git a/Python/traceback.c b/Python/traceback.c index 097f69c..b247954 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -1180,7 +1180,7 @@ dump_frame(int fd, _PyInterpreterFrame *frame) PUTS(fd, "???"); } - int lineno = _PyInterpreterFrame_GetLine(frame); + int lineno = PyUnstable_InterpreterFrame_GetLine(frame); PUTS(fd, ", line "); if (lineno >= 0) { _Py_DumpDecimal(fd, (size_t)lineno); |