Skip to content

Commit

Permalink
Revert "capacity can be different from len"
Browse files Browse the repository at this point in the history
This reverts commit deccb8b.
  • Loading branch information
tisonkun committed Oct 6, 2024
1 parent deccb8b commit b3be453
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
4 changes: 0 additions & 4 deletions bindings/c/include/opendal.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ typedef struct opendal_bytes {
* The length of the byte array
*/
uintptr_t len;
/**
* The capacity of the byte array
*/
uintptr_t capacity;
} opendal_bytes;

/**
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl opendal_error {
drop(Vec::from_raw_parts(
data_mut,
(*message_ptr).len,
(*message_ptr).capacity,
(*message_ptr).len,
));
}

Expand Down
11 changes: 2 additions & 9 deletions bindings/c/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub struct opendal_bytes {
pub data: *const u8,
/// The length of the byte array
pub len: usize,
/// The capacity of the byte array
pub capacity: usize,
}

impl opendal_bytes {
Expand All @@ -44,21 +42,16 @@ impl opendal_bytes {
let vec = buf.to_vec();
let data = vec.as_ptr();
let len = vec.len();
let capacity = vec.capacity();
std::mem::forget(vec);
Self {
data,
len,
capacity,
}
Self { data, len }
}

/// \brief Frees the heap memory used by the opendal_bytes
#[no_mangle]
pub unsafe extern "C" fn opendal_bytes_free(ptr: *mut opendal_bytes) {
if !ptr.is_null() {
let data_mut = (*ptr).data as *mut u8;
drop(Vec::from_raw_parts(data_mut, (*ptr).len, (*ptr).capacity));
drop(Vec::from_raw_parts(data_mut, (*ptr).len, (*ptr).len));
drop(Box::from_raw(ptr));
}
}
Expand Down

0 comments on commit b3be453

Please sign in to comment.