#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![deny(unsafe_op_in_unsafe_fn)]
#![warn(clippy::cargo)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::missing_errors_doc)]
#![warn(clippy::missing_panics_doc)]
#![allow(non_camel_case_types)]
#![doc(html_root_url = "https://docs.rs/block-sys/0.2.1")]
#![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))]
#![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))]
#![deprecated = "`block-sys` is deprecated. Use `block2::ffi` instead"]
extern crate std;
#[cfg(not(feature = "std"))]
compile_error!("The `std` feature currently must be enabled.");
#[cfg(feature = "gnustep-1-7")]
extern crate objc_sys as _;
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
extern "C" {}
use core::cell::UnsafeCell;
use core::ffi::c_void;
use core::marker::{PhantomData, PhantomPinned};
use std::os::raw::{c_char, c_ulong};
#[repr(C)]
pub struct Class {
#[cfg(any(feature = "apple", feature = "compiler-rt"))]
_priv: [*mut c_void; 32],
#[cfg(any(feature = "gnustep-1-7", feature = "objfw"))]
_priv: [u8; 0],
_opaque: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
#[allow(non_camel_case_types)]
pub type block_flags = i32;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_DEALLOCATING: block_flags = 0x0001;
pub const BLOCK_REFCOUNT_MASK: block_flags = if cfg!(feature = "gnustep-1-7") {
0x00ffffff
} else if cfg!(any(feature = "compiler-rt", feature = "objfw")) {
0xffff
} else if cfg!(feature = "apple") {
0xfffe } else {
0
};
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_INLINE_LAYOUT_STRING: block_flags = 1 << 21;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_SMALL_DESCRIPTOR: block_flags = 1 << 22;
#[cfg(any(doc, feature = "apple"))] pub const BLOCK_IS_NOESCAPE: block_flags = 1 << 23;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_NEEDS_FREE: block_flags = 1 << 24;
pub const BLOCK_HAS_COPY_DISPOSE: block_flags = 1 << 25;
pub const BLOCK_HAS_CTOR: block_flags = 1 << 26;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_IS_GC: block_flags = 1 << 27;
pub const BLOCK_IS_GLOBAL: block_flags = 1 << 28;
#[doc(alias = "BLOCK_USE_SRET")]
#[doc(alias = "BLOCK_HAS_DESCRIPTOR")] pub const BLOCK_USE_STRET: block_flags = 1 << 29;
pub const BLOCK_HAS_SIGNATURE: block_flags = 1 << 30;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_HAS_EXTENDED_LAYOUT: block_flags = 1 << 31;
#[allow(non_camel_case_types)]
pub type block_assign_dispose_flags = i32;
pub const BLOCK_FIELD_IS_OBJECT: block_assign_dispose_flags = 3;
pub const BLOCK_FIELD_IS_BLOCK: block_assign_dispose_flags = 7;
pub const BLOCK_FIELD_IS_BYREF: block_assign_dispose_flags = 8;
pub const BLOCK_FIELD_IS_WEAK: block_assign_dispose_flags = 16;
pub const BLOCK_BYREF_CALLER: block_assign_dispose_flags = 128;
#[cfg(any(doc, feature = "apple"))]
pub const BLOCK_ALL_COPY_DISPOSE_FLAGS: block_assign_dispose_flags = BLOCK_FIELD_IS_OBJECT
| BLOCK_FIELD_IS_BLOCK
| BLOCK_FIELD_IS_BYREF
| BLOCK_FIELD_IS_WEAK
| BLOCK_BYREF_CALLER;
extern "C" {
pub static _NSConcreteGlobalBlock: Class;
pub static _NSConcreteStackBlock: Class;
pub static _NSConcreteMallocBlock: Class;
#[cfg(any(doc, feature = "apple", feature = "compiler-rt"))]
pub static _NSConcreteAutoBlock: Class;
#[cfg(any(doc, feature = "apple", feature = "compiler-rt"))]
pub static _NSConcreteFinalizingBlock: Class;
#[cfg(any(doc, feature = "apple", feature = "compiler-rt"))]
pub static _NSConcreteWeakBlockVariable: Class;
pub fn _Block_copy(block: *const c_void) -> *mut c_void;
pub fn _Block_release(block: *const c_void);
pub fn _Block_object_assign(
dest_addr: *mut c_void,
object: *const c_void,
flags: block_assign_dispose_flags,
);
pub fn _Block_object_dispose(object: *const c_void, flags: block_assign_dispose_flags);
#[cfg(any(doc, feature = "apple", feature = "compiler-rt"))]
pub fn Block_size(block: *mut c_void) -> c_ulong;
}
#[repr(C)]
pub struct Block_layout {
pub isa: *const Class,
pub flags: block_flags,
pub reserved: i32,
pub invoke: Option<unsafe extern "C" fn()>,
pub descriptor: *const c_void,
}
#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct Block_descriptor_header {
pub reserved: c_ulong, pub size: c_ulong, }
#[repr(C)]
pub struct Block_descriptor {
pub header: Block_descriptor_header,
pub copy: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
pub dispose: Option<unsafe extern "C" fn(src: *mut c_void)>,
}
#[repr(C)]
pub struct Block_descriptor_basic {
pub header: Block_descriptor_header,
#[doc(alias = "signature")]
pub encoding: *const c_char,
}
#[repr(C)]
pub struct Block_descriptor_with_signature {
pub header: Block_descriptor_header,
pub copy: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
pub dispose: Option<unsafe extern "C" fn(src: *mut c_void)>,
#[doc(alias = "signature")]
pub encoding: *const c_char,
}
#[repr(C)]
#[doc(alias = "Block_byref_1")]
pub struct Block_byref_header {
pub isa: *const Class,
pub forwarding: *mut Block_byref_header,
pub flags: block_flags,
#[cfg(feature = "apple")]
pub size: u32,
#[cfg(not(feature = "apple"))]
pub size: i32,
}
#[repr(C)]
#[doc(alias = "Block_byref_2")]
pub struct Block_byref {
pub header: Block_byref_header,
pub keep: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
pub destroy: Option<unsafe extern "C" fn(src: *mut c_void)>,
}
#[cfg(any(doc, feature = "apple"))]
#[repr(C)]
#[doc(alias = "Block_byref_3")]
pub struct Block_byref_extended {
pub header: Block_byref_header,
pub keep: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
pub destroy: Option<unsafe extern "C" fn(src: *mut c_void)>,
pub layout: *const c_char,
}
#[cfg(test)]
mod tests {
use super::*;
use core::ptr;
use std::println;
#[test]
fn smoke() {
assert_eq!(unsafe { _Block_copy(ptr::null_mut()) }, ptr::null_mut());
}
#[test]
fn test_linkable() {
println!("{:p}", unsafe { &_NSConcreteGlobalBlock });
println!("{:p}", unsafe { &_NSConcreteStackBlock });
println!("{:p}", unsafe { &_NSConcreteMallocBlock });
println!("{:p}", _Block_copy as unsafe extern "C" fn(_) -> _);
println!(
"{:p}",
_Block_object_assign as unsafe extern "C" fn(_, _, _)
);
println!("{:p}", _Block_object_dispose as unsafe extern "C" fn(_, _));
println!("{:p}", _Block_release as unsafe extern "C" fn(_));
#[cfg(any(feature = "apple", feature = "compiler-rt"))]
{
println!("{:p}", unsafe { &_NSConcreteAutoBlock });
println!("{:p}", unsafe { &_NSConcreteFinalizingBlock });
println!("{:p}", unsafe { &_NSConcreteWeakBlockVariable });
println!("{:p}", Block_size as unsafe extern "C" fn(_) -> _);
}
}
}