@@ -1344,8 +1344,13 @@ using module = module_;
1344
1344
// / Return a dictionary representing the global variables in the current execution frame,
1345
1345
// / or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded).
1346
1346
inline dict globals () {
1347
+ #if PY_VERSION_HEX >= 0x030d00000
1348
+ PyObject *p = PyEval_GetFrameGlobals ();
1349
+ return p ? reinterpret_steal<dict>(p) : reinterpret_borrow<dict>(module_::import (" __main__" ).attr (" __dict__" ).ptr ()));
1350
+ #else
1347
1351
PyObject *p = PyEval_GetGlobals ();
1348
1352
return reinterpret_borrow<dict>(p ? p : module_::import (" __main__" ).attr (" __dict__" ).ptr ());
1353
+ #endif
1349
1354
}
1350
1355
1351
1356
template <typename ... Args, typename = detail::enable_if_t <args_are_all_keyword_or_ds<Args...>()>>
@@ -2770,7 +2775,12 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
2770
2775
PyCodeObject *f_code = PyFrame_GetCode (frame);
2771
2776
// f_code is guaranteed to not be NULL
2772
2777
if ((std::string) str (f_code->co_name ) == name && f_code->co_argcount > 0 ) {
2778
+ # if PY_VERSION_HEX >= 0x030d0000
2779
+ PyObject *locals = PyEval_GetFrameLocals ();
2780
+ # else
2773
2781
PyObject *locals = PyEval_GetLocals ();
2782
+ Py_INCREF (locals);
2783
+ # endif
2774
2784
if (locals != nullptr ) {
2775
2785
# if PY_VERSION_HEX >= 0x030b0000
2776
2786
PyObject *co_varnames = PyCode_GetVarnames (f_code);
@@ -2780,6 +2790,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
2780
2790
PyObject *self_arg = PyTuple_GET_ITEM (co_varnames, 0 );
2781
2791
Py_DECREF (co_varnames);
2782
2792
PyObject *self_caller = dict_getitem (locals, self_arg);
2793
+ Py_DECREF (locals);
2783
2794
if (self_caller == self.ptr ()) {
2784
2795
Py_DECREF (f_code);
2785
2796
Py_DECREF (frame);
0 commit comments