Skip to content

Commit

Permalink
Merge #3036
Browse files Browse the repository at this point in the history
3036: fix const-ness of some FFI name & doc members r=adamreichold a=davidhewitt

I just noticed that these are [`*const` since Python 3.7](python/cpython@007d7ff#diff-830b405713d1c40982ffa918864e39c40c1b318d79b8dd2b523646dc3bd18b52).

This might break existing compiles, so will not include this in 0.18.2.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
  • Loading branch information
bors[bot] and davidhewitt committed Mar 10, 2023
2 parents 550473f + fbebc28 commit 4b0b9b9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions newsfragments/3036.fixed.md
Original file line number Diff line number Diff line change
@@ -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`).
4 changes: 2 additions & 2 deletions pyo3-ffi/src/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<getter>,
pub set: Option<setter>,
pub doc: *const c_char,
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions pyo3-ffi/src/structmember.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pyo3-ffi/src/structseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 4b0b9b9

Please sign in to comment.