Skip to content

Conversation

@SilasMarvin
Copy link
Contributor

In pyo3-ffi the PyMemberDescrObject had the d_member attribute defined as a pointer to PyGetSetDef when it should be a pointer to PyMemberDef.

The PyMemberDescrObject as defined in CPython:

typedef struct {
    PyDescr_COMMON;
    PyMemberDef *d_member;
} PyMemberDescrObject;

See: https://github.com/python/cpython/blob/ebf955df7a89ed0c7968f79faec1de49f61ed7cb/Include/cpython/descrobject.h#L44

pub struct PyMemberDescrObject {
pub d_common: PyDescrObject,
pub d_member: *mut PyGetSetDef,
pub d_member: *mut PyMemberDef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this changed in python/cpython@042f31d, which was first released as part of Python 3.11 (I think, please double-check that).

In which case, I think the correct fix is to make this conditional on Python version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great catch!

Confirmed you are correct, it was first released as part of Pyhon 3.11. You can verify by cloning cpython and running:

git tag --contains 042f31da552c19054acd3ef7bb6cfd857bce172b | grep "^v3\." | sort -V

Updated the code.

Copy link
Contributor

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a release note too

@@ -1,4 +1,4 @@
use crate::{PyGetSetDef, PyMethodDef, PyObject, PyTypeObject};
use crate::{PyGetSetDef, PyMemberDef, PyMethodDef, PyObject, PyTypeObject};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be conditional too to appease clippy

#[cfg(not(Py_3_11))]
pub d_member: *mut PyGetSetDef,
#[cfg(Py_3_11)]
pub d_member: *mut crate::PyMemberDef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to nitpick - it’s a little more idiomatic to add a new use statement that’s inside a #[cfg(Py_3_11)] conditional compilation block at the top of this file rather than using crate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Updated

@davidhewitt davidhewitt added this pull request to the merge queue Nov 26, 2025
Merged via the queue into PyO3:main with commit 48c8432 Nov 26, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants