Skip to content

Commit

Permalink
make z_stream::default() use follow the standard allocator preference
Browse files Browse the repository at this point in the history
which is rust, if available, then C, if available, else None
  • Loading branch information
folkertdev committed May 29, 2024
1 parent 90775ea commit cd77499
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions zlib-rs/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub type z_streamp = *mut z_stream;

impl Default for z_stream {
fn default() -> Self {
Self {
let mut stream = Self {
next_in: core::ptr::null_mut(),
avail_in: 0,
total_in: 0,
Expand All @@ -49,13 +49,25 @@ impl Default for z_stream {
total_out: 0,
msg: core::ptr::null_mut(),
state: core::ptr::null_mut(),
zalloc: Some(crate::allocate::zalloc_c),
zfree: Some(crate::allocate::zfree_c),
zalloc: None,
zfree: None,
opaque: core::ptr::null_mut(),
data_type: 0,
adler: 0,
reserved: 0,
};

#[cfg(feature = "rust-allocator")]
if stream.zalloc.is_none() || stream.zfree.is_none() {
stream.configure_default_rust_allocator()
}

#[cfg(feature = "c-allocator")]
if stream.zalloc.is_none() || stream.zfree.is_none() {
stream.configure_default_c_allocator()
}

stream
}
}

Expand Down

0 comments on commit cd77499

Please sign in to comment.