@@ -1046,11 +1046,11 @@ mod tests {
10461046
10471047 // Get pending operations
10481048 let ptr = pecos_get_pending_operations ( ) ;
1049- assert ! ( !ptr . is_null ( ) ) ;
1050-
1051- // SAFETY: `pecos_get_pending_operations` returns a fresh leaked Box;
1052- // non-null asserted above; the test scope owns it until `pecos_free_operations`.
1053- let collector = unsafe { & * ptr } ;
1049+ // SAFETY: `pecos_get_pending_operations` returns null or a leaked
1050+ // `Box<OperationCollector>` (properly initialised + aligned);
1051+ // ownership stays here until `pecos_free_operations` below.
1052+ let collector =
1053+ unsafe { ptr. as_ref ( ) } . expect ( "pecos_get_pending_operations returned null" ) ;
10541054 assert_eq ! ( collector. operations. len( ) , 2 ) ;
10551055
10561056 // Free the collector
@@ -1341,10 +1341,8 @@ mod tests {
13411341
13421342 // Verify operations were exported
13431343 let ops_ptr = pecos_get_pending_operations ( ) ;
1344- assert ! ( !ops_ptr. is_null( ) ) ;
1345- // SAFETY: `pecos_get_pending_operations` returns a fresh leaked Box;
1346- // non-null asserted above; freed below via `pecos_free_operations`.
1347- let ops = unsafe { & * ops_ptr } ;
1344+ // SAFETY: see `pecos_get_pending_operations` -- null-or-leaked-Box invariant.
1345+ let ops = unsafe { ops_ptr. as_ref ( ) } . expect ( "pecos_get_pending_operations returned null" ) ;
13481346 assert_eq ! ( ops. operations. len( ) , 2 ) ;
13491347 unsafe { pecos_free_operations ( ops_ptr) } ;
13501348
@@ -1409,21 +1407,17 @@ mod tests {
14091407 let needed_id = pecos_wait_for_need_result ( 500 ) ;
14101408 assert_eq ! ( needed_id, 0 ) ;
14111409 let ops_ptr = pecos_get_pending_operations ( ) ;
1412- assert ! ( !ops_ptr. is_null( ) ) ;
1413- // SAFETY: `pecos_get_pending_operations` returns a fresh leaked Box;
1414- // non-null asserted above; freed below via `pecos_free_operations`.
1415- let ops = unsafe { & * ops_ptr } ;
1410+ // SAFETY: see `pecos_get_pending_operations` -- null-or-leaked-Box invariant.
1411+ let ops = unsafe { ops_ptr. as_ref ( ) } . expect ( "pecos_get_pending_operations returned null" ) ;
14161412 assert_eq ! ( ops. operations, vec![ Operation :: AllocateQubit { id: 0 } ] ) ;
14171413 unsafe { pecos_free_operations ( ops_ptr) } ;
14181414 pecos_signal_result_ready ( ) ;
14191415
14201416 let needed_id = pecos_wait_for_need_result ( 500 ) ;
14211417 assert_eq ! ( needed_id, 1 ) ;
14221418 let ops_ptr = pecos_get_pending_operations ( ) ;
1423- assert ! ( !ops_ptr. is_null( ) ) ;
1424- // SAFETY: `pecos_get_pending_operations` returns a fresh leaked Box;
1425- // non-null asserted above; freed below via `pecos_free_operations`.
1426- let ops = unsafe { & * ops_ptr } ;
1419+ // SAFETY: see `pecos_get_pending_operations` -- null-or-leaked-Box invariant.
1420+ let ops = unsafe { ops_ptr. as_ref ( ) } . expect ( "pecos_get_pending_operations returned null" ) ;
14271421 assert_eq ! ( ops. operations, vec![ Operation :: Quantum ( QuantumOp :: H ( 0 ) ) ] ) ;
14281422 unsafe { pecos_free_operations ( ops_ptr) } ;
14291423 pecos_signal_result_ready ( ) ;
0 commit comments