Skip to content

Commit

Permalink
prevent breaking swift and zig ci
Browse files Browse the repository at this point in the history
  • Loading branch information
xyjixyjixyji committed Jul 19, 2023
1 parent 99d7ee2 commit a0e1e82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bindings/c/include/opendal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
7 changes: 4 additions & 3 deletions bindings/c/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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,
}

impl opendal_bytes {
/// Construct a [`opendal_bytes`] from the Rust [`Vec`] of bytes
pub(crate) fn new(vec: Vec<u8>) -> 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 }
Expand All @@ -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) };
}
Expand Down

0 comments on commit a0e1e82

Please sign in to comment.