Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"1ca2fc0de37d5850cf99edc825e15314c6187f80de344770a8bc9d287bb0ed34","Cargo.toml":"56d6f66e2cb09178f95cae8b693bc7df11e6009f6b62b8c9b0d2e9c214b6029f","README.md":"42b5a4d716e08420f454679cd242e11277d73f004acd8011a9011c21b1d3f6a0","build.rs":"2a5c5644a1823de47cdcb0ce3f8aa89a3d5762c77a3dcc4d79fce4665dfe8414","compat-headers/gnustep/Block.h":"0b6ea4f8bcf92fa2d1bb28f05f793aa163d9086bb543e33baaa49fe401b054fa","compat-headers/gnustep/Block_private.h":"6c8f55014f98cf7bc276cd8ab48532a85f1456ea9cd401c475bd90dd3211b668","compat-headers/objfw/Block.h":"dd6516920b6d4f234fe8267b45ac2db502abd2e321fc3b2495bab9fd9acfc25e","src/lib.rs":"ec93b77b241c1851152bbafa0a7d1bca3a8d7d59b62e61c03008b4c23f93b133"},"package":"0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146"}

View file

@ -0,0 +1,55 @@
# Changelog
Notable changes to this crate will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased - YYYY-MM-DD
## 0.1.0-beta.1 - 2022-08-28
### Fixed
* Fixed `docs.rs` setup.
## 0.1.0-beta.0 - 2022-07-19
### Added
* Use `doc_auto_cfg` to improve documentation output.
### Changed
* **BREAKING**: Changed `links` key from `block_0_0` to `block_0_1` (so
`DEP_BLOCK_0_0_CC_ARGS` in build scripts becomes `DEP_BLOCK_0_1_CC_ARGS`).
## 0.0.4 - 2022-06-13
### Changed
* **BREAKING**: Changed `links` key from `block` to `block_0_0` for better
future compatibility, until we reach 1.0 (so `DEP_BLOCK_CC_ARGS` in build
scripts becomes `DEP_BLOCK_0_0_CC_ARGS`).
* **BREAKING**: Apple's runtime is now always the default.
* **BREAKING**: Updated `objc-sys` to `v0.2.0-beta.0`.
### Fixed
* **BREAKING**: Tweak the types of a lot of fields and arguments.
## 0.0.3 - 2022-01-03
### Changed
* **BREAKING**: Updated `objc-sys` to `v0.2.0-alpha.1`.
## 0.0.2 - 2021-12-22
### Changed
* **BREAKING**: Updated `objc-sys` to `v0.2.0-alpha.0`.
### Fixed
* **BREAKING**: `Class` is now `!UnwindSafe`.
## 0.0.1 - 2021-11-22
Initial release.

99
third-party/vendor/block-sys/Cargo.toml vendored Normal file
View file

@ -0,0 +1,99 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "block-sys"
version = "0.1.0-beta.1"
authors = ["Mads Marquart <mads@marquart.dk>"]
build = "build.rs"
links = "block_0_1"
description = "Raw bindings to Apple's C language extension of blocks"
documentation = "https://docs.rs/block-sys/"
readme = "README.md"
keywords = [
"objective-c",
"macos",
"ios",
"blocks",
"sys",
]
categories = [
"external-ffi-bindings",
"os::macos-apis",
]
license = "MIT"
repository = "https://github.com/madsmtm/objc2"
resolver = "2"
[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"
no-default-features = true
features = [
"std",
"unstable-docsrs",
]
targets = [
"x86_64-apple-darwin",
"aarch64-apple-darwin",
"aarch64-apple-ios",
"x86_64-apple-ios",
"x86_64-unknown-linux-gnu",
"i686-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
]
[dependencies.objc-sys]
version = "=0.2.0-beta.2"
optional = true
default-features = false
[features]
alloc = ["objc-sys?/alloc"]
apple = []
compiler-rt = []
default = [
"std",
"apple",
]
gnustep-1-7 = [
"objc-sys",
"objc-sys/gnustep-1-7",
]
gnustep-1-8 = [
"objc-sys/gnustep-1-8",
"gnustep-1-7",
]
gnustep-1-9 = [
"objc-sys/gnustep-1-9",
"gnustep-1-8",
]
gnustep-2-0 = [
"objc-sys/gnustep-2-0",
"gnustep-1-9",
]
gnustep-2-1 = [
"objc-sys/gnustep-2-1",
"gnustep-2-0",
]
std = [
"alloc",
"objc-sys?/std",
]
unstable-docsrs = [
"objc-sys",
"objc-sys/unstable-docsrs",
]
unstable-objfw = []
unstable-winobjc = [
"objc-sys/unstable-winobjc",
"gnustep-1-8",
]

116
third-party/vendor/block-sys/README.md vendored Normal file
View file

@ -0,0 +1,116 @@
# `block-sys`
[![Latest version](https://badgen.net/crates/v/block-sys)](https://crates.io/crates/block-sys)
[![License](https://badgen.net/badge/license/MIT/blue)](../LICENSE.txt)
[![Documentation](https://docs.rs/block-sys/badge.svg)](https://docs.rs/block-sys/)
[![CI](https://github.com/madsmtm/objc2/actions/workflows/ci.yml/badge.svg)](https://github.com/madsmtm/objc2/actions/workflows/ci.yml)
Raw Rust bindings to Apple's C language extension of blocks.
This crate is part of the [`objc2` project](https://github.com/madsmtm/objc2),
see that for related crates.
## Runtime Support
This library is basically just a raw interface to the aptly specified [Blocks
ABI](https://clang.llvm.org/docs/Block-ABI-Apple.html). However, different
runtime implementations exist and act in slightly different ways (and have
several different helper functions), the most important aspect being that the
libraries are named differently, so the linking must take that into account.
The user can choose the desired runtime by using the relevant cargo feature
flags, see the following sections (might have to disable the default `apple`
feature first). Note that if the `objc-sys` crate is present in the module
tree, this should have the same feature flag enabled as that.
### Apple's [`libclosure`](https://github.com/apple-oss-distributions/libclosure)
- Feature flag: `apple`.
This is naturally the most sophisticated runtime, and it has quite a lot more
features than the specification mandates. This is used by default.
The minimum required operating system versions are as follows:
- macOS: `10.6`
- iOS: `3.2`
- tvOS: Unknown
- watchOS: Unknown
Though in practice Rust itself requires higher versions than this.
### LLVM `compiler-rt`'s [`libBlocksRuntime`](https://github.com/llvm/llvm-project/tree/release/13.x/compiler-rt/lib/BlocksRuntime)
- Feature flag: `compiler-rt`.
This is effectively just a copy of Apple's older (around macOS 10.6) runtime,
and is now used in [Swift's `libdispatch`] and [Swift's Foundation] as well.
This can be easily used on many Linux systems with the `libblocksruntime-dev`
package.
Using this runtime probably won't work together with `objc-sys` crate.
[Swift's `libdispatch`]: https://github.com/apple/swift-corelibs-libdispatch/tree/swift-5.5.1-RELEASE/src/BlocksRuntime
[Swift's Foundation]: https://github.com/apple/swift-corelibs-foundation/tree/swift-5.5.1-RELEASE/Sources/BlocksRuntime
### GNUStep's [`libobjc2`](https://github.com/gnustep/libobjc2)
- Feature flag: `gnustep-1-7`, `gnustep-1-8`, `gnustep-1-9`, `gnustep-2-0` and
`gnustep-2-1` depending on the version you're using.
GNUStep is a bit odd, because it bundles blocks support into its Objective-C
runtime. This means we have to link to `libobjc`, and this is done by
depending on the `objc-sys` crate. A bit unorthodox, yes, but it works.
Sources:
- [`Block.h`](https://github.com/gnustep/libobjc2/blob/v2.1/objc/blocks_runtime.h)
- [`Block_private.h`](https://github.com/gnustep/libobjc2/blob/v2.1/objc/blocks_private.h)
### Microsoft's [`WinObjC`](https://github.com/microsoft/WinObjC)
- Feature flag: `unstable-winobjc`.
**Unstable: Hasn't been tested on Windows yet!**
Essentially just [a fork](https://github.com/microsoft/libobjc2) based on
GNUStep's `libobjc2` version 1.8.
### [`ObjFW`](https://github.com/ObjFW/ObjFW)
- Feature flag: `unstable-objfw`.
**Unstable: Doesn't work yet!**
TODO.
## C Compiler configuration
To our knowledge, currently only `clang` supports the [Language Specification
for Blocks][block-lang]. To assist in compiling C (or Objective-C) sources
using these features, this crate's build script expose the
`DEP_BLOCK_0_1_CC_ARGS` environment variable to downstream build scripts.
Example usage in your `build.rs` (using the `cc` crate) would be as follows:
```rust , ignore
fn main() {
let mut builder = cc::Build::new();
builder.compiler("clang");
builder.file("my_script_using_blocks.c");
for flag in std::env::var("DEP_BLOCK_0_1_CC_ARGS").unwrap().split(' ') {
builder.flag(flag);
}
builder.compile("libmy_script_using_blocks.a");
}
```
[block-lang]: https://clang.llvm.org/docs/BlockLanguageSpec.html

75
third-party/vendor/block-sys/build.rs vendored Normal file
View file

@ -0,0 +1,75 @@
use std::env;
use std::path::Path;
fn main() {
// Only rerun if this file changes; the script doesn't depend on our code
println!("cargo:rerun-if-changed=build.rs");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let mut apple = env::var_os("CARGO_FEATURE_APPLE").is_some();
let compiler_rt = env::var_os("CARGO_FEATURE_COMPILER_RT").is_some();
let mut gnustep = env::var_os("CARGO_FEATURE_GNUSTEP_1_7").is_some();
let objfw = env::var_os("CARGO_FEATURE_UNSTABLE_OBJFW").is_some();
// Only when the crate is being compiled directly
if cfg!(feature = "unstable-docsrs") {
if let "macos" | "ios" | "tvos" | "watchos" = &*target_os {
apple = true;
// Add cheaty #[cfg(feature = "apple")] directive
println!("cargo:rustc-cfg=feature=\"apple\"");
} else {
// Also winobjc
gnustep = true;
// Add cheaty #[cfg(feature = "gnustep-1-7")] directive
println!("cargo:rustc-cfg=feature=\"gnustep-1-7\"");
}
}
let mut cc_args = "-fblocks".to_owned();
match (apple, compiler_rt, gnustep, objfw) {
(true, false, false, false) => {
// Link to libclosure (internally called libsystem_blocks), which is
// exported by libSystem.dylib.
//
// Note that System.framework is just a deprecated wrapper over the
// dynamic library.
println!("cargo:rustc-link-lib=dylib=System");
// Alternative: Only link to libsystem_blocks.dylib
// println!("cargo:rustc-link-search=native=/usr/lib/system");
// println!("cargo:rustc-link-lib=dylib=system_blocks");
}
(false, true, false, false) => {
println!("cargo:rustc-link-lib=dylib=BlocksRuntime");
}
(false, false, true, false) => {
// Don't link to anything; objc-sys already does that for us!
// Add GNUStep compability headers to make `#include <Block.h>`
// work (on newer GNUStep versions these headers are present)
if env::var_os("CARGO_FEATURE_GNUSTEP_2_0").is_none() {
let compat_headers =
Path::new(env!("CARGO_MANIFEST_DIR")).join("compat-headers/gnustep");
cc_args.push_str(" -I");
cc_args.push_str(compat_headers.to_str().unwrap());
}
}
(false, false, false, true) => {
// Add compability headers to make `#include <Block.h>` work.
let compat_headers = Path::new(env!("CARGO_MANIFEST_DIR")).join("compat-headers/objfw");
cc_args.push_str(" -I");
cc_args.push_str(compat_headers.to_str().unwrap());
println!("cargo:rustc-link-lib=dylib=objfw");
unimplemented!("ObjFW is not yet supported")
}
// Checked in if-let above
(false, false, false, false) => {
panic!("Invalid feature combination; at least one runtime must be selected!")
}
(_, _, _, _) => panic!("Invalid feature combination; only one runtime may be selected!"),
}
// Add DEP_BLOCK_[version]_CC_ARGS
println!("cargo:cc_args={}", cc_args);
}

View file

@ -0,0 +1 @@
#include <objc/blocks_runtime.h>

View file

@ -0,0 +1 @@
#include <objc/blocks_private.h>

View file

@ -0,0 +1 @@
#include <ObjFW/block.h>

449
third-party/vendor/block-sys/src/lib.rs vendored Normal file
View file

@ -0,0 +1,449 @@
//! # Raw bindings to Apple's C language extension of blocks
//!
//! The documentation for these bindings is a mix from GNUStep's and Apple's
//! sources, but the [ABI specification][ABI] is really the place you should
//! be looking!
//!
//! See also the [`README.md`](https://crates.io/crates/block-sys) for more
//! background information, and for how to configure the desired runtime.
//!
//! [ABI]: https://clang.llvm.org/docs/Block-ABI-Apple.html
// TODO: Replace `extern "C"` with `extern "C-unwind"` where applicable.
// See https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html.
#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![deny(unsafe_op_in_unsafe_fn)]
#![warn(clippy::cargo)]
#![warn(clippy::ptr_as_ptr)]
// Update in Cargo.toml as well.
#![doc(html_root_url = "https://docs.rs/block-sys/0.1.0-beta.1")]
#![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))]
#![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))]
extern crate std;
#[cfg(not(feature = "std"))]
compile_error!("The `std` feature currently must be enabled.");
// Ensure linkage actually happens
#[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"))]
// The size of this is unknown
_priv: [u8; 0],
/// See objc_sys::OpaqueData
_opaque: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
/// Block descriptor flags.
/// Values for Block_layout->flags to describe block objects
#[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") {
// Mask for the reference count in byref structure's flags field. The low
// 3 bytes are reserved for the reference count, the top byte for the flags.
0x00ffffff
} else if cfg!(any(feature = "compiler-rt", feature = "objfw")) {
0xffff
} else if cfg!(feature = "apple") {
0xfffe // runtime
} else {
0
};
#[cfg(any(doc, feature = "apple"))]
/// compiler
pub const BLOCK_INLINE_LAYOUT_STRING: block_flags = 1 << 21;
#[cfg(any(doc, feature = "apple"))]
/// compiler
pub const BLOCK_SMALL_DESCRIPTOR: block_flags = 1 << 22;
#[cfg(any(doc, feature = "apple"))] // Part of ABI?
/// compiler
pub const BLOCK_IS_NOESCAPE: block_flags = 1 << 23;
#[cfg(any(doc, feature = "apple"))]
/// runtime
pub const BLOCK_NEEDS_FREE: block_flags = 1 << 24;
/// The block descriptor contains copy and dispose helpers.
/// compiler
pub const BLOCK_HAS_COPY_DISPOSE: block_flags = 1 << 25;
/// The helpers have C++ code.
/// compiler: helpers have C++ code
pub const BLOCK_HAS_CTOR: block_flags = 1 << 26;
#[cfg(any(doc, feature = "apple"))]
/// compiler
pub const BLOCK_IS_GC: block_flags = 1 << 27;
/// Block is stored in global memory and does not need to be copied.
/// compiler
pub const BLOCK_IS_GLOBAL: block_flags = 1 << 28;
/// Block function uses a calling convention that returns a structure via a
/// pointer passed in by the caller.
///
/// match (BLOCK_USE_STRET, BLOCK_HAS_SIGNATURE) {
/// (false, false) => 10.6.ABI, no signature field available
/// (true, false) => 10.6.ABI, no signature field available
/// (false, true) => ABI.2010.3.16, regular calling convention, presence of signature field
/// (true, true) => ABI.2010.3.16, stret calling convention, presence of signature field,
/// }
///
/// See <https://clang.llvm.org/docs/Block-ABI-Apple.html#high-level>
#[doc(alias = "BLOCK_USE_SRET")]
#[doc(alias = "BLOCK_HAS_DESCRIPTOR")] // compiler-rt || macOS 10.6
pub const BLOCK_USE_STRET: block_flags = 1 << 29;
/// Block has an Objective-C type encoding.
/// compiler
pub const BLOCK_HAS_SIGNATURE: block_flags = 1 << 30;
#[cfg(any(doc, feature = "apple"))]
/// compiler
pub const BLOCK_HAS_EXTENDED_LAYOUT: block_flags = 1 << 31;
/// Flags used in the final argument to _Block_object_assign() and
/// _Block_object_dispose(). These indicate the type of copy or dispose to
/// perform.
/// Values for _Block_object_assign() and _Block_object_dispose() parameters
///
/// This is a helper type, in the sources this type does not have a name!
#[allow(non_camel_case_types)]
pub type block_assign_dispose_flags = i32;
/// The value is of some id-like type, and should be copied as an Objective-C
/// object: i.e. by sending -retain or via the GC assign functions in GC mode
/// (not yet supported).
///
/// id, NSObject, __attribute__((NSObject)), block, ...
pub const BLOCK_FIELD_IS_OBJECT: block_assign_dispose_flags = 3;
/// The field is a block. This must be copied by the block copy functions.
///
/// a block variable
pub const BLOCK_FIELD_IS_BLOCK: block_assign_dispose_flags = 7;
/// The field is an indirect reference to a variable declared with the __block
/// storage qualifier.
///
/// the on stack structure holding the __block variable
pub const BLOCK_FIELD_IS_BYREF: block_assign_dispose_flags = 8;
/// The field is an indirect reference to a variable declared with the __block
/// storage qualifier.
///
/// declared __weak, only used in byref copy helpers
pub const BLOCK_FIELD_IS_WEAK: block_assign_dispose_flags = 16;
/// The field is an indirect reference to a variable declared with the __block
/// storage qualifier.
///
/// called from __block (byref) copy/dispose support routines.
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;
// TODO: BLOCK_LAYOUT_X
extern "C" {
// the raw data space for runtime classes for blocks
// class+meta used for stack, malloc, and collectable based blocks
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);
/// Runtime entry point called by compiler when assigning objects inside
/// copy helper routines
pub fn _Block_object_assign(
dest_addr: *mut c_void,
object: *const c_void,
flags: block_assign_dispose_flags,
);
/// runtime entry point called by the compiler when disposing of objects
/// inside dispose helper routine
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; // usize
// Whether the return value of the block is on the stack.
// macOS 10.7
// #[cfg(any(doc, feature = "apple"))]
// pub fn _Block_use_stret(block: *mut c_void) -> bool;
// Returns a string describing the block's GC layout.
// This uses the GC skip/scan encoding.
// May return NULL.
// macOS 10.7
// #[cfg(any(doc, feature = "apple"))]
// pub fn _Block_layout(block: *mut c_void) -> *const c_char;
// Returns a string describing the block's layout.
// This uses the "extended layout" form described above.
// May return NULL.
// macOS 10.8
// #[cfg(any(doc, feature = "apple"))]
// pub fn _Block_extended_layout(block: *mut c_void) -> *const c_char;
// Callable only from the ARR weak subsystem while in exclusion zone
// macOS 10.7
// #[cfg(any(doc, feature = "apple"))]
// pub fn _Block_tryRetain(block: *const c_void) -> bool;
// Callable only from the ARR weak subsystem while in exclusion zone
// macOS 10.7
// #[cfg(any(doc, feature = "apple"))]
// pub fn _Block_isDeallocating(block: *const c_void) -> bool;
// indicates whether block was compiled with compiler that sets the ABI
// related metadata bits
// macOS 10.7
// #[cfg(any(doc, feature = "apple", feature = "gnustep-1-7"))]
// pub fn _Block_has_signature(block: *mut c_void) -> bool;
// Returns a string describing the block's parameter and return types.
// The encoding scheme is the same as Objective-C @encode.
// Returns NULL for blocks compiled with some compilers.
// macOS 10.7
// #[cfg(any(doc, feature = "apple", feature = "gnustep-1-7"))]
// pub fn _Block_signature(block: *mut c_void) -> *const c_char;
}
#[repr(C)]
pub struct Block_layout {
/// Class pointer. Always initialised to &_NSConcreteStackBlock for blocks
/// that are created on the stack or &_NSConcreteGlobalBlock for blocks
/// that are created in global storage.
pub isa: *const Class,
/// Flags.
/// See the `block_flags` enumerated type for possible values.
/// Contains ref count in Apple and ObjFW.
pub flags: block_flags,
/// Reserved - always initialised to 0 by the compiler (but this is not
/// said in the specification).
///
/// Used for the reference count in GNUStep and WinObjC.
pub reserved: i32,
/// The function that implements the block. The first argument is this
/// structure, the subsequent arguments are the block's explicit
/// parameters. If the BLOCK_USE_SRET & BLOCK_HAS_SIGNATURE flag is set,
/// there is an additional hidden argument, which is a pointer to the
/// space on the stack allocated to hold the return value.
pub invoke: Option<unsafe extern "C" fn()>,
/// The block's descriptor. The actual type of this is:
/// ```pseudo-code
/// match (BLOCK_HAS_COPY_DISPOSE, BLOCK_HAS_SIGNATURE) {
/// (false, false) => Block_descriptor_header,
/// (true, false) => Block_descriptor,
/// (false, true) => Block_descriptor_basic,
/// (true, true) => Block_descriptor_with_signature,
/// }
/// ```
///
/// But it is safe to access this through just `Block_descriptor_header`.
// Note: Important to use `*const c_void` until we know which type it is!
pub descriptor: *const c_void,
}
#[repr(C)]
pub struct Block_descriptor_header {
/// Reserved for future use. Currently always 0.
pub reserved: c_ulong, // usize
/// Size of the block.
pub size: c_ulong, // usize
}
/// Block descriptor that contains copy and dispose operations.
///
/// Requires BLOCK_HAS_COPY_DISPOSE
#[repr(C)]
pub struct Block_descriptor {
pub header: Block_descriptor_header,
/// Copy function, generated by the compiler to help copy the block if it
/// contains nontrivial copy operations.
pub copy: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
/// Dispose function, generated by the compiler to help copy the block if
/// it contains nontrivial destructors.
pub dispose: Option<unsafe extern "C" fn(src: *mut c_void)>,
}
/// Extended block descriptor that does not contain copy and dispose helper
/// functions.
///
/// Requires BLOCK_HAS_SIGNATURE
#[repr(C)]
pub struct Block_descriptor_basic {
pub header: Block_descriptor_header,
/// Objective-C type encoding of the block.
#[doc(alias = "signature")]
pub encoding: *const c_char,
}
/// Requires BLOCK_HAS_COPY_DISPOSE and BLOCK_HAS_SIGNATURE
#[repr(C)]
pub struct Block_descriptor_with_signature {
pub header: Block_descriptor_header,
/// Same as [`Block_descriptor::copy`].
pub copy: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
/// Same as [`Block_descriptor::dispose`].
pub dispose: Option<unsafe extern "C" fn(src: *mut c_void)>,
/// Objective-C type encoding of the block.
#[doc(alias = "signature")]
pub encoding: *const c_char,
}
// #[cfg(any(doc, feature = "apple"))]
// pub layout: *const c_char,
// #[repr(C)]
// pub struct Block_descriptor_small {
// pub size: u32,
// pub signature: i32,
// pub layout: i32,
// pub copy: i32,
// pub dispose: i32,
// }
// #[repr(C)]
// pub struct Block_basic {
// pub isa: *mut c_void,
// pub Block_flags: i32,
// pub Block_size: i32,
// pub Block_invoke: Option<unsafe extern "C" fn()>,
// pub Block_copy: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
// pub Block_dispose: Option<unsafe extern "C" fn(block: *mut c_void)>,
// }
// Example usage: https://github.com/apple-oss-distributions/libdispatch/blob/libdispatch-84.5/src/once.c
/// Structure used for on-stack variables that are referenced by blocks.
#[repr(C)]
#[doc(alias = "Block_byref_1")]
pub struct Block_byref_header {
/// Class pointer. Currently unused on GNUStep and always NULL. Could be
/// used in the future to support introspection.
pub isa: *const Class,
/// The pointer to the structure that contains the real version of the
/// data. All accesses go via this pointer. If an on-stack byref structure
/// is copied to the heap, then its forwarding pointer should point to the
/// heap version. Otherwise it should point to itself.
pub forwarding: *mut Block_byref_header,
/// Flags and reference count.
///
/// TODO: Volatile!
pub flags: block_flags,
#[cfg(feature = "apple")]
/// Size of this structure.
pub size: u32,
#[cfg(not(feature = "apple"))]
/// Size of this structure.
pub size: i32,
}
/// Structure used for on-stack variables that are referenced by blocks.
///
/// requires BLOCK_BYREF_HAS_COPY_DISPOSE
#[repr(C)]
#[doc(alias = "Block_byref_2")]
pub struct Block_byref {
pub header: Block_byref_header,
/// Copy function.
pub keep: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
/// Dispose function.
pub destroy: Option<unsafe extern "C" fn(src: *mut c_void)>,
}
#[cfg(any(doc, feature = "apple"))]
/// Structure used for on-stack variables that are referenced by blocks.
///
/// requires BLOCK_BYREF_LAYOUT_EXTENDED
#[repr(C)]
#[doc(alias = "Block_byref_3")]
pub struct Block_byref_extended {
pub header: Block_byref_header,
/// Same as [`Block_byref::keep`].
pub keep: Option<unsafe extern "C" fn(dst: *mut c_void, src: *mut c_void)>,
/// Same as [`Block_byref::destroy`].
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(_) -> _);
}
}
}