GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523. (GH-96849)

This commit is contained in:
Mark Shannon 2023-05-05 17:53:07 +01:00 committed by GitHub
parent 45a9e3834a
commit a0df9ee8fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 8 deletions

View file

@ -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;

View file

@ -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
_PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame)
PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame)
{
return _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
}
int
PyUnstable_InterpreterFrame_GetLine(_PyInterpreterFrame *frame)
{
int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
return PyCode_Addr2Line(frame->f_code, addr);

View file

@ -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);