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

extract the save area #75

Merged
merged 7 commits into from
Jan 14, 2025
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
10 changes: 2 additions & 8 deletions bzip2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,9 @@ impl CFile {
}

fn open_input(name: impl AsRef<Path>) -> Option<Self> {
// The CString really only needs to live for the duration of the fopen
#[allow(temporary_cstring_as_ptr)]
let fp = unsafe {
libc::fopen(
CString::new(name.as_ref().to_str().unwrap())
.unwrap()
.as_ptr(),
RB_MODE,
)
let path = CString::new(name.as_ref().to_str().unwrap());
libc::fopen(path.unwrap().as_ptr(), RB_MODE)
};
if fp.is_null() {
None
Expand Down
88 changes: 46 additions & 42 deletions libbz2-rs-sys/src/bzlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,31 +558,35 @@
pub limit: [[i32; 258]; 6],
pub base: [[i32; 258]; 6],
pub perm: [[i32; 258]; 6],
pub minLens: [i32; 6],
pub save_i: i32,
pub save_j: i32,
pub save_t: i32,
pub save_alphaSize: i32,
pub save_nGroups: i32,
pub save_nSelectors: i32,
pub save_EOB: i32,
pub save_groupNo: i32,
pub save_groupPos: i32,
pub save_nextSym: i32,
pub save_nblockMAX: i32,
pub save_nblock: i32,
pub save_es: i32,
pub save_N: i32,
pub save_curr: i32,
pub save_zt: i32,
pub save_zn: i32,
pub save_zvec: i32,
pub save_zj: i32,
pub save_gSel: i32,
pub save_gMinlen: i32,
pub save_gLimit: i32,
pub save_gBase: i32,
pub save_gPerm: i32,
pub minLens: [u8; 6],
pub save: SaveArea,
}

#[derive(Default)]
pub(crate) struct SaveArea {
pub i: i32,
pub j: i32,
pub t: i32,
pub alphaSize: i32,
pub nGroups: i32,
pub nSelectors: i32,
pub EOB: i32,
pub groupNo: i32,
pub groupPos: i32,
pub nextSym: i32,
pub nblockMAX: i32,
pub nblock: i32,
pub es: i32,
pub N: i32,
pub curr: i32,
pub zn: i32,
pub zvec: i32,
pub zj: i32,
pub gMinlen: u8,
pub gSel: u8,
pub gLimit: u8,
pub gBase: u8,
pub gPerm: u8,
}

pub(crate) struct DSlice<T> {
Expand Down Expand Up @@ -1263,12 +1267,12 @@
}

/* can a new run be started? */
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
return false;
}

/* Only caused by corrupt data stream? */
if s.nblock_used > s.save_nblock + 1 {
if s.nblock_used > s.save.nblock + 1 {
return true;
}

Expand All @@ -1279,7 +1283,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
};
if k1 != s.k0 {
Expand All @@ -1292,7 +1296,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
};
if k1 != s.k0 {
Expand All @@ -1305,7 +1309,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
};
if k1 != s.k0 {
Expand Down Expand Up @@ -1337,7 +1341,7 @@
/* end restore */

let avail_out_INIT: u32 = cs_avail_out;
let s_save_nblockPP: i32 = s.save_nblock + 1;
let s_save_nblockPP: i32 = s.save.nblock + 1;

let tt = &s.tt.as_slice()[..100000usize.wrapping_mul(ro_blockSize100k as usize)];

Expand Down Expand Up @@ -1536,12 +1540,12 @@
}

/* can a new run be started? */
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
return false;
}

/* Only caused by corrupt data stream? */
if s.nblock_used > s.save_nblock + 1 {
if s.nblock_used > s.save.nblock + 1 {
return true;
}

Expand All @@ -1552,7 +1556,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
};
if k1 != s.k0 {
Expand All @@ -1565,7 +1569,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
}
if k1 != s.k0 {
Expand All @@ -1578,7 +1582,7 @@
BZ_RAND_UPD_MASK!(s);
k1 ^= BZ_RAND_MASK!(s);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
}
if k1 != s.k0 {
Expand Down Expand Up @@ -1612,18 +1616,18 @@
BZ_UPDATE_CRC!(s.calculatedBlockCRC, s.state_out_ch);
s.state_out_len -= 1;
}
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
return false;
}
if s.nblock_used > s.save_nblock + 1 {
if s.nblock_used > s.save.nblock + 1 {
return true;
}

s.state_out_len = 1;
s.state_out_ch = s.k0;
BZ_GET_SMALL!(s, k1);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
}
if k1 != s.k0 {
Expand All @@ -1634,7 +1638,7 @@
s.state_out_len = 2;
BZ_GET_SMALL!(s, k1);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {
continue;
}
if k1 != s.k0 {
Expand All @@ -1645,7 +1649,7 @@
s.state_out_len = 3;
BZ_GET_SMALL!(s, k1);
s.nblock_used += 1;
if s.nblock_used == s.save_nblock + 1 {
if s.nblock_used == s.save.nblock + 1 {

Check warning on line 1652 in libbz2-rs-sys/src/bzlib.rs

View check run for this annotation

Codecov / codecov/patch

libbz2-rs-sys/src/bzlib.rs#L1652

Added line #L1652 was not covered by tests
continue;
}
if k1 != s.k0 {
Expand Down Expand Up @@ -1726,7 +1730,7 @@
return ReturnCode::BZ_DATA_ERROR;
}

if s.nblock_used == s.save_nblock + 1 && s.state_out_len == 0 {
if s.nblock_used == s.save.nblock + 1 && s.state_out_len == 0 {
s.calculatedBlockCRC = !s.calculatedBlockCRC;
if s.verbosity >= 3 {
debug_log!(
Expand Down
Loading
Loading