-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[stdlib] Add PyCapsule_New and PyCapsule_GetPointer #4334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
721af64
to
add0db0
Compare
mojo/stdlib/src/python/_cpython.mojo
Outdated
return self.lib.call["PyCapsule_New", PyObjectPtr]( | ||
pointer, name.unsafe_ptr(), destructor | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to call self._inc_total_rc()
here, since PyCapsule_New
returns a new reference. Also, we should cast name
to c_char
, if only to document ABI compliance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, adding.
This comment was marked as resolved.
This comment was marked as resolved.
ce7df25
to
fcc2efd
Compare
Nice, I pushed a second commit. I am not sure if you prefer separate commits for ease of review or just one commit for cleaner history. |
This comment was marked as outdated.
This comment was marked as outdated.
Thanks for the edits, accepted them. |
037d990
to
4d41eec
Compare
4d41eec
to
768722f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch! Just a few nits and requests, but LGTM otherwise.
var capsule_pointer = Cpython_env[].PyCapsule_GetPointer( | ||
capsule, "some_name" | ||
) | ||
assert_equal(capsule_impl.bitcast[NoneType](), capsule_pointer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test for a PyCapsule_GetPointer
with a mismatched name?
var capsule_pointer = Cpython_env[].PyCapsule_GetPointer( | |
capsule, "some_name" | |
) | |
assert_equal(capsule_impl.bitcast[NoneType](), capsule_pointer) | |
var capsule_pointer = Cpython_env[].PyCapsule_GetPointer( | |
capsule, "some_name" | |
) | |
assert_equal(capsule_impl.bitcast[NoneType](), capsule_pointer) |
These are critical when interacting with PyCapsules created by other libraries in the system. The current use case is interacting with PyArrow. Signed-off-by: Marius Seritan <[email protected]>
6414dd7
to
e4cbca2
Compare
Co-authored-by: Laszlo Kindrat <[email protected]> Signed-off-by: Marius Seritan <[email protected]>
Co-authored-by: Laszlo Kindrat <[email protected]> Signed-off-by: Marius Seritan <[email protected]>
Signed-off-by: Marius Seritan <[email protected]>
e4cbca2
to
affaddd
Compare
@laszlokindrat many thanks for the review, I addressed the feedback. I am not sure if there is anything else for me to do, I will wait for the PR to be merged at some point. Let me know if I am missing something. |
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
Landed in 86a9310! Thank you for your contribution 🎉 |
[External] [stdlib] Add PyCapsule_New and PyCapsule_GetPointer These are critical when interacting with PyCapsules created by other libraries in the system. The current use case is interacting with PyArrow. <!-- Thanks for submitting a pull request, your contribution is really appreciated! If possible, add a link to the issue you are trying to solve in the pull request description. If your pull request is big (> 100 lines), consider splitting it into multiple pull requests as it may accelerate the review process. --> ORIGINAL_AUTHOR=Marius Seritan <[email protected]> PUBLIC_PR_LINK=#4334 Co-authored-by: Marius Seritan <[email protected]> Closes #4334 MODULAR_ORIG_COMMIT_REV_ID: 4a1e4aa8c12b799de2eb010e75fda4f4f64b76c0
These are critical when interacting with PyCapsules created by other libraries in the system. The current use case is interacting with PyArrow.