@@ -575,8 +575,7 @@ class cpp_function : public function {
575575 // chain.
576576 chain_start = rec;
577577 rec->next = chain;
578- auto rec_capsule
579- = reinterpret_borrow<capsule>(((PyCFunctionObject *) m_ptr)->m_self );
578+ auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF (m_ptr));
580579 rec_capsule.set_pointer (unique_rec.release ());
581580 guarded_strdup.release ();
582581 } else {
@@ -636,12 +635,11 @@ class cpp_function : public function {
636635 }
637636 }
638637
639- /* Install docstring */
640638 auto *func = (PyCFunctionObject *) m_ptr;
641- std::free (const_cast <char *>(func->m_ml ->ml_doc ));
642639 // Install docstring if it's non-empty (when at least one option is enabled)
643- func->m_ml ->ml_doc
644- = signatures.empty () ? nullptr : PYBIND11_COMPAT_STRDUP (signatures.c_str ());
640+ auto *doc = signatures.empty () ? nullptr : PYBIND11_COMPAT_STRDUP (signatures.c_str ());
641+ std::free (const_cast <char *>(PYBIND11_PYCFUNCTION_GET_DOC (func)));
642+ PYBIND11_PYCFUNCTION_SET_DOC (func, doc);
645643
646644 if (rec->is_method ) {
647645 m_ptr = PYBIND11_INSTANCE_METHOD_NEW (m_ptr, rec->scope .ptr ());
@@ -3119,8 +3117,8 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
31193117 }
31203118
31213119 /* Don't call dispatch code if invoked from overridden function.
3122- Unfortunately this doesn't work on PyPy. */
3123- #if !defined(PYPY_VERSION)
3120+ Unfortunately this doesn't work on PyPy and GraalPy . */
3121+ #if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
31243122# if PY_VERSION_HEX >= 0x03090000
31253123 PyFrameObject *frame = PyThreadState_GetFrame (PyThreadState_Get ());
31263124 if (frame != nullptr ) {
0 commit comments