#![cfg_attr(not(all(test, feature = "float")), allow(dead_code, unused_macros))]
#[allow(unused_imports)]
pub(crate) use self::generated::{RegISize, RegSize};
#[macro_use]
#[path = "gen/utils.rs"]
mod generated;
use core::sync::atomic::Ordering;
macro_rules! static_assert {
($cond:expr $(,)?) => {{
let [()] = [(); (true & $cond) as usize];
}};
}
macro_rules! static_assert_layout {
($atomic_type:ty, $value_type:ty) => {
static_assert!(
core::mem::align_of::<$atomic_type>() == core::mem::size_of::<$atomic_type>()
);
static_assert!(core::mem::size_of::<$atomic_type>() == core::mem::size_of::<$value_type>());
};
}
macro_rules! doc_comment {
($doc:expr, $($tt:tt)*) => {
#[doc = $doc]
$($tt)*
};
}
#[allow(unused_macros)]
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "arm64ec",
target_arch = "powerpc64",
target_arch = "riscv32",
target_arch = "riscv64",
all(target_arch = "x86_64", not(any(target_env = "sgx", miri))),
))]
macro_rules! ifunc {
(unsafe fn($($arg_pat:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)? { $($init_body:tt)* }) => {{
type FnTy = unsafe fn($($arg_ty),*) $(-> $ret_ty)?;
static FUNC: core::sync::atomic::AtomicPtr<()>
= core::sync::atomic::AtomicPtr::new(init as *mut ());
#[cold]
unsafe fn init($($arg_pat: $arg_ty),*) $(-> $ret_ty)? {
let func: FnTy = { $($init_body)* };
FUNC.store(func as *mut (), core::sync::atomic::Ordering::Relaxed);
unsafe { func($($arg_pat),*) }
}
let func = {
core::mem::transmute::<*mut (), FnTy>(FUNC.load(core::sync::atomic::Ordering::Relaxed))
};
func($($arg_pat),*)
}};
}
#[allow(unused_macros)]
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "arm64ec",
target_arch = "powerpc64",
target_arch = "riscv32",
target_arch = "riscv64",
all(target_arch = "x86_64", not(any(target_env = "sgx", miri))),
))]
macro_rules! fn_alias {
(
$(#[$($fn_attr:tt)*])*
$vis:vis unsafe fn($($arg_pat:ident: $arg_ty:ty),*) $(-> $ret_ty:ty)?;
$(#[$($alias_attr:tt)*])*
$new:ident = $from:ident($($last_args:tt)*);
$($rest:tt)*
) => {
$(#[$($fn_attr)*])*
$(#[$($alias_attr)*])*
$vis unsafe fn $new($($arg_pat: $arg_ty),*) $(-> $ret_ty)? {
unsafe { $from($($arg_pat,)* $($last_args)*) }
}
fn_alias! {
$(#[$($fn_attr)*])*
$vis unsafe fn($($arg_pat: $arg_ty),*) $(-> $ret_ty)?;
$($rest)*
}
};
(
$(#[$($attr:tt)*])*
$vis:vis unsafe fn($($arg_pat:ident: $arg_ty:ty),*) $(-> $ret_ty:ty)?;
) => {}
}
macro_rules! const_fn {
(
const_if: #[cfg($($cfg:tt)+)];
$(#[$($attr:tt)*])*
$vis:vis const $($rest:tt)*
) => {
#[cfg($($cfg)+)]
$(#[$($attr)*])*
$vis const $($rest)*
#[cfg(not($($cfg)+))]
$(#[$($attr)*])*
$vis $($rest)*
};
}
macro_rules! impl_debug_and_serde {
(AtomicF16) => {
impl_debug!(AtomicF16);
};
(AtomicF128) => {
impl_debug!(AtomicF128);
};
($atomic_type:ident) => {
impl_debug!($atomic_type);
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::ser::Serialize for $atomic_type {
#[allow(clippy::missing_inline_in_public_items)] fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
self.load(Ordering::Relaxed).serialize(serializer)
}
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::de::Deserialize<'de> for $atomic_type {
#[allow(clippy::missing_inline_in_public_items)] fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,
{
serde::de::Deserialize::deserialize(deserializer).map(Self::new)
}
}
};
}
macro_rules! impl_debug {
($atomic_type:ident) => {
impl fmt::Debug for $atomic_type {
#[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.load(Ordering::Relaxed), f)
}
}
};
}
macro_rules! impl_default_no_fetch_ops {
($atomic_type:ident, bool) => {
impl $atomic_type {
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn and(&self, val: bool, order: Ordering) {
self.fetch_and(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn or(&self, val: bool, order: Ordering) {
self.fetch_or(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn xor(&self, val: bool, order: Ordering) {
self.fetch_xor(val, order);
}
}
};
($atomic_type:ident, $int_type:ty) => {
impl $atomic_type {
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn add(&self, val: $int_type, order: Ordering) {
self.fetch_add(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn sub(&self, val: $int_type, order: Ordering) {
self.fetch_sub(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn and(&self, val: $int_type, order: Ordering) {
self.fetch_and(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn or(&self, val: $int_type, order: Ordering) {
self.fetch_or(val, order);
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn xor(&self, val: $int_type, order: Ordering) {
self.fetch_xor(val, order);
}
}
};
}
macro_rules! impl_default_bit_opts {
(AtomicPtr, $int_type:ty) => {
impl<T> AtomicPtr<T> {
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_set(&self, bit: u32, order: Ordering) -> bool {
#[cfg(portable_atomic_no_strict_provenance)]
use crate::utils::ptr::PtrExt as _;
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_or(mask, order).addr() & mask != 0
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_clear(&self, bit: u32, order: Ordering) -> bool {
#[cfg(portable_atomic_no_strict_provenance)]
use crate::utils::ptr::PtrExt as _;
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_and(!mask, order).addr() & mask != 0
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_toggle(&self, bit: u32, order: Ordering) -> bool {
#[cfg(portable_atomic_no_strict_provenance)]
use crate::utils::ptr::PtrExt as _;
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_xor(mask, order).addr() & mask != 0
}
}
};
($atomic_type:ident, $int_type:ty) => {
impl $atomic_type {
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_set(&self, bit: u32, order: Ordering) -> bool {
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_or(mask, order) & mask != 0
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_clear(&self, bit: u32, order: Ordering) -> bool {
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_and(!mask, order) & mask != 0
}
#[inline]
#[cfg_attr(miri, track_caller)] pub(crate) fn bit_toggle(&self, bit: u32, order: Ordering) -> bool {
let mask = <$int_type>::wrapping_shl(1, bit);
self.fetch_xor(mask, order) & mask != 0
}
}
};
}
macro_rules! items {
({$($tt:tt)*}) => {
$($tt)*
};
}
macro_rules! cfg_sel {
({#[cfg(else)] { $($output:tt)* }}) => {
$($output)*
};
({
#[cfg($cfg:meta)]
{ $($output:tt)* }
$($( $rest:tt )+)?
}) => {
#[cfg($cfg)]
cfg_sel! {{#[cfg(else)] { $($output)* }}}
$(
#[cfg(not($cfg))]
cfg_sel! {{ $($rest)+ }}
)?
};
({
#[cfg_attr(portable_atomic_no_cfg_target_has_atomic, cfg($cfg1:meta))]
#[cfg_attr(not(portable_atomic_no_cfg_target_has_atomic), cfg($cfg2:meta))]
{ $($output:tt)* }
$($( $rest:tt )+)?
}) => {
#[cfg_attr(portable_atomic_no_cfg_target_has_atomic, cfg($cfg1))]
#[cfg_attr(not(portable_atomic_no_cfg_target_has_atomic), cfg($cfg2))]
cfg_sel! {{#[cfg(else)] { $($output)* }}}
$(
#[cfg_attr(portable_atomic_no_cfg_target_has_atomic, cfg(not($cfg1)))]
#[cfg_attr(not(portable_atomic_no_cfg_target_has_atomic), cfg(not($cfg2)))]
cfg_sel! {{ $($rest)+ }}
)?
};
}
#[allow(dead_code)]
#[inline(always)]
#[cold]
fn cold_path() {}
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn likely(b: bool) -> bool {
if b {
true
} else {
cold_path();
false
}
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn unlikely(b: bool) -> bool {
if b {
cold_path();
true
} else {
false
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[allow(dead_code)]
#[inline(always)]
#[cfg_attr(all(debug_assertions, not(portable_atomic_no_track_caller)), track_caller)]
pub(crate) unsafe fn assert_unchecked(cond: bool) {
if !cond {
#[cfg(debug_assertions)]
unreachable!();
#[cfg(not(debug_assertions))]
unsafe {
core::hint::unreachable_unchecked()
}
}
}
#[inline]
#[cfg_attr(all(debug_assertions, not(portable_atomic_no_track_caller)), track_caller)]
pub(crate) fn assert_load_ordering(order: Ordering) {
match order {
Ordering::Acquire | Ordering::Relaxed | Ordering::SeqCst => {}
Ordering::Release => panic!("there is no such thing as a release load"),
Ordering::AcqRel => panic!("there is no such thing as an acquire-release load"),
_ => unreachable!(),
}
}
#[inline]
#[cfg_attr(all(debug_assertions, not(portable_atomic_no_track_caller)), track_caller)]
pub(crate) fn assert_store_ordering(order: Ordering) {
match order {
Ordering::Release | Ordering::Relaxed | Ordering::SeqCst => {}
Ordering::Acquire => panic!("there is no such thing as an acquire store"),
Ordering::AcqRel => panic!("there is no such thing as an acquire-release store"),
_ => unreachable!(),
}
}
#[inline]
#[cfg_attr(all(debug_assertions, not(portable_atomic_no_track_caller)), track_caller)]
pub(crate) fn assert_compare_exchange_ordering(success: Ordering, failure: Ordering) {
match success {
Ordering::AcqRel
| Ordering::Acquire
| Ordering::Relaxed
| Ordering::Release
| Ordering::SeqCst => {}
_ => unreachable!(),
}
match failure {
Ordering::Acquire | Ordering::Relaxed | Ordering::SeqCst => {}
Ordering::Release => panic!("there is no such thing as a release failure ordering"),
Ordering::AcqRel => panic!("there is no such thing as an acquire-release failure ordering"),
_ => unreachable!(),
}
}
#[allow(dead_code)]
#[inline]
pub(crate) fn upgrade_success_ordering(success: Ordering, failure: Ordering) -> Ordering {
match (success, failure) {
(Ordering::Relaxed, Ordering::Acquire) => Ordering::Acquire,
(Ordering::Release, Ordering::Acquire) => Ordering::AcqRel,
(_, Ordering::SeqCst) => Ordering::SeqCst,
_ => success,
}
}
#[cfg(not(portable_atomic_no_asm_maybe_uninit))]
#[cfg(target_pointer_width = "32")]
const _: () = assert!(unsafe {
zero_extend64_ptr(ptr::without_provenance_mut(!0)).assume_init() == !0_u32 as u64
});
#[cfg(not(portable_atomic_no_asm_maybe_uninit))]
#[cfg(target_pointer_width = "32")]
#[allow(dead_code)]
#[inline]
pub(crate) const fn zero_extend64_ptr(v: *mut ()) -> core::mem::MaybeUninit<u64> {
#[repr(C)]
struct ZeroExtended {
#[cfg(target_endian = "big")]
pad: *mut (),
v: *mut (),
#[cfg(target_endian = "little")]
pad: *mut (),
}
unsafe { core::mem::transmute(ZeroExtended { v, pad: core::ptr::null_mut() }) }
}
#[allow(dead_code)]
#[cfg(any(
target_arch = "aarch64",
target_arch = "arm64ec",
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "s390x",
target_arch = "x86_64",
))]
#[derive(Clone, Copy)]
#[repr(C)]
pub(crate) union U128 {
pub(crate) whole: u128,
pub(crate) pair: Pair<u64>,
}
#[allow(dead_code)]
#[cfg(any(target_arch = "arm", target_arch = "riscv32"))]
#[derive(Clone, Copy)]
#[repr(C)]
pub(crate) union U64 {
pub(crate) whole: u64,
pub(crate) pair: Pair<u32>,
}
#[allow(dead_code)]
#[derive(Clone, Copy)]
#[repr(C)]
pub(crate) struct Pair<T: Copy> {
#[cfg(any(
target_endian = "little",
target_arch = "aarch64",
target_arch = "arm",
target_arch = "arm64ec",
))]
pub(crate) lo: T,
pub(crate) hi: T,
#[cfg(not(any(
target_endian = "little",
target_arch = "aarch64",
target_arch = "arm",
target_arch = "arm64ec",
)))]
pub(crate) lo: T,
}
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
type MinWord = u32;
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
type RetInt = u32;
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
#[allow(dead_code)]
#[inline]
pub(crate) fn create_sub_word_mask_values<T>(ptr: *mut T) -> (*mut MinWord, RetInt, RetInt) {
use core::mem;
#[cfg(portable_atomic_no_strict_provenance)]
use self::ptr::PtrExt as _;
const SHIFT_MASK: bool = !cfg!(any(
target_arch = "bpf",
target_arch = "loongarch32",
target_arch = "loongarch64",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "s390x",
target_arch = "sparc",
target_arch = "sparc64",
target_arch = "xtensa",
));
let ptr_mask = mem::size_of::<MinWord>() - 1;
let aligned_ptr = ptr.with_addr(ptr.addr() & !ptr_mask) as *mut MinWord;
let ptr_lsb = if SHIFT_MASK {
ptr.addr() & ptr_mask
} else {
ptr.addr()
};
let shift = if cfg!(any(target_endian = "little", target_arch = "s390x")) {
ptr_lsb.wrapping_mul(8)
} else {
(ptr_lsb ^ (mem::size_of::<MinWord>() - mem::size_of::<T>())).wrapping_mul(8)
};
let mut mask: RetInt = (1 << (mem::size_of::<T>() * 8)) - 1; if SHIFT_MASK {
mask <<= shift;
}
#[allow(clippy::cast_possible_truncation)]
{
(aligned_ptr, shift as RetInt, mask)
}
}
#[allow(dead_code)]
pub(crate) mod ptr {
cfg_sel!({
#[cfg(not(portable_atomic_no_strict_provenance))]
{
#[allow(unused_imports)]
pub(crate) use core::ptr::{
with_exposed_provenance, with_exposed_provenance_mut, without_provenance_mut,
};
}
#[cfg(else)]
{
use core::mem;
#[inline(always)]
#[must_use]
pub(crate) const fn without_provenance_mut<T>(addr: usize) -> *mut T {
#[cfg(miri)]
unsafe {
mem::transmute(addr)
}
#[cfg(not(miri))]
{
addr as *mut T
}
}
#[inline(always)]
#[must_use]
#[cfg_attr(miri, track_caller)] pub(crate) fn with_exposed_provenance<T>(addr: usize) -> *const T {
addr as *const T
}
#[inline(always)]
#[must_use]
#[cfg_attr(miri, track_caller)] pub(crate) fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
addr as *mut T
}
pub(crate) trait PtrExt<T: ?Sized>: Copy {
#[must_use]
fn addr(self) -> usize;
#[must_use]
fn with_addr(self, addr: usize) -> Self
where
T: Sized;
}
impl<T: ?Sized> PtrExt<T> for *mut T {
#[inline(always)]
#[must_use]
fn addr(self) -> usize {
unsafe { mem::transmute(self as *mut ()) }
}
#[inline]
#[must_use]
fn with_addr(self, addr: usize) -> Self
where
T: Sized,
{
let self_addr = self.addr() as isize;
let dest_addr = addr as isize;
let offset = dest_addr.wrapping_sub(self_addr);
(self as *mut u8).wrapping_offset(offset) as *mut T
}
}
}
});
}
#[cfg(any(
test,
portable_atomic_test_no_std_static_assert_ffi,
not(any(target_arch = "x86", target_arch = "x86_64"))
))]
#[cfg(any(not(portable_atomic_no_asm), portable_atomic_unstable_asm))]
#[allow(dead_code, non_camel_case_types, unused_macros)]
#[macro_use]
pub(crate) mod ffi {
pub(crate) type c_void = core::ffi::c_void;
#[cfg(target_pointer_width = "16")]
pub(crate) type c_int = i16;
#[cfg(target_pointer_width = "16")]
pub(crate) type c_uint = u16;
#[cfg(not(target_pointer_width = "16"))]
pub(crate) type c_int = i32;
#[cfg(not(target_pointer_width = "16"))]
pub(crate) type c_uint = u32;
#[cfg(all(target_pointer_width = "64", not(windows)))]
pub(crate) type c_long = i64;
#[cfg(all(target_pointer_width = "64", not(windows)))]
pub(crate) type c_ulong = u64;
#[cfg(not(all(target_pointer_width = "64", not(windows))))]
pub(crate) type c_long = i32;
#[cfg(not(all(target_pointer_width = "64", not(windows))))]
pub(crate) type c_ulong = u32;
pub(crate) type c_size_t = usize;
cfg_sel!({
#[cfg(all(
not(any(target_vendor = "apple", windows, target_os = "vita")),
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "csky",
target_arch = "hexagon",
target_arch = "msp430",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "s390x",
target_arch = "xtensa",
),
))]
{
pub(crate) type c_char = u8;
}
#[cfg(else)]
{
pub(crate) type c_char = i8;
}
});
#[cfg(test)]
const _: fn() = || {
let _: c_int = 0 as std::os::raw::c_int;
let _: c_uint = 0 as std::os::raw::c_uint;
let _: c_long = 0 as std::os::raw::c_long;
let _: c_ulong = 0 as std::os::raw::c_ulong;
#[cfg(unix)]
let _: c_size_t = 0 as libc::size_t; let _: c_char = 0 as std::os::raw::c_char;
};
#[repr(transparent)]
pub(crate) struct CStr([c_char]);
impl CStr {
#[inline]
#[must_use]
pub(crate) const fn as_ptr(&self) -> *const c_char {
self.0.as_ptr()
}
#[inline]
#[must_use]
pub(crate) unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
unsafe { &*(bytes as *const [u8] as *const CStr) }
}
#[cfg(test)]
#[inline]
#[must_use]
pub(crate) fn to_bytes_with_nul(&self) -> &[u8] {
#[allow(clippy::unnecessary_cast)] unsafe {
&*(&self.0 as *const [c_char] as *const [u8])
}
}
}
macro_rules! c {
($s:expr) => {{
const BYTES: &[u8] = concat!($s, "\0").as_bytes();
const _: () = static_assert!(crate::utils::ffi::_const_is_c_str(BYTES));
#[allow(unused_unsafe)]
unsafe {
crate::utils::ffi::CStr::from_bytes_with_nul_unchecked(BYTES)
}
}};
}
#[must_use]
pub(crate) const fn _const_is_c_str(bytes: &[u8]) -> bool {
#[cfg(portable_atomic_no_track_caller)]
{
!bytes.is_empty()
}
#[cfg(not(portable_atomic_no_track_caller))]
{
if bytes.is_empty() {
return false;
}
let mut i = bytes.len() - 1;
if bytes[i] != 0 {
return false;
}
while i != 0 {
i -= 1;
if bytes[i] == 0 {
return false;
}
}
true
}
}
macro_rules! sys_type {
({$(
$(#[$attr:meta])*
$vis:vis type $([$($windows_path:ident)::+])? $name:ident = $ty:ty;
)*}) => {
$(
$(#[$attr])*
$vis type $name = $ty;
)*
#[cfg(any(test, portable_atomic_test_no_std_static_assert_ffi))]
test_helper::static_assert_sys_type!($(
$(#[$attr])*
type $([$($windows_path)::+])? $name;
)*);
};
}
macro_rules! sys_struct {
({$(
$(#[$attr:meta])*
$vis:vis struct $([$($windows_path:ident)::+])? $name:ident {$(
$(#[$field_attr:meta])*
$field_vis:vis $field_name:ident: $field_ty:ty,
)*}
)*}) => {
$(
$(#[$attr])*
#[derive(Clone, Copy)]
#[cfg_attr(
any(test, portable_atomic_test_no_std_static_assert_ffi),
derive(Debug, PartialEq)
)]
#[repr(C)]
$vis struct $name {$(
$(#[$field_attr])*
$field_vis $field_name: $field_ty,
)*}
)*
#[cfg(any(test, portable_atomic_test_no_std_static_assert_ffi))]
test_helper::static_assert_sys_struct!($(
$(#[$attr])*
struct $([$($windows_path)::+])? $name {$(
$(#[$field_attr])*
$field_name: $field_ty,
)*}
)*);
};
}
/// Defines constants with #[cfg(test)] static assertions which checks
macro_rules! sys_const {
({$(
$(#[$attr:meta])*
$vis:vis const $([$($windows_path:ident)::+])? $name:ident: $ty:ty = $val:expr;
)*}) => {
$(
$(#[$attr])*
$vis const $name: $ty = $val;
)*
#[cfg(any(test, portable_atomic_test_no_std_static_assert_ffi))]
test_helper::static_assert_sys_const!($(
$(#[$attr])*
const $([$($windows_path)::+])? $name: $ty;
)*);
};
}
macro_rules! sys_fn {
({
$(#[$extern_attr:meta])*
extern $abi:literal {$(
$(#[$fn_attr:meta])*
$vis:vis fn $([$($windows_path:ident)::+])? $name:ident(
$($args:tt)*
) $(-> $ret_ty:ty)?;
)*}
}) => {
$(#[$extern_attr])*
extern $abi {$(
$(#[$fn_attr])*
$vis fn $name($($args)*) $(-> $ret_ty)?;
)*}
#[cfg(any(test, portable_atomic_test_no_std_static_assert_ffi))]
test_helper::static_assert_sys_fn!(
$(#[$extern_attr])*
extern $abi {$(
$(#[$fn_attr])*
fn $([$($windows_path)::+])? $name($($args)*) $(-> $ret_ty)?;
)*}
);
};
}
#[allow(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks,
clippy::wildcard_imports
)]
#[cfg(test)]
mod tests {
#[test]
fn test_c_macro() {
#[track_caller]
fn t(s: &crate::utils::ffi::CStr, raw: &[u8]) {
assert_eq!(s.to_bytes_with_nul(), raw);
}
t(c!(""), b"\0");
t(c!("a"), b"a\0");
t(c!("abc"), b"abc\0");
t(c!(concat!("abc", "d")), b"abcd\0");
}
#[test]
fn test_is_c_str() {
#[track_caller]
fn t(bytes: &[u8]) {
assert_eq!(
super::_const_is_c_str(bytes),
std::ffi::CStr::from_bytes_with_nul(bytes).is_ok()
);
}
t(b"\0");
t(b"a\0");
t(b"abc\0");
t(b"");
t(b"a");
t(b"abc");
t(b"\0a");
t(b"\0a\0");
t(b"ab\0c\0");
t(b"\0\0");
}
}
}