You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Ji-Xinyou (via GitHub)" <gi...@apache.org> on 2023/06/19 10:33:41 UTC
[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2493: fix: Fix the build for zig binding
Ji-Xinyou commented on code in PR #2493:
URL: https://github.com/apache/incubator-opendal/pull/2493#discussion_r1233866120
##########
bindings/c/src/types.rs:
##########
@@ -143,17 +144,28 @@ impl Into<bytes::Bytes> for opendal_bytes {
pub struct opendal_metadata {
/// The pointer to the opendal::Metadata in the Rust code.
/// Only touch this on judging whether it is NULL.
- pub inner: *const od::Metadata,
+ pub inner: *mut od::Metadata,
}
impl opendal_metadata {
+ /// Convert a Rust core [`od::Metadata`] into a heap allocated C-compatible
+ /// [`opendal_metadata`]
+ pub(crate) fn new(m: od::Metadata) -> Self {
+ Self {
+ inner: Box::into_raw(Box::new(m)),
+ }
+ }
+
/// \brief Free the heap-allocated metadata used by opendal_metadata
#[no_mangle]
pub extern "C" fn opendal_metadata_free(&self) {
if self.inner.is_null() {
return;
}
- let _ = unsafe { Box::from_raw(self.inner as *mut od::Metadata) };
+
Review Comment:
here, the metadata itself is heap-allocated, and so is its `inner` field. I think we need to drop `self` here as well, just consume it.
##########
bindings/c/src/lib.rs:
##########
@@ -403,7 +403,7 @@ pub unsafe extern "C" fn opendal_operator_stat(
let path = unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() };
match op.stat(path) {
Ok(m) => opendal_result_stat {
- meta: opendal_metadata::from_metadata(m),
+ meta: Box::into_raw(Box::new(opendal_metadata::new(m))),
Review Comment:
So the `opendal_metadata` itself contains will be a 64-byte heap-allocated. I think the self should be dropped as well.
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org