Skip to content

PyCapsule: allow zero-sized types#5889

Open
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/allow-zero-sized-capsule
Open

PyCapsule: allow zero-sized types#5889
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/allow-zero-sized-capsule

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Mar 17, 2026

Box::into_raw never returns a null pointer so it seems safe

Alternative to #5882, see this MR for context

@Tpt Tpt force-pushed the tpt/allow-zero-sized-capsule branch from 1fc4d3a to c5a29a9 Compare March 17, 2026 11:12
@davidhewitt
Copy link
Member

I think I'm in favour of this, seems like no technical reason we should restrict users in this way 👍

`Box::into_raw` never returns a null pointer so it seems safe
@Tpt Tpt force-pushed the tpt/allow-zero-sized-capsule branch from c5a29a9 to 70c66a0 Compare March 17, 2026 14:16
@Tpt Tpt marked this pull request as ready for review March 17, 2026 14:51
@Icxolu
Copy link
Member

Icxolu commented Mar 17, 2026

Do we need to consider that the ZST story in C is at least somewhat convoluted? Or do we want to support this as a way of Rust to Rust communication over the C ABI?

@Tpt
Copy link
Contributor Author

Tpt commented Mar 18, 2026

Do we need to consider that the ZST story in C is at least somewhat convoluted? Or do we want to support this as a way of Rust to Rust communication over the C ABI?

Good question. My "hot" take would be that if the user plans to dereference the pointer from C then they already need to care about the ABI of the pointed data, and care about ZST is part of it. So, preventing ZST is only a very small part of making this safe.

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.

4 participants