Skip to content

Commit ec4dcf2

Browse files
authored
Merge branch 'main' into jump_if_bool
2 parents 09ba3bc + d6fb104 commit ec4dcf2

File tree

14 files changed

+97
-30
lines changed

14 files changed

+97
-30
lines changed

‎Doc/c-api/frame.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ See also :ref:`Reflection <reflection>`.
7878
.. versionadded:: 3.11
7979
8080
81+
.. c:function:: int PyFrame_GetLasti(PyFrameObject *frame)
82+
83+
Get the *frame*'s ``f_lasti`` attribute (:class:`dict`).
84+
85+
Returns -1 if ``frame.f_lasti`` is ``None``.
86+
87+
*frame* must not be ``NULL``.
88+
89+
.. versionadded:: 3.11
90+
91+
8192
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
8293
8394
Get the *frame*'s ``f_locals`` attribute (:class:`dict`).

‎Doc/data/stable_abi.dat‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/whatsnew/3.11.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ New Features
11281128

11291129
* Add new functions to get frame object attributes:
11301130
:c:func:`PyFrame_GetBuiltins`, :c:func:`PyFrame_GetGenerator`,
1131-
:c:func:`PyFrame_GetGlobals`.
1131+
:c:func:`PyFrame_GetGlobals`, :c:func:`PyFrame_GetLasti`.
11321132

11331133
Porting to Python 3.11
11341134
----------------------
@@ -1253,9 +1253,9 @@ Porting to Python 3.11
12531253
* ``f_gen``: use :c:func:`PyFrame_GetGenerator`.
12541254
* ``f_globals``: use :c:func:`PyFrame_GetGlobals`.
12551255
* ``f_iblock``: removed.
1256-
* ``f_lasti``: use ``PyObject_GetAttrString((PyObject*)frame, "f_lasti")``.
1256+
* ``f_lasti``: use :c:func:`PyFrame_GetLasti`.
12571257
Code using ``f_lasti`` with ``PyCode_Addr2Line()`` should use
1258-
:c:func:`PyFrame_GetLineNumber` instead.
1258+
:c:func:`PyFrame_GetLineNumber` instead; it may be faster.
12591259
* ``f_lineno``: use :c:func:`PyFrame_GetLineNumber`
12601260
* ``f_locals``: use :c:func:`PyFrame_GetLocals`.
12611261
* ``f_stackdepth``: removed.

‎Include/cpython/frameobject.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *frame);
2929
PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
3030

3131
PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
32+
PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);

‎Lib/test/test_capi.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ def test_frame_getters(self):
11021102
self.assertEqual(frame.f_locals, _testcapi.frame_getlocals(frame))
11031103
self.assertIs(frame.f_globals, _testcapi.frame_getglobals(frame))
11041104
self.assertIs(frame.f_builtins, _testcapi.frame_getbuiltins(frame))
1105+
self.assertEqual(frame.f_lasti, _testcapi.frame_getlasti(frame))
11051106

11061107
def test_frame_get_generator(self):
11071108
gen = self.getgenframe()

‎Lib/test/test_stable_abi_ctypes.py‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:c:func:`PyThread_get_thread_native_id` is excluded from the stable ABI on
2+
platforms where it doesn't exist (like Solaris).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``PyFrame_GetLasti`` C-API function to access frame object's ``lasti``
2+
attribute safely from C code.

‎Misc/stable_abi.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ function PyThread_get_stacksize
17871787
function PyThread_get_thread_ident
17881788
added 3.2
17891789
function PyThread_get_thread_native_id
1790+
ifdef PY_HAVE_THREAD_NATIVE_ID
17901791
added 3.2
17911792
function PyThread_init_thread
17921793
added 3.2

‎Modules/_testcapimodule.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5893,6 +5893,21 @@ frame_getbuiltins(PyObject *self, PyObject *frame)
58935893
return PyFrame_GetBuiltins((PyFrameObject *)frame);
58945894
}
58955895

5896+
static PyObject *
5897+
frame_getlasti(PyObject *self, PyObject *frame)
5898+
{
5899+
if (!PyFrame_Check(frame)) {
5900+
PyErr_SetString(PyExc_TypeError, "argument must be a frame");
5901+
return NULL;
5902+
}
5903+
int lasti = PyFrame_GetLasti((PyFrameObject *)frame);
5904+
if (lasti < 0) {
5905+
assert(lasti == -1);
5906+
Py_RETURN_NONE;
5907+
}
5908+
return PyLong_FromLong(lasti);
5909+
}
5910+
58965911

58975912
static PyObject *negative_dictoffset(PyObject *, PyObject *);
58985913
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
@@ -6186,6 +6201,7 @@ static PyMethodDef TestMethods[] = {
61866201
{"frame_getglobals", frame_getglobals, METH_O, NULL},
61876202
{"frame_getgenerator", frame_getgenerator, METH_O, NULL},
61886203
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
6204+
{"frame_getlasti", frame_getlasti, METH_O, NULL},
61896205
{NULL, NULL} /* sentinel */
61906206
};
61916207

0 commit comments

Comments
 (0)