Skip to content

Commit

Permalink
Replace assert! with debug_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
ypo committed Mar 6, 2024
1 parent d49d68c commit 98b5db7
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/common/alc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn new_alc_pkt(
);

if pkt.toi == lct::TOI_FDT {
assert!(pkt.fdt_id.is_some());
debug_assert!(pkt.fdt_id.is_some());

let version = match profile {
Profile::RFC6726 => 2,
Expand Down Expand Up @@ -336,7 +336,7 @@ fn push_sct(data: &mut Vec<u8>, time: std::time::SystemTime) {
}

fn parse_sct(ext: &[u8]) -> Result<Option<std::time::SystemTime>> {
assert!(ext.len() >= 4);
debug_assert!(ext.len() >= 4);
let use_bits_hi = ext[2];
let sct_hi = (use_bits_hi >> 7) & 1;
let sct_low = (use_bits_hi >> 6) & 1;
Expand Down
4 changes: 2 additions & 2 deletions src/common/alccodec/alcnocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl AlcCodec for AlcNoCode {
return Err(FluteError::new("Wrong extension size"));
}

assert!(fti[0] == lct::Ext::Fti as u8);
assert!(fti[1] == 4);
debug_assert!(fti[0] == lct::Ext::Fti as u8);
debug_assert!(fti[1] == 4);

let transfer_length = u64::from_be_bytes(fti[2..10].as_ref().try_into().unwrap()) >> 16;
let encoding_symbol_length = u16::from_be_bytes(fti[10..12].as_ref().try_into().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/common/alccodec/alcraptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AlcCodec for AlcRaptor {
let transfer_header: u64 =
(transfer_length << 24) | (oti.encoding_symbol_length as u64 & 0xFFFF);

assert!(oti.scheme_specific.is_some());
debug_assert!(oti.scheme_specific.is_some());
if let SchemeSpecific::Raptor(raptor) = oti.scheme_specific.as_ref().unwrap() {
let padding: u16 = 0;
data.extend(ext_header.to_be_bytes());
Expand All @@ -46,7 +46,7 @@ impl AlcCodec for AlcRaptor {
data.extend(padding.to_be_bytes());
lct::inc_hdr_len(data, len);
} else {
assert!(false);
debug_assert!(false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/alccodec/alcraptorq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AlcCodec for AlcRaptorQ {
let transfer_header: u64 =
(transfer_length << 24) | (oti.encoding_symbol_length as u64 & 0xFFFF);

assert!(oti.scheme_specific.is_some());
debug_assert!(oti.scheme_specific.is_some());
if let SchemeSpecific::RaptorQ(raptorq) = oti.scheme_specific.as_ref().unwrap() {
let padding: u16 = 0;
data.extend(ext_header.to_be_bytes());
Expand All @@ -46,7 +46,7 @@ impl AlcCodec for AlcRaptorQ {
data.extend(padding.to_be_bytes());
lct::inc_hdr_len(data, len);
} else {
assert!(false);
debug_assert!(false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/alccodec/alcrs28.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ impl AlcCodec for AlcRS28 {
return Err(FluteError::new("Wrong extension size"));
}

assert!(fti[0] == lct::Ext::Fti as u8);
assert!(fti[1] == 3);
debug_assert!(fti[0] == lct::Ext::Fti as u8);
debug_assert!(fti[1] == 3);

let transfer_length =
u64::from_be_bytes(fti[0..8].as_ref().try_into().unwrap()) & 0xFFFFFFFFFFFF;
Expand Down
4 changes: 2 additions & 2 deletions src/common/alccodec/alcrs28underspecified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl AlcCodec for AlcRS28UnderSpecified {
return Err(FluteError::new("Wrong extension size"));
}

assert!(fti[0] == lct::Ext::Fti as u8);
assert!(fti[1] == 4);
debug_assert!(fti[0] == lct::Ext::Fti as u8);
debug_assert!(fti[1] == 4);

let transfer_length = u64::from_be_bytes(fti[2..10].as_ref().try_into().unwrap()) >> 16;
let fec_instance_id = u16::from_be_bytes(fti[8..10].as_ref().try_into().unwrap());
Expand Down
6 changes: 3 additions & 3 deletions src/common/alccodec/alcrs2m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl AlcCodec for AlcRS2m {
data.extend(max_n.to_be_bytes());
lct::inc_hdr_len(data, 4);
} else {
assert!(false);
debug_assert!(false);
}
}

Expand All @@ -58,8 +58,8 @@ impl AlcCodec for AlcRS2m {
return Err(FluteError::new("Wrong extension size"));
}

assert!(fti[0] == lct::Ext::Fti as u8);
assert!(fti[1] == 4);
debug_assert!(fti[0] == lct::Ext::Fti as u8);
debug_assert!(fti[1] == 4);

let transfer_length =
u64::from_be_bytes(fti[0..8].as_ref().try_into().unwrap()) & 0xFFFFFFFFFFFF;
Expand Down
2 changes: 1 addition & 1 deletion src/common/lct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ pub fn get_ext<'a>(data: &'a [u8], lct: &LCTHeader, ext: u8) -> Result<Option<&'
)));
}

if het == ext as u8 {
if het == ext {
return Ok(Some(&lct_ext_ext[..hel]));
}
lct_ext_ext = &lct_ext_ext[hel..];
Expand Down
2 changes: 1 addition & 1 deletion src/receiver/blockdecoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl BlockDecoder {
}

pub fn push(&mut self, pkt: &alc::AlcPkt, payload_id: &alc::PayloadID) {
assert!(self.initialized);
debug_assert!(self.initialized);

if self.completed {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/receiver/blockwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl BlockWriter {
if self.sbn != sbn {
return Ok(false);
}
assert!(block.completed);
debug_assert!(block.completed);
let data = block.source_block()?;

// Detect the size of the last symbol
Expand All @@ -83,7 +83,7 @@ impl BlockWriter {
self.decode_write_pkt(data, writer)?;
}

assert!(data.len() <= self.bytes_left);
debug_assert!(data.len() <= self.bytes_left);
self.bytes_left -= data.len();

self.sbn += 1;
Expand All @@ -108,7 +108,7 @@ impl BlockWriter {
}

fn init_decoder(&mut self, data: &[u8]) {
assert!(self.decoder.is_none());
debug_assert!(self.decoder.is_none());
self.decoder = match self.cenc {
lct::Cenc::Null => None,
lct::Cenc::Zlib => Some(Box::new(DecompressZlib::new(data))),
Expand Down
20 changes: 10 additions & 10 deletions src/receiver/objectreceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl ObjectReceiver {
}

fn push_to_block(&mut self, pkt: &alc::AlcPkt, now: std::time::SystemTime) -> Result<()> {
assert!(self.oti.is_some());
assert!(self.transfer_length.is_some());
debug_assert!(self.oti.is_some());
debug_assert!(self.transfer_length.is_some());
let payload_id = alc::parse_payload_id(pkt, self.oti.as_ref().unwrap())?;
log::debug!(
"toi={} sbn={} esi={} meta={:?}",
Expand All @@ -153,7 +153,7 @@ impl ObjectReceiver {
);

if self.transfer_length.unwrap() == 0 {
assert!(self.block_writer.is_none());
debug_assert!(self.block_writer.is_none());
self.complete(now);
return Ok(());
}
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ObjectReceiver {
now: std::time::SystemTime,
server_time: std::time::SystemTime,
) -> bool {
assert!(self.toi != lct::TOI_FDT);
debug_assert!(self.toi != lct::TOI_FDT);
if self.fdt_instance_id.is_some() {
return false;
}
Expand All @@ -252,7 +252,7 @@ impl ObjectReceiver {
if self.oti.is_none() {
self.oti = fdt.get_oti_for_file(file);
if self.oti.is_some() {
assert!(self.transfer_length.is_none());
debug_assert!(self.transfer_length.is_none());
self.transfer_length = Some(file.get_transfer_length());
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ impl ObjectReceiver {
now,
);

assert!(self.block_writer.is_none());
debug_assert!(self.block_writer.is_none());
self.object_writer = Some(ObjectWriterSession {
writer: object_writer,
state: ObjectWriterSessionState::Idle,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl ObjectReceiver {
return Ok(());
}

assert!(self.block_writer.is_some());
debug_assert!(self.block_writer.is_some());
let mut sbn = sbn_start as usize;
let writer = self.block_writer.as_mut().unwrap();
while sbn < self.blocks.len() {
Expand Down Expand Up @@ -521,7 +521,7 @@ impl ObjectReceiver {
}

self.oti = pkt.oti.clone();
assert!(self.transfer_length.is_none());
debug_assert!(self.transfer_length.is_none());
self.transfer_length = pkt.transfer_length;

if pkt.transfer_length.is_none() {
Expand All @@ -532,7 +532,7 @@ impl ObjectReceiver {

if self.cenc.is_none() {
log::warn!("Cenc is unknown ?");
assert!(self.toi != lct::TOI_FDT);
debug_assert!(self.toi != lct::TOI_FDT);
return;
}
}
Expand Down Expand Up @@ -561,7 +561,7 @@ impl ObjectReceiver {
return;
}

assert!(self.blocks.is_empty());
debug_assert!(self.blocks.is_empty());
let oti = self.oti.as_ref().unwrap();

let (a_large, a_small, nb_a_large, nb_blocks) = partition::block_partitioning(
Expand Down
4 changes: 2 additions & 2 deletions src/receiver/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Receiver {

/// Push ALC/LCT packets to the `Receiver`
pub fn push(&mut self, alc_pkt: &alc::AlcPkt, now: std::time::SystemTime) -> Result<()> {
assert!(self.tsi == alc_pkt.lct.tsi);
debug_assert!(self.tsi == alc_pkt.lct.tsi);
self.last_activity = Instant::now();

if alc_pkt.lct.close_session {
Expand Down Expand Up @@ -470,7 +470,7 @@ impl Receiver {
);

if obj.cache_expiration_date.is_some() {
assert!(obj.content_location.is_some());
debug_assert!(obj.content_location.is_some());
log::debug!(
"Insert {:?} for a duration of {:?}",
obj.content_location,
Expand Down
6 changes: 3 additions & 3 deletions src/receiver/uncompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DecompressGzip {
pub fn new(pkt: &[u8]) -> DecompressGzip {
let mut ring = RingBuffer::new(pkt.len() * 2);
let result = ring.write(pkt).unwrap();
assert!(result == pkt.len());
debug_assert!(result == pkt.len());
DecompressGzip {
decoder: GzDecoder::new(ring),
}
Expand Down Expand Up @@ -51,7 +51,7 @@ impl DecompressDeflate {
pub fn new(pkt: &[u8]) -> DecompressDeflate {
let mut ring = RingBuffer::new(pkt.len() * 2);
let result = ring.write(pkt).unwrap();
assert!(result == pkt.len());
debug_assert!(result == pkt.len());
DecompressDeflate {
decoder: DeflateDecoder::new(ring),
}
Expand Down Expand Up @@ -79,7 +79,7 @@ impl DecompressZlib {
pub fn new(pkt: &[u8]) -> DecompressZlib {
let mut ring = RingBuffer::new(pkt.len() * 2);
let result = ring.write(pkt).unwrap();
assert!(result == pkt.len());
debug_assert!(result == pkt.len());
DecompressZlib {
decoder: ZlibDecoder::new(ring),
}
Expand Down
16 changes: 8 additions & 8 deletions src/sender/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl Block {
block_length: usize,
buffer: &[u8],
) -> Result<Vec<Box<dyn FecShard>>> {
assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
assert!(nb_source_symbols <= block_length as usize);
debug_assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
debug_assert!(nb_source_symbols <= block_length as usize);
let encoder = fec::rscodec::RSGalois8Codec::new(
nb_source_symbols,
oti.max_number_of_parity_symbols as usize,
Expand All @@ -119,9 +119,9 @@ impl Block {
block_length: usize,
buffer: &[u8],
) -> Result<Vec<Box<dyn FecShard>>> {
assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
assert!(nb_source_symbols <= block_length as usize);
assert!(oti.scheme_specific.is_some());
debug_assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
debug_assert!(nb_source_symbols <= block_length as usize);
debug_assert!(oti.scheme_specific.is_some());

if let Some(SchemeSpecific::RaptorQ(scheme)) = oti.scheme_specific.as_ref() {
let encoder = fec::raptorq::RaptorQEncoder::new(
Expand All @@ -144,9 +144,9 @@ impl Block {
block_length: usize,
buffer: &[u8],
) -> Result<Vec<Box<dyn FecShard>>> {
assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
assert!(nb_source_symbols <= block_length as usize);
assert!(oti.scheme_specific.is_some());
debug_assert!(nb_source_symbols <= oti.maximum_source_block_length as usize);
debug_assert!(nb_source_symbols <= block_length as usize);
debug_assert!(oti.scheme_specific.is_some());

let encoder = fec::raptor::RaptorEncoder::new(
nb_source_symbols,
Expand Down
2 changes: 1 addition & 1 deletion src/sender/blockencoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl BlockEncoder {
log::debug!("Empty file ? Send a pkt containing close object flag");
self.nb_pkt_sent += 1;

assert!(self.file.object.transfer_length == 0);
debug_assert!(self.file.object.transfer_length == 0);
return Some(pkt::Pkt {
payload: Vec::new(),
transfer_length: self.file.object.transfer_length,
Expand Down
4 changes: 2 additions & 2 deletions src/sender/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Fdt {

let filedesc = Arc::new(FileDesc::new(priority, obj, &self.oti, &toi, None, false)?);

assert!(self.files.contains_key(&filedesc.toi) == false);
debug_assert!(self.files.contains_key(&filedesc.toi) == false);
self.files.insert(filedesc.toi, filedesc.clone());
self.files_transfer_queue.push_back(filedesc);
Ok(toi)
Expand Down Expand Up @@ -529,7 +529,7 @@ mod tests {

let output_print = std::str::from_utf8(&output.stderr).expect("ascii to text went wrong ");

assert!(
debug_assert!(
output.status.success(),
"\n\nValidation failed\n\n{}\n\n",
output_print
Expand Down
2 changes: 1 addition & 1 deletion src/sender/filedesc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl FileDesc {

pub fn transfer_done(&self, now: SystemTime) {
let mut info = self.transfer_info.write().unwrap();
assert!(info.transferring == true);
debug_assert!(info.transferring == true);
info.transferring = false;
info.transfer_count += 1;
info.total_nb_transfer += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/sender/sendersession.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl SenderSession {
continue;
}

assert!(self.file.is_some());
debug_assert!(self.file.is_some());
let file = self.file.as_ref().unwrap();

if !self.transfer_fdt_only {
Expand Down
4 changes: 2 additions & 2 deletions src/sender/toiallocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ToiAllocator {
{
let mut db = allocator.toi_reserved.lock().unwrap();
let success = db.insert(toi);
assert!(success);
debug_assert!(success);
}

Arc::new(Toi {
Expand All @@ -48,7 +48,7 @@ impl ToiAllocator {
pub fn release(&self, toi: u128) {
let mut db = self.toi_reserved.lock().unwrap();
let success = db.remove(&toi);
assert!(success);
debug_assert!(success);
}

pub fn contains(&self, toi: &u128) -> bool {
Expand Down
Loading

0 comments on commit 98b5db7

Please sign in to comment.