Can python objects reference the Rust heap? #3737
Answered
by
birkenfeld
ShaneMurphy2
asked this question in
Questions
-
Could I, say, leak a Vec and use it as a ptr for the method |
Beta Was this translation helpful? Give feedback.
Answered by
birkenfeld
Jan 12, 2024
Replies: 1 comment 3 replies
-
In the specific case you mention, yes, since that method will copy the memory into the new Bytes object (those always have their allocation on the Python heap). The way to use arbitrary memory is with buffers/memoryviews, and those are specifically meant for representing non Python data, so no problem referencing a leaked Rust object. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
ShaneMurphy2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the specific case you mention, yes, since that method will copy the memory into the new Bytes object (those always have their allocation on the Python heap).
The way to use arbitrary memory is with buffers/memoryviews, and those are specifically meant for representing non Python data, so no problem referencing a leaked Rust object.