@@ -242,6 +242,57 @@ PyFrame_GetLasti(PyFrameObject *frame)
242242#endif
243243
244244
245+ // gh-91248 added PyFrame_GetVar() to Python 3.12.0a2
246+ #if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION)
247+ PYCAPI_COMPAT_STATIC_INLINE (PyObject*)
248+ PyFrame_GetVar(PyFrameObject *frame, PyObject *name)
249+ {
250+ PyObject *locals, *value;
251+
252+ locals = PyFrame_GetLocals (frame);
253+ if (locals == NULL ) {
254+ return NULL ;
255+ }
256+ #if PY_VERSION_HEX >= 0x03000000
257+ value = PyDict_GetItemWithError (locals, name);
258+ #else
259+ value = PyDict_GetItem (locals, name);
260+ #endif
261+ Py_DECREF (locals);
262+
263+ if (value == NULL ) {
264+ if (PyErr_Occurred ()) {
265+ return NULL ;
266+ }
267+ #if PY_VERSION_HEX >= 0x03000000
268+ PyErr_Format (PyExc_NameError, " variable %R does not exist" , name);
269+ #else
270+ PyErr_SetString (PyExc_NameError, " variable does not exist" );
271+ #endif
272+ return NULL ;
273+ }
274+ return Py_NewRef (value);
275+ }
276+ #endif
277+
278+
279+ // gh-91248 added PyFrame_GetVarString() to Python 3.12.0a2
280+ #if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION)
281+ PYCAPI_COMPAT_STATIC_INLINE (PyObject*)
282+ PyFrame_GetVarString(PyFrameObject *frame, const char *name)
283+ {
284+ PyObject *name_obj, *value;
285+ name_obj = PyUnicode_FromString (name);
286+ if (name_obj == NULL ) {
287+ return NULL ;
288+ }
289+ value = PyFrame_GetVar (frame, name_obj);
290+ Py_DECREF (name_obj);
291+ return value;
292+ }
293+ #endif
294+
295+
245296// bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5
246297#if PY_VERSION_HEX < 0x030900A5
247298PYCAPI_COMPAT_STATIC_INLINE (PyInterpreterState *)
0 commit comments