From 1c6c22ecbda986543b8ff40ad999a9e063740581 Mon Sep 17 00:00:00 2001 From: Deepnarayan Sett Date: Fri, 25 Apr 2025 14:34:33 +0530 Subject: [PATCH] Fix Unit Test Rust based on the new changes on Rust 1.86.0 --- docs/CHANGES.TXT | 1 + src/rust/src/decoder/mod.rs | 25 ++++++++++++++++++------- src/rust/src/lib.rs | 6 +++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT index b02b9936f..4503d0f43 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -40,6 +40,7 @@ - New: Add tesseract page segmentation modes control with `--psm` flag - Fix: Resolve compile-time error about implicit declarations (#1646) - Fix: fatal out of memory error extracting from a VOB PS +- Fix: Unit Test Rust failing due to changes in Rust Version 1.86.0 0.94 (2021-12-14) ----------------- diff --git a/src/rust/src/decoder/mod.rs b/src/rust/src/decoder/mod.rs index 86a0ebcbe..fb65c91d3 100644 --- a/src/rust/src/decoder/mod.rs +++ b/src/rust/src/decoder/mod.rs @@ -44,24 +44,35 @@ pub struct Dtvcc<'a> { impl<'a> Dtvcc<'a> { /// Create a new dtvcc context pub fn new(ctx: &'a mut dtvcc_ctx) -> Self { - let report = unsafe { &mut *ctx.report }; - let encoder = unsafe { &mut *(ctx.encoder as *mut encoder_ctx) }; - let timing = unsafe { &mut *ctx.timing }; - + let report = if !ctx.report.is_null() { + unsafe { Box::new(*(ctx.report)) } + } else { + Box::new(ccx_decoder_dtvcc_report::default()) + }; + let encoder = if !ctx.encoder.is_null() { + unsafe { Box::new(*(ctx.encoder as *mut encoder_ctx)) } + } else { + Box::new(encoder_ctx::default()) + }; + let timing = if !ctx.timing.is_null() { + unsafe { Box::new(*(ctx.timing)) } + } else { + Box::new(ccx_common_timing_ctx::default()) + }; Self { is_active: is_true(ctx.is_active), active_services_count: ctx.active_services_count as u8, services_active: ctx.services_active.to_vec(), report_enabled: is_true(ctx.report_enabled), - report, + report: Box::leak(report), decoders: ctx.decoders.iter_mut().collect(), packet: ctx.current_packet.to_vec(), packet_length: ctx.current_packet_length as u8, is_header_parsed: is_true(ctx.is_current_packet_header_parsed), last_sequence: ctx.last_sequence, - encoder, + encoder: Box::leak(encoder), no_rollup: is_true(ctx.no_rollup), - timing, + timing: Box::leak(timing), } } /// Process cc data and add it to the dtvcc packet diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index d6b575d89..92e7562f1 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -173,7 +173,11 @@ pub fn do_cb(ctx: &mut lib_cc_decode, dtvcc: &mut Dtvcc, cc_block: &[u8]) -> boo 0 | 1 => {} // Type 2 and 3 are for CEA-708 data. 2 | 3 => { - let current_time = unsafe { (*ctx.timing).get_fts(ctx.current_field as u8) }; + let current_time = if ctx.timing.is_null() { + 0 + } else { + unsafe { (*ctx.timing).get_fts(ctx.current_field as u8) } + }; ctx.current_field = 3; // Check whether current time is within start and end bounds