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

Improve encapsulation of unsafe code #51

Merged
merged 8 commits into from
Nov 26, 2024
Merged

Improve encapsulation of unsafe code #51

merged 8 commits into from
Nov 26, 2024

Conversation

bjorn3
Copy link
Collaborator

@bjorn3 bjorn3 commented Nov 26, 2024

No description provided.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 90.81633% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libbzip2-rs-sys/src/bzlib.rs 88.60% 9 Missing ⚠️
Files with missing lines Coverage Δ
libbzip2-rs-sys/src/allocator.rs 63.85% <100.00%> (ø)
libbzip2-rs-sys/src/blocksort.rs 99.42% <ø> (ø)
libbzip2-rs-sys/src/compress.rs 99.63% <ø> (ø)
libbzip2-rs-sys/src/decompress.rs 94.23% <100.00%> (ø)
libbzip2-rs-sys/src/high_level.rs 81.98% <100.00%> (ø)
libbzip2-rs-sys/src/huffman.rs 96.87% <ø> (ø)
libbzip2-rs-sys/src/lib.rs 98.21% <ø> (ø)
libbzip2-rs-sys/src/bzlib.rs 91.95% <88.60%> (ø)

libbzip2-rs-sys/src/bzlib.rs Show resolved Hide resolved
Comment on lines +266 to +268
if let Some(next_byte) = strm.read_byte() {
$s.bsBuff = $s.bsBuff << 8 | next_byte as u32;
$s.bsLive += 8;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a note, I suspect speedup when we make the bsBuff a u64 and/or try to perform wider reads here.

libbzip2-rs-sys/src/bzlib.rs Show resolved Hide resolved
Comment on lines -746 to 766
if strm.avail_out == 0 {
if s.state_out_pos >= s.writer.num_z as i32 {
break;
}
if s.state_out_pos >= s.writer.num_z as i32 {
if !strm.write_byte(zbits[s.state_out_pos as usize]) {
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this use if let Some(v) = zbits.get(s.state_out_pos)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_z can be less than zbits.len(), but never bigger. As such I think we should keep panicking if zbits[s.state_out_pos] is out of bounds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? doesn't the top check verify that the index is in-range? In what case could this panic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't. Hence why using zbits.get() instead of zbits[] is not necessary.

libbzip2-rs-sys/src/bzlib.rs Show resolved Hide resolved
libbzip2-rs-sys/src/bzlib.rs Outdated Show resolved Hide resolved
libbzip2-rs-sys/src/bzlib.rs Outdated Show resolved Hide resolved
libbzip2-rs-sys/src/bzlib.rs Outdated Show resolved Hide resolved
return ReturnCode::BZ_DATA_ERROR;
}
return ReturnCode::BZ_STREAM_END;
_ => match decompress(strm, s, allocator.clone()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could make decompress take the allocator by-reference? most other functions already do

@folkertdev folkertdev merged commit 8c63a9c into main Nov 26, 2024
14 checks passed
@folkertdev folkertdev deleted the safer_bzlib branch November 26, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants