Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
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 from2 commits
ce23394
6ff2f4d
821de76
5aed2cb
fea57fb
a6a6662
19bc82e
53ce02c
7fbece8
File 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 |
---|---|---|
@@ -27,3 +27,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. | ||
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. */ | ||
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 *) _PyInterpreterFrame_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) _PyInterpreterFrame_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) _PyInterpreterFrame_GetLine(struct _PyInterpreterFrame *frame); | ||
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. Using 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. You can add |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Expose C-API functions to get the code object, lasti and line number from | ||
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. Not sure if this needs a news entry since the functions are exposed technically on a private header. | ||
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);`` | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -118,6 +118,20 @@ _PyFrame_Clear(_PyInterpreterFrame *frame) | ||
Py_DECREF(frame->f_code); | ||
} | ||
/* Limited API functions */ | ||
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. These functions are excluded from the limited API, they are declared in cpython/. 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. What is the part of the API that isn't portable called? "unlimited", "non-limited"? 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. The Limited API is supposed to be the most portable. The "not portable" API is called the "Public API". For me, the reference documentation about that is now:https://devguide.python.org/developer-workflow/c-api/index.html#changing-python-s-c-api See also:Include/README.rst. | ||
PyCodeObject *_PyInterpreterFrame_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 _PyInterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame) | ||
{ | ||
return _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); | ||
} | ||
int | ||
_PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame) | ||
{ | ||