• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Qiskit / qiskit / 14181833713

31 Mar 2025 09:28PM UTC coverage: 87.754% (-0.3%) from 88.016%
14181833713

Pull #14006

github

web-flow
Merge 2fa8bd68a into d0aa10088
Pull Request #14006: Add initial C API for circuit construction

14 of 270 new or added lines in 5 files covered. (5.19%)

10 existing lines in 2 files now uncovered.

72764 of 82918 relevant lines covered (87.75%)

365110.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/cext/src/pointers.rs
1
// This code is part of Qiskit.
2
//
3
// (C) Copyright IBM 2024
4
//
5
// This code is licensed under the Apache License, Version 2.0. You may
6
// obtain a copy of this license in the LICENSE.txt file in the root directory
7
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
//
9
// Any modifications or derivative works of this code must retain this
10
// copyright notice, and modified files need to carry a notice indicating
11
// that they have been altered from the originals.
12

13
use crate::exit_codes::CInputError;
14

15
/// Check the pointer is not null and is aligned.
NEW
16
pub(crate) fn check_ptr<T>(ptr: *const T) -> Result<(), CInputError> {
×
NEW
17
    if ptr.is_null() {
×
NEW
18
        return Err(CInputError::NullPointerError);
×
NEW
19
    };
×
NEW
20
    if !ptr.is_aligned() {
×
NEW
21
        return Err(CInputError::AlignmentError);
×
NEW
22
    };
×
NEW
23
    Ok(())
×
NEW
24
}
×
25

26
/// Casts a const pointer to a reference. Panics is the pointer is null or not aligned.
27
///
28
/// # Safety
29
///
30
/// This function requires ``ptr`` to be point to an initialized object of type ``T``.
31
/// While the resulting reference exists, the memory pointed to must not be mutated.
NEW
32
pub(crate) unsafe fn const_ptr_as_ref<'a, T>(ptr: *const T) -> &'a T {
×
NEW
33
    check_ptr(ptr).unwrap();
×
NEW
34
    let as_ref = unsafe { ptr.as_ref() };
×
NEW
35
    as_ref.unwrap() // we know the pointer is not null, hence we can safely unwrap
×
NEW
36
}
×
37

38
/// Casts a mut pointer to a mut reference. Panics is the pointer is null or not aligned.
39
///
40
/// # Safety
41
///
42
/// This function requires ``ptr`` to be point to an initialized object of type ``T``.
43
/// While the resulting reference exists, the memory pointed to must not be accessed otherwise.
NEW
44
pub(crate) unsafe fn mut_ptr_as_ref<'a, T>(ptr: *mut T) -> &'a mut T {
×
NEW
45
    check_ptr(ptr).unwrap();
×
NEW
46
    let as_mut_ref = unsafe { ptr.as_mut() };
×
NEW
47
    as_mut_ref.unwrap() // we know the pointer is not null, hence we can safely unwrap
×
NEW
48
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc