Skip to content

internal: add safety comments in pyclass/gc, call and marshal - #6288

Open
xavierforge wants to merge 3 commits into
PyO3:mainfrom
xavierforge:docs/safety-comments-gc-call-marshal
Open

internal: add safety comments in pyclass/gc, call and marshal#6288
xavierforge wants to merge 3 commits into
PyO3:mainfrom
xavierforge:docs/safety-comments-gc-call-marshal

Conversation

@xavierforge

Copy link
Copy Markdown
Contributor

Part of #5487, continuing from #6256, #6259 and #6265.

Removes the #![allow(clippy::undocumented_unsafe_blocks)] exemption from three files and adds // SAFETY: comments for their five unsafe blocks:

  • src/pyclass/gc.rs
  • src/call.rs
  • src/marshal.rs

One commit per file for easier review. Verified with clippy under both the default and abi3 feature sets to cover the Py_LIMITED_API branches (note marshal.rs is cfg-gated out under Py_LIMITED_API, so the abi3 pass does not exercise it).

Notes for review: the pyclass/gc.rs argument leans on PyVisit's construction invariant (only created by PyO3's tp_traverse implementation, cannot outlive that call). The PyMarshal_WriteObjectToString comment deliberately claims only that a non-NULL return is a new owned reference to a bytes object: unlike the read direction, its C API documentation does not document the error return, and NULL is permitted by Bound::from_owned_ptr_or_err regardless.

Disclosure: I used AI assistance while analyzing this code; I have personally verified each safety argument against the documented contracts.

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.

1 participant