Skip to content

Commit

Permalink
Merge pull request #235 from mwlon/cbind-sizet
Browse files Browse the repository at this point in the history
Changed C-binding data length to `size_t`
  • Loading branch information
Skielex authored Oct 7, 2024
2 parents 407fc12 + a0d5c4c commit 8741a6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit 8741a6a

Please sign in to comment.