Tpt commented on code in PR #1426:
URL:
https://github.com/apache/datafusion-python/pull/1426#discussion_r2933389839
##########
examples/datafusion-ffi-example/src/utils.rs:
##########
@@ -35,30 +34,10 @@ pub(crate) fn ffi_logical_codec_from_pycapsule(
};
let capsule = capsule.cast::<PyCapsule>()?;
- validate_pycapsule(capsule, "datafusion_logical_extension_codec")?;
-
let data: NonNull<FFI_LogicalExtensionCodec> = capsule
- .pointer_checked(Some(c_str!("datafusion_logical_extension_codec")))?
+ .pointer_checked(Some(c"datafusion_logical_extension_codec"))?
.cast();
let codec = unsafe { data.as_ref() };
Ok(codec.clone())
}
-
-pub(crate) fn validate_pycapsule(capsule: &Bound<PyCapsule>, name: &str) ->
PyResult<()> {
- let capsule_name = capsule.name()?;
- if capsule_name.is_none() {
- return Err(PyValueError::new_err(format!(
- "Expected {name} PyCapsule to have name set."
- )));
- }
-
- let capsule_name = unsafe { capsule_name.unwrap().as_cstr().to_str()? };
- if capsule_name != name {
- return Err(PyValueError::new_err(format!(
- "Expected name '{name}' in PyCapsule, instead got '{capsule_name}'"
- )));
- }
Review Comment:
Good point. The error messages from `PyCapsule_GetPointer` are
`ValueError("PyCapsule_GetPointer called with invalid PyCapsule object")` and
`ValueError("PyCapsule_GetPointer called with incorrect name")`. These error
only happen if the "magic" methods return invalid capsules so they should only
be encountered by people trying to implement them and not regular DataFusion
users. Also, the stack trace should give a hint of which capsule is raising the
error.
An option might be to wrap the error in a nicer message. WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]