@@ -335,7 +335,7 @@ class cpp_function : public function {
335335 const std::type_info *const *types,
336336 size_t args) {
337337 // Do NOT receive `unique_rec` by value. If this function fails to move out the unique_ptr,
338- // we do not want this to destuct the pointer. `initialize` (the caller) still relies on
338+ // we do not want this to destruct the pointer. `initialize` (the caller) still relies on
339339 // the pointee being alive after this call. Only move out if a `capsule` is going to keep
340340 // it alive.
341341 auto *rec = unique_rec.get ();
@@ -2739,19 +2739,19 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27392739
27402740 /* Don't call dispatch code if invoked from overridden function.
27412741 Unfortunately this doesn't work on PyPy. */
2742- #if !defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000
2743- // TODO: Remove PyPy workaround for Python 3.11.
2744- // Current API fails on 3.11 since co_varnames can be null.
2742+ #if !defined(PYPY_VERSION)
27452743# if PY_VERSION_HEX >= 0x03090000
27462744 PyFrameObject *frame = PyThreadState_GetFrame (PyThreadState_Get ());
27472745 if (frame != nullptr ) {
27482746 PyCodeObject *f_code = PyFrame_GetCode (frame);
27492747 // f_code is guaranteed to not be NULL
27502748 if ((std::string) str (f_code->co_name ) == name && f_code->co_argcount > 0 ) {
27512749 PyObject *locals = PyEval_GetLocals ();
2752- if (locals != nullptr && f_code->co_varnames != nullptr ) {
2753- PyObject *self_caller
2754- = dict_getitem (locals, PyTuple_GET_ITEM (f_code->co_varnames , 0 ));
2750+ if (locals != nullptr ) {
2751+ PyObject *co_varnames = PyObject_GetAttrString ((PyObject *) f_code, " co_varnames" );
2752+ PyObject *self_arg = PyTuple_GET_ITEM (co_varnames, 0 );
2753+ Py_DECREF (co_varnames);
2754+ PyObject *self_caller = dict_getitem (locals, self_arg);
27552755 if (self_caller == self.ptr ()) {
27562756 Py_DECREF (f_code);
27572757 Py_DECREF (frame);
@@ -2797,9 +2797,9 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27972797 d.ptr ());
27982798 if (result == nullptr )
27992799 throw error_already_set ();
2800+ Py_DECREF (result);
28002801 if (d[" self" ].is_none ())
28012802 return function ();
2802- Py_DECREF (result);
28032803#endif
28042804
28052805 return override ;
0 commit comments