diff --git a/newsfragments/3036.fixed.md b/newsfragments/3036.fixed.md new file mode 100644 index 00000000000..0c55f17ea69 --- /dev/null +++ b/newsfragments/3036.fixed.md @@ -0,0 +1 @@ +Correct FFI definitions `PyGetSetDef`, `PyMemberDef`, `PyStructSequence_Field` and `PyStructSequence_Desc` to have `*const c_char` members for `name` and `doc` (not `*mut c_char`). diff --git a/pyo3-ffi/src/descrobject.rs b/pyo3-ffi/src/descrobject.rs index b858497f9a4..c6f099b5923 100644 --- a/pyo3-ffi/src/descrobject.rs +++ b/pyo3-ffi/src/descrobject.rs @@ -11,7 +11,7 @@ pub type setter = #[repr(C)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct PyGetSetDef { - pub name: *mut c_char, + pub name: *const c_char, pub get: Option, pub set: Option, pub doc: *const c_char, @@ -21,7 +21,7 @@ pub struct PyGetSetDef { impl Default for PyGetSetDef { fn default() -> PyGetSetDef { PyGetSetDef { - name: ptr::null_mut(), + name: ptr::null(), get: None, set: None, doc: ptr::null(), diff --git a/pyo3-ffi/src/structmember.rs b/pyo3-ffi/src/structmember.rs index b41cdaee412..81912042040 100644 --- a/pyo3-ffi/src/structmember.rs +++ b/pyo3-ffi/src/structmember.rs @@ -6,11 +6,11 @@ use std::ptr; #[repr(C)] #[derive(Copy, Clone, Eq, PartialEq)] pub struct PyMemberDef { - pub name: *mut c_char, + pub name: *const c_char, pub type_code: c_int, pub offset: Py_ssize_t, pub flags: c_int, - pub doc: *mut c_char, + pub doc: *const c_char, } impl Default for PyMemberDef { diff --git a/pyo3-ffi/src/structseq.rs b/pyo3-ffi/src/structseq.rs index 8e66a95e0e2..6dfc1daf158 100644 --- a/pyo3-ffi/src/structseq.rs +++ b/pyo3-ffi/src/structseq.rs @@ -6,15 +6,15 @@ use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] pub struct PyStructSequence_Field { - pub name: *mut c_char, - pub doc: *mut c_char, + pub name: *const c_char, + pub doc: *const c_char, } #[repr(C)] #[derive(Copy, Clone)] pub struct PyStructSequence_Desc { - pub name: *mut c_char, - pub doc: *mut c_char, + pub name: *const c_char, + pub doc: *const c_char, pub fields: *mut PyStructSequence_Field, pub n_in_sequence: c_int, }