| 241 | // gh-91248 added PyFrame_GetVar() to Python 3.12.0a2 |
| 242 | #if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION) |
| 243 | static inline PyObject* PyFrame_GetVar(PyFrameObject *frame, PyObject *name) |
| 244 | { |
| 245 | PyObject *locals, *value; |
| 246 | |
| 247 | locals = PyFrame_GetLocals(frame); |
| 248 | if (locals == NULL) { |
| 249 | return NULL; |
| 250 | } |
| 251 | #if PY_VERSION_HEX >= 0x03000000 |
| 252 | value = PyDict_GetItemWithError(locals, name); |
| 253 | #else |
| 254 | value = _PyDict_GetItemWithError(locals, name); |
| 255 | #endif |
| 256 | Py_DECREF(locals); |
| 257 | |
| 258 | if (value == NULL) { |
| 259 | if (PyErr_Occurred()) { |
| 260 | return NULL; |
| 261 | } |
| 262 | #if PY_VERSION_HEX >= 0x03000000 |
| 263 | PyErr_Format(PyExc_NameError, "variable %R does not exist", name); |
| 264 | #else |
| 265 | PyErr_SetString(PyExc_NameError, "variable does not exist"); |
| 266 | #endif |
| 267 | return NULL; |
| 268 | } |
| 269 | return Py_NewRef(value); |
| 270 | } |
| 271 | #endif |
| 272 | |
| 273 |
no test coverage detected