From a0e1e82ce763e121dfa86d087ec9d7143b9e7490 Mon Sep 17 00:00:00 2001 From: Ji-Xinyou Date: Thu, 20 Jul 2023 03:23:53 +0800 Subject: [PATCH] prevent breaking swift and zig ci --- bindings/c/include/opendal.h | 2 +- bindings/c/src/types.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bindings/c/include/opendal.h b/bindings/c/include/opendal.h index 4b24bdedfdd5..d5df0f498b92 100644 --- a/bindings/c/include/opendal.h +++ b/bindings/c/include/opendal.h @@ -191,7 +191,7 @@ typedef struct opendal_bytes { /** * Pointing to the byte array on heap */ - uint8_t *data; + const uint8_t *data; /** * The length of the byte array */ diff --git a/bindings/c/src/types.rs b/bindings/c/src/types.rs index 6f172451ebe3..a9b45fcd2711 100644 --- a/bindings/c/src/types.rs +++ b/bindings/c/src/types.rs @@ -92,7 +92,7 @@ impl From<*mut od::BlockingOperator> for opendal_operator_ptr { #[repr(C)] pub struct opendal_bytes { /// Pointing to the byte array on heap - pub data: *mut u8, + pub data: *const u8, /// The length of the byte array pub len: usize, } @@ -100,7 +100,7 @@ pub struct opendal_bytes { impl opendal_bytes { /// Construct a [`opendal_bytes`] from the Rust [`Vec`] of bytes pub(crate) fn new(vec: Vec) -> Self { - let data = vec.as_ptr() as *mut u8; + let data = vec.as_ptr(); let len = vec.len(); std::mem::forget(vec); Self { data, len } @@ -110,8 +110,9 @@ impl opendal_bytes { #[no_mangle] pub extern "C" fn opendal_bytes_free(ptr: *mut opendal_bytes) { if !ptr.is_null() { + let data_mut = unsafe { (*ptr).data as *mut u8 }; // free the vector - let _ = unsafe { Vec::from_raw_parts((*ptr).data, (*ptr).len, (*ptr).len) }; + let _ = unsafe { Vec::from_raw_parts(data_mut, (*ptr).len, (*ptr).len) }; // free the pointer let _ = unsafe { Box::from_raw(ptr) }; }