Skip to content

Commit dac4f8c

Browse files
committed
Add PyFrame_GetLasti() function
1 parent 03a4830 commit dac4f8c

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

‎docs/api.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Python 3.11
3939
4040
Not available on PyPy.
4141
42+
.. c:function:: int PyFrame_GetLasti(PyFrameObject *frame)
43+
44+
See `PyFrame_GetLasti() documentation <https://docs.python.org/dev/c-api/frame.html#c.PyFrame_GetLasti>`__.
45+
46+
Not available on PyPy.
47+
4248
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
4349
4450
See `PyFrame_GetLocals() documentation <https://docs.python.org/dev/c-api/frame.html#c.PyFrame_GetLocals>`__.

‎docs/changelog.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Changelog
22
=========
33

4-
* 2022-04-07: Add functions ``PyFrame_GetLocals()``, ``PyFrame_GetGlobals()``
5-
and ``PyFrame_GetBuiltins()``.
4+
* 2022-04-08: Add functions ``PyFrame_GetLocals()``, ``PyFrame_GetGlobals()``
5+
``PyFrame_GetBuiltins()``, and ``PyFrame_GetLasti()``.
66
* 2022-03-12: Add functions ``PyFloat_Pack2()``, ``PyFloat_Pack4()``,
77
``PyFloat_Pack8()``, ``PyFloat_Unpack2()``, ``PyFloat_Unpack4()`` and
88
``PyFloat_Unpack8()``.

‎pythoncapi_compat.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ _PyFrame_GetBackBorrow(PyFrameObject *frame)
207207

208208
// bpo-40421 added PyFrame_GetLocals() to Python 3.11.0a7
209209
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
210-
PyObject*
210+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
211211
PyFrame_GetLocals(PyFrameObject *frame)
212212
{
213213
#if PY_VERSION_HEX >= 0x030400B1
@@ -224,7 +224,7 @@ PyFrame_GetLocals(PyFrameObject *frame)
224224

225225
// bpo-40421 added PyFrame_GetGlobals() to Python 3.11.0a7
226226
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
227-
PyObject*
227+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
228228
PyFrame_GetGlobals(PyFrameObject *frame)
229229
{
230230
return Py_NewRef(frame->f_globals);
@@ -234,14 +234,24 @@ PyFrame_GetGlobals(PyFrameObject *frame)
234234

235235
// bpo-40421 added PyFrame_GetBuiltins() to Python 3.11.0a7
236236
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
237-
PyObject*
237+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
238238
PyFrame_GetBuiltins(PyFrameObject *frame)
239239
{
240240
return Py_NewRef(frame->f_builtins);
241241
}
242242
#endif
243243

244244

245+
// bpo-40421 added PyFrame_GetLasti() to Python 3.11.0b1
246+
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
247+
PYCAPI_COMPAT_STATIC_INLINE(int)
248+
PyFrame_GetLasti(PyFrameObject *frame)
249+
{
250+
return frame->f_lasti;
251+
}
252+
#endif
253+
254+
245255
// bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5
246256
#if PY_VERSION_HEX < 0x030900A5
247257
PYCAPI_COMPAT_STATIC_INLINE(PyInterpreterState *)

‎tests/test_pythoncapi_compat_cext.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ test_frame(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
232232
Py_DECREF(globals);
233233
Py_DECREF(builtins);
234234

235+
// test PyFrame_GetLasti()
236+
int lasti = PyFrame_GetLasti(frame);
237+
assert(lasti >= 0);
238+
235239
Py_DECREF(frame);
236240
Py_RETURN_NONE;
237241
}

0 commit comments

Comments
 (0)