Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523.#96849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523. #96849
Changes from all commits
ce233946ff2f4d821de765aed2cbfea57fba6a666219bc82e53ce02c7fbece8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,8 @@ | ||
| # error "this header file must not be included directly" | ||
| #endif | ||
| struct _PyInterpreterFrame; | ||
| /* Standard object interface */ | ||
| PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, | ||
| @@ -27,3 +29,18 @@ PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame); | ||
| PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f); | ||
| PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); | ||
| /* The following functions are for use by debuggers and other tools | ||
| * implementing custom frame evaluators with PEP 523. */ | ||
| /* Returns the code object of the frame (strong reference). | ||
| * Does not raise an exception. */ | ||
| PyAPI_FUNC(PyCodeObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame); | ||
| /* Returns a byte ofsset into the last executed instruction. | ||
markshannon marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * Does not raise an exception. */ | ||
| PyAPI_FUNC(int) PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame); | ||
| /* Returns the currently executing line number, or -1 if there is no line number. | ||
| * Does not raise an exception. */ | ||
| PyAPI_FUNC(int) PyUnstable_InterpreterFrame_GetLine(struct _PyInterpreterFrame *frame); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Add unstable C-API functions to get the code object, lasti and line number from | ||
| the internal ``_PyInterpreterFrame`` in the limited API. The functions are: | ||
markshannon marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * ``PyCodeObject * PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame)`` | ||
| * ``int PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame)`` | ||
| * ``int PyUnstable_InterpreterFrame_GetLine(struct _PyInterpreterFrame *frame)`` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
markshannon marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| 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); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere I saw the expression: "This function cannot fail" but I can no longer find it in the doc.