From 98b5db7811808c71135529cba95e66cf25c2a94a Mon Sep 17 00:00:00 2001 From: Yannick Poirier Date: Wed, 6 Mar 2024 15:55:31 +0100 Subject: [PATCH] Replace assert! with debug_assert --- src/common/alc.rs | 4 ++-- src/common/alccodec/alcnocode.rs | 4 ++-- src/common/alccodec/alcraptor.rs | 4 ++-- src/common/alccodec/alcraptorq.rs | 4 ++-- src/common/alccodec/alcrs28.rs | 4 ++-- src/common/alccodec/alcrs28underspecified.rs | 4 ++-- src/common/alccodec/alcrs2m.rs | 6 +++--- src/common/lct.rs | 2 +- src/receiver/blockdecoder.rs | 2 +- src/receiver/blockwriter.rs | 6 +++--- src/receiver/objectreceiver.rs | 20 ++++++++++---------- src/receiver/receiver.rs | 4 ++-- src/receiver/uncompress.rs | 6 +++--- src/sender/block.rs | 16 ++++++++-------- src/sender/blockencoder.rs | 2 +- src/sender/fdt.rs | 4 ++-- src/sender/filedesc.rs | 2 +- src/sender/sendersession.rs | 2 +- src/sender/toiallocator.rs | 4 ++-- src/tools/ringbuffer.rs | 12 ++++++------ 20 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/common/alc.rs b/src/common/alc.rs index d1eff48..7d168f4 100644 --- a/src/common/alc.rs +++ b/src/common/alc.rs @@ -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, @@ -336,7 +336,7 @@ fn push_sct(data: &mut Vec, time: std::time::SystemTime) { } fn parse_sct(ext: &[u8]) -> Result> { - 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; diff --git a/src/common/alccodec/alcnocode.rs b/src/common/alccodec/alcnocode.rs index 1841be4..3f9d616 100644 --- a/src/common/alccodec/alcnocode.rs +++ b/src/common/alccodec/alcnocode.rs @@ -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()); diff --git a/src/common/alccodec/alcraptor.rs b/src/common/alccodec/alcraptor.rs index ef9e0e1..15b8cc8 100644 --- a/src/common/alccodec/alcraptor.rs +++ b/src/common/alccodec/alcraptor.rs @@ -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()); @@ -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); } } diff --git a/src/common/alccodec/alcraptorq.rs b/src/common/alccodec/alcraptorq.rs index fbd7f28..09585ec 100644 --- a/src/common/alccodec/alcraptorq.rs +++ b/src/common/alccodec/alcraptorq.rs @@ -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()); @@ -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); } } diff --git a/src/common/alccodec/alcrs28.rs b/src/common/alccodec/alcrs28.rs index a15c013..0ae404d 100644 --- a/src/common/alccodec/alcrs28.rs +++ b/src/common/alccodec/alcrs28.rs @@ -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; diff --git a/src/common/alccodec/alcrs28underspecified.rs b/src/common/alccodec/alcrs28underspecified.rs index be30f94..c5c0c0b 100644 --- a/src/common/alccodec/alcrs28underspecified.rs +++ b/src/common/alccodec/alcrs28underspecified.rs @@ -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()); diff --git a/src/common/alccodec/alcrs2m.rs b/src/common/alccodec/alcrs2m.rs index 0f88f69..b4f9bd0 100644 --- a/src/common/alccodec/alcrs2m.rs +++ b/src/common/alccodec/alcrs2m.rs @@ -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); } } @@ -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; diff --git a/src/common/lct.rs b/src/common/lct.rs index bbeeaff..44cdf9b 100644 --- a/src/common/lct.rs +++ b/src/common/lct.rs @@ -443,7 +443,7 @@ pub fn get_ext<'a>(data: &'a [u8], lct: &LCTHeader, ext: u8) -> Result None, lct::Cenc::Zlib => Some(Box::new(DecompressZlib::new(data))), diff --git a/src/receiver/objectreceiver.rs b/src/receiver/objectreceiver.rs index 5c7955a..4836802 100644 --- a/src/receiver/objectreceiver.rs +++ b/src/receiver/objectreceiver.rs @@ -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={:?}", @@ -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(()); } @@ -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; } @@ -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()); } } @@ -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, @@ -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() { @@ -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() { @@ -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; } } @@ -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( diff --git a/src/receiver/receiver.rs b/src/receiver/receiver.rs index ea663b7..a568936 100644 --- a/src/receiver/receiver.rs +++ b/src/receiver/receiver.rs @@ -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 { @@ -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, diff --git a/src/receiver/uncompress.rs b/src/receiver/uncompress.rs index 0d63c7c..523b17a 100644 --- a/src/receiver/uncompress.rs +++ b/src/receiver/uncompress.rs @@ -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), } @@ -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), } @@ -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), } diff --git a/src/sender/block.rs b/src/sender/block.rs index 57166ea..bf82e3a 100644 --- a/src/sender/block.rs +++ b/src/sender/block.rs @@ -102,8 +102,8 @@ impl Block { block_length: usize, buffer: &[u8], ) -> Result>> { - 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, @@ -119,9 +119,9 @@ impl Block { block_length: usize, buffer: &[u8], ) -> Result>> { - 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( @@ -144,9 +144,9 @@ impl Block { block_length: usize, buffer: &[u8], ) -> Result>> { - 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, diff --git a/src/sender/blockencoder.rs b/src/sender/blockencoder.rs index 9a6aeec..a6823b1 100644 --- a/src/sender/blockencoder.rs +++ b/src/sender/blockencoder.rs @@ -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, diff --git a/src/sender/fdt.rs b/src/sender/fdt.rs index db9232d..61f73bc 100644 --- a/src/sender/fdt.rs +++ b/src/sender/fdt.rs @@ -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) @@ -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 diff --git a/src/sender/filedesc.rs b/src/sender/filedesc.rs index 8235e42..aa492a0 100644 --- a/src/sender/filedesc.rs +++ b/src/sender/filedesc.rs @@ -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; diff --git a/src/sender/sendersession.rs b/src/sender/sendersession.rs index 1f83b96..7c94c20 100644 --- a/src/sender/sendersession.rs +++ b/src/sender/sendersession.rs @@ -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 { diff --git a/src/sender/toiallocator.rs b/src/sender/toiallocator.rs index 2c72c26..a4dabc0 100644 --- a/src/sender/toiallocator.rs +++ b/src/sender/toiallocator.rs @@ -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 { @@ -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 { diff --git a/src/tools/ringbuffer.rs b/src/tools/ringbuffer.rs index 0c9350a..e7f6d6b 100644 --- a/src/tools/ringbuffer.rs +++ b/src/tools/ringbuffer.rs @@ -68,7 +68,7 @@ impl std::io::Read for RingBuffer { buf[..max_size] .copy_from_slice(&self.buffer[self.consumer..(self.consumer + max_size)]); self.consumer += max_size; - assert!(self.consumer <= self.buffer.len()); + debug_assert!(self.consumer <= self.buffer.len()); if self.consumer == self.buffer.len() { self.consumer = 0; @@ -83,8 +83,8 @@ impl std::io::Read for RingBuffer { buf[end_size..(end_size + left)].copy_from_slice(&self.buffer[..left]); self.consumer += left; - assert!(self.consumer <= self.producer); - assert!(self.consumer != self.buffer.len()); + debug_assert!(self.consumer <= self.producer); + debug_assert!(self.consumer != self.buffer.len()); Ok(max_size) } } @@ -105,8 +105,8 @@ impl std::io::Write for RingBuffer { .copy_from_slice(&buf[..max_size]); self.producer += max_size; - assert!(self.consumer > self.producer); - assert!(self.producer != self.buffer.len()); + debug_assert!(self.consumer > self.producer); + debug_assert!(self.producer != self.buffer.len()); return Ok(max_size); } @@ -128,7 +128,7 @@ impl std::io::Write for RingBuffer { let left_size = max_size - end_size; self.buffer[..left_size].copy_from_slice(&buf[end_size..(end_size + left_size)]); self.producer += left_size; - assert!(self.producer < self.consumer); + debug_assert!(self.producer < self.consumer); Ok(max_size) }