Skip to content

Avoid using PyDictObject when compiling for RustPython#6057

Open
bschoenmaeckers wants to merge 3 commits into
PyO3:mainfrom
bschoenmaeckers:dict_object_rustpython
Open

Avoid using PyDictObject when compiling for RustPython#6057
bschoenmaeckers wants to merge 3 commits into
PyO3:mainfrom
bschoenmaeckers:dict_object_rustpython

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Member

@bschoenmaeckers bschoenmaeckers commented May 18, 2026

fixes #6047

Tested using:

~/repo/pyo3 ❱ RUSTFLAGS="--cfg RustPython" cargo clippy --features abi3-py314
   Compiling pyo3-ffi v0.28.3 (/Users/basschoenmaeckers/repo/pyo3/pyo3-ffi)
   Compiling pyo3 v0.28.3 (/Users/basschoenmaeckers/repo/pyo3)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.84s

@bschoenmaeckers bschoenmaeckers added the CI-skip-changelog Skip checking changelog entry label May 18, 2026
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review; I'm not sure this is enough:

  • See e.g. dict_len function which assumes the layout of PyDictObject; as long as the cast suceeds then this function is potentially wrong. Perhaps we should make PyDictObject opaque (or not exposed at all) in pyo3-ffi under RustPython?
  • I haven't checked extensively, but I have similar concerns for other types. e.g. PyTupleMethods::as_slice.

@bschoenmaeckers bschoenmaeckers force-pushed the dict_object_rustpython branch from 26f0cab to fef3a8c Compare May 26, 2026 10:14
@bschoenmaeckers
Copy link
Copy Markdown
Member Author

Sorry for the slow review; I'm not sure this is enough:

  • See e.g. dict_len function which assumes the layout of PyDictObject; as long as the cast suceeds then this function is potentially wrong. Perhaps we should make PyDictObject opaque (or not exposed at all) in pyo3-ffi under RustPython?
  • I haven't checked extensively, but I have similar concerns for other types. e.g. PyTupleMethods::as_slice.

RustPython will never support compiling without the abi3 feature enabled. So PyDictObject will never be available. I can look into enforcing the Py_LIMITED_API cfg when compiling for RustPython.

@bschoenmaeckers
Copy link
Copy Markdown
Member Author

In 55c2ea9, I force enable the Py_LIMITED_API flag so RustPython will never get compiled with incompatible api's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RustPython type imports via mutable modules can lead to type confusion

2 participants