Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.4k
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 ourterms of service andprivacy 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 from6 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. */ | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| PyAPI_FUNC(PyCodeObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame); | ||
| /* Returns a byte ofsset into the last executed instruction. | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh 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 @@ | ||
| Expose 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. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| * ``PyCodeObject * _PyInterpreterFrame_GetCode(struct _PyInterpreterFrame *frame)`` | ||
| * ``int _PyInterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame)`` | ||
| * ``int _PyInterpreterFrame_GetLine(struct _PyInterpreterFrame *frame)`` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -118,8 +118,24 @@ _PyFrame_Clear(_PyInterpreterFrame *frame) | ||
| Py_DECREF(frame->f_code); | ||
| } | ||
| /* 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. Show resolvedHide resolvedUh 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 | ||
| PyUnstable_InterpreterFrame_GetLine(_PyInterpreterFrame *frame) | ||
| { | ||
| int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); | ||
| return PyCode_Addr2Line(frame->f_code, addr); | ||