Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed C-binding data length to size_t #235

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pco_c/include/cpcodec_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ typedef enum PcoError {

typedef struct PcoFfiVec {
const void *ptr;
unsigned int len;
size_t len;
const void *raw_box;
} PcoFfiVec;

enum PcoError pco_simpler_compress(const void *nums,
unsigned int len,
size_t len,
unsigned char dtype,
unsigned int level,
struct PcoFfiVec *dst);

enum PcoError pco_simple_decompress(const void *compressed,
unsigned int len,
size_t len,
unsigned char dtype,
struct PcoFfiVec *dst);

Expand Down
18 changes: 9 additions & 9 deletions pco_c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::ptr;

use libc::{c_uchar, c_uint, c_void};
use libc::{c_uchar, c_uint, c_void, size_t};

use pco::data_types::{CoreDataType, NumberLike};

Expand Down Expand Up @@ -51,7 +51,7 @@ pco::with_core_dtypes!(impl_dtypes);
#[repr(C)]
pub struct PcoFfiVec {
ptr: *const c_void,
len: c_uint,
len: size_t,
raw_box: *const c_void,
}

Expand All @@ -61,7 +61,7 @@ impl PcoFfiVec {
Vec<T>: Into<DynTypedVec>,
{
self.ptr = v.as_ptr() as *const c_void;
self.len = v.len() as c_uint;
self.len = v.len();
self.raw_box = Box::into_raw(Box::new(v.into())) as *const c_void;
}

Expand All @@ -79,11 +79,11 @@ impl PcoFfiVec {

fn _simpler_compress<T: NumberLike>(
nums: *const c_void,
len: c_uint,
len: size_t,
level: c_uint,
ffi_vec_ptr: *mut PcoFfiVec,
) -> PcoError {
let slice = unsafe { std::slice::from_raw_parts(nums as *const T, len as usize) };
let slice = unsafe { std::slice::from_raw_parts(nums as *const T, len) };
match pco::standalone::simpler_compress(slice, level as usize) {
Err(_) => PcoError::PcoCompressionError,
Ok(v) => {
Expand All @@ -95,13 +95,13 @@ fn _simpler_compress<T: NumberLike>(

fn _simple_decompress<T: NumberLike>(
compressed: *const c_void,
len: c_uint,
len: size_t,
ffi_vec_ptr: *mut PcoFfiVec,
) -> PcoError
where
Vec<T>: Into<DynTypedVec>,
{
let slice = unsafe { std::slice::from_raw_parts(compressed as *const u8, len as usize) };
let slice = unsafe { std::slice::from_raw_parts(compressed as *const u8, len) };
match pco::standalone::simple_decompress::<T>(slice) {
Err(_) => PcoError::PcoDecompressionError,
Ok(v) => {
Expand All @@ -114,7 +114,7 @@ where
#[no_mangle]
pub extern "C" fn pco_simpler_compress(
nums: *const c_void,
len: c_uint,
len: size_t,
dtype: c_uchar,
level: c_uint,
dst: *mut PcoFfiVec,
Expand All @@ -133,7 +133,7 @@ pub extern "C" fn pco_simpler_compress(
#[no_mangle]
pub extern "C" fn pco_simple_decompress(
compressed: *const c_void,
len: c_uint,
len: size_t,
dtype: c_uchar,
dst: *mut PcoFfiVec,
) -> PcoError {
Expand Down
Loading