Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
166
third-party/vendor/objc-sys/src/class.rs
vendored
Normal file
166
third-party/vendor/objc-sys/src/class.rs
vendored
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
use std::os::raw::{c_char, c_int, c_uint};
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use crate::{objc_ivar, objc_method, objc_object, objc_property, objc_property_attribute_t};
|
||||
use crate::{objc_protocol, objc_selector, OpaqueData, BOOL, IMP};
|
||||
|
||||
/// An opaque type that represents an Objective-C class.
|
||||
#[repr(C)]
|
||||
pub struct objc_class {
|
||||
// `isa` field is deprecated and not available on GNUStep, so we don't
|
||||
// expose it here. Use `class_getSuperclass` instead.
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
/// This is `c_char` in GNUStep's libobjc2 and `uint8_t` in Apple's objc4.
|
||||
///
|
||||
/// The pointer represents opaque data, and is definitely not just an integer,
|
||||
/// so its signedness (i8 vs. u8) is not applicable.
|
||||
///
|
||||
/// So we just assign it here as a private alias to u8, to not document the
|
||||
/// difference.
|
||||
type ivar_layout_type = u8;
|
||||
|
||||
// May call `resolveClassMethod:` or `resolveInstanceMethod:`.
|
||||
extern_c_unwind! {
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getClassMethod(
|
||||
cls: *const objc_class,
|
||||
name: *const objc_selector,
|
||||
) -> *const objc_method;
|
||||
#[cfg(any(doc, not(objfw)))] // Available in newer versions
|
||||
pub fn class_getInstanceMethod(
|
||||
cls: *const objc_class,
|
||||
name: *const objc_selector,
|
||||
) -> *const objc_method;
|
||||
|
||||
pub fn class_respondsToSelector(cls: *const objc_class, sel: *const objc_selector) -> BOOL;
|
||||
|
||||
// #[deprecated = "use class_getMethodImplementation instead"]
|
||||
// #[cfg(any(doc, apple))]
|
||||
// pub fn class_lookupMethod
|
||||
// #[deprecated = "use class_respondsToSelector instead"]
|
||||
// #[cfg(any(doc, apple))]
|
||||
// pub fn class_respondsToMethod
|
||||
}
|
||||
|
||||
// TODO: Hooks registered with objc_setHook_getClass may be allowed to unwind?
|
||||
extern_c! {
|
||||
pub fn objc_getClass(name: *const c_char) -> *const objc_class;
|
||||
pub fn objc_getRequiredClass(name: *const c_char) -> *const objc_class;
|
||||
pub fn objc_lookUpClass(name: *const c_char) -> *const objc_class;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_getMetaClass(name: *const c_char) -> *const objc_class;
|
||||
pub fn objc_copyClassList(out_len: *mut c_uint) -> *mut *const objc_class;
|
||||
pub fn objc_getClassList(buffer: *mut *const objc_class, buffer_len: c_int) -> c_int;
|
||||
|
||||
pub fn objc_allocateClassPair(
|
||||
superclass: *const objc_class,
|
||||
name: *const c_char,
|
||||
extra_bytes: usize,
|
||||
) -> *mut objc_class;
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_duplicateClass(
|
||||
original: *const objc_class,
|
||||
name: *const c_char,
|
||||
extra_bytes: usize,
|
||||
) -> *mut objc_class;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_disposeClassPair(cls: *mut objc_class);
|
||||
pub fn objc_registerClassPair(cls: *mut objc_class);
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_addIvar(
|
||||
cls: *mut objc_class,
|
||||
name: *const c_char,
|
||||
size: usize,
|
||||
alignment: u8,
|
||||
types: *const c_char,
|
||||
) -> BOOL;
|
||||
pub fn class_addMethod(
|
||||
cls: *mut objc_class,
|
||||
name: *const objc_selector,
|
||||
imp: IMP,
|
||||
types: *const c_char,
|
||||
) -> BOOL;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_addProperty(
|
||||
cls: *mut objc_class,
|
||||
name: *const c_char,
|
||||
attributes: *const objc_property_attribute_t,
|
||||
attributes_count: c_uint,
|
||||
) -> BOOL;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_addProtocol(cls: *mut objc_class, protocol: *const objc_protocol) -> BOOL;
|
||||
pub fn class_conformsToProtocol(cls: *const objc_class, protocol: *const objc_protocol)
|
||||
-> BOOL;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))] // Available in newer versions
|
||||
pub fn class_copyIvarList(
|
||||
cls: *const objc_class,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_ivar;
|
||||
#[cfg(any(doc, not(objfw)))] // Available in newer versions
|
||||
pub fn class_copyMethodList(
|
||||
cls: *const objc_class,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_method;
|
||||
#[cfg(any(doc, not(objfw)))] // Available in newer versions
|
||||
pub fn class_copyPropertyList(
|
||||
cls: *const objc_class,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_property;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_copyProtocolList(
|
||||
cls: *const objc_class,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_protocol;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_createInstance(cls: *const objc_class, extra_bytes: usize) -> *mut objc_object;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getClassVariable(cls: *const objc_class, name: *const c_char) -> *const objc_ivar;
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn class_getImageName(cls: *const objc_class) -> *const c_char;
|
||||
pub fn class_getInstanceSize(cls: *const objc_class) -> usize;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getInstanceVariable(
|
||||
cls: *const objc_class,
|
||||
name: *const c_char,
|
||||
) -> *const objc_ivar;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getIvarLayout(cls: *const objc_class) -> *const ivar_layout_type;
|
||||
pub fn class_getName(cls: *const objc_class) -> *const c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getProperty(cls: *const objc_class, name: *const c_char) -> *const objc_property;
|
||||
pub fn class_getSuperclass(cls: *const objc_class) -> *const objc_class;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_getVersion(cls: *const objc_class) -> c_int;
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn class_getWeakIvarLayout(cls: *const objc_class) -> *const ivar_layout_type;
|
||||
pub fn class_isMetaClass(cls: *const objc_class) -> BOOL;
|
||||
pub fn class_replaceMethod(
|
||||
cls: *mut objc_class,
|
||||
name: *const objc_selector,
|
||||
imp: IMP,
|
||||
types: *const c_char,
|
||||
) -> IMP;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_replaceProperty(
|
||||
cls: *mut objc_class,
|
||||
name: *const c_char,
|
||||
attributes: *const objc_property_attribute_t,
|
||||
attributes_len: c_uint,
|
||||
);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_setIvarLayout(cls: *mut objc_class, layout: *const ivar_layout_type);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn class_setVersion(cls: *mut objc_class, version: c_int);
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn class_setWeakIvarLayout(cls: *mut objc_class, layout: *const ivar_layout_type);
|
||||
|
||||
// #[deprecated = "not recommended"]
|
||||
// pub fn class_setSuperclass
|
||||
}
|
||||
38
third-party/vendor/objc-sys/src/constants.rs
vendored
Normal file
38
third-party/vendor/objc-sys/src/constants.rs
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//! Various common #defines and enum constants.
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
use std::os::raw::c_int;
|
||||
|
||||
use crate::{id, objc_class, BOOL};
|
||||
|
||||
/// The equivalent of `true` for Objective-C's [`BOOL`][`super::BOOL`] type.
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const YES: BOOL = true as BOOL; // true -> 1
|
||||
|
||||
/// The equivalent of `false` for Objective-C's [`BOOL`][`super::BOOL`] type.
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
pub const NO: BOOL = false as BOOL; // false -> 0
|
||||
|
||||
/// A quick alias for a [`null_mut`][`core::ptr::null_mut`] object / instance.
|
||||
pub const nil: id = 0 as *mut _;
|
||||
|
||||
/// A quick alias for a [`null_mut`][`core::ptr::null_mut`] class.
|
||||
pub const Nil: *mut objc_class = 0 as *mut _;
|
||||
|
||||
pub type objc_AssociationPolicy = usize;
|
||||
pub const OBJC_ASSOCIATION_ASSIGN: objc_AssociationPolicy = 0;
|
||||
pub const OBJC_ASSOCIATION_RETAIN_NONATOMIC: objc_AssociationPolicy = 1;
|
||||
pub const OBJC_ASSOCIATION_COPY_NONATOMIC: objc_AssociationPolicy = 3;
|
||||
pub const OBJC_ASSOCIATION_RETAIN: objc_AssociationPolicy = 769;
|
||||
pub const OBJC_ASSOCIATION_COPY: objc_AssociationPolicy = 771;
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
pub const OBJC_SYNC_SUCCESS: c_int = 0;
|
||||
#[cfg(any(doc, apple))]
|
||||
pub const OBJC_SYNC_NOT_OWNING_THREAD_ERROR: c_int = -1;
|
||||
/// Only relevant before macOS 10.13
|
||||
#[cfg(any(doc, apple))]
|
||||
pub const OBJC_SYNC_TIMED_OUT: c_int = -2;
|
||||
/// Only relevant before macOS 10.13
|
||||
#[cfg(any(doc, apple))]
|
||||
pub const OBJC_SYNC_NOT_INITIALIZED: c_int = -3;
|
||||
116
third-party/vendor/objc-sys/src/exception.rs
vendored
Normal file
116
third-party/vendor/objc-sys/src/exception.rs
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//! Defined in:
|
||||
//! Apple: `objc-exception.h`
|
||||
//! GNUStep: `eh_personality.c`, which is a bit brittle to rely on, but I
|
||||
//! think it's fine...
|
||||
use core::ffi::c_void;
|
||||
#[cfg(any(doc, apple_new))]
|
||||
use std::os::raw::c_int;
|
||||
#[cfg(feature = "unstable-exception")]
|
||||
use std::os::raw::c_uchar;
|
||||
|
||||
#[cfg(any(doc, apple_new))]
|
||||
use crate::objc_class;
|
||||
use crate::objc_object;
|
||||
|
||||
/// Remember that this is non-null!
|
||||
#[cfg(any(doc, apple_new))]
|
||||
pub type objc_exception_matcher =
|
||||
unsafe extern "C" fn(catch_type: *mut objc_class, exception: *mut objc_object) -> c_int;
|
||||
|
||||
/// Remember that this is non-null!
|
||||
#[cfg(any(doc, apple_new))]
|
||||
pub type objc_exception_preprocessor =
|
||||
unsafe extern "C" fn(exception: *mut objc_object) -> *mut objc_object;
|
||||
|
||||
/// Remember that this is non-null!
|
||||
#[cfg(any(doc, apple_new))]
|
||||
pub type objc_uncaught_exception_handler = unsafe extern "C" fn(exception: *mut objc_object);
|
||||
|
||||
#[cfg(objfw)]
|
||||
pub type objc_uncaught_exception_handler =
|
||||
Option<unsafe extern "C" fn(exception: *mut objc_object)>;
|
||||
|
||||
/// Remember that this is non-null!
|
||||
#[cfg(any(doc, all(apple_new, target_os = "macos")))]
|
||||
pub type objc_exception_handler =
|
||||
unsafe extern "C" fn(unused: *mut objc_object, context: *mut c_void);
|
||||
|
||||
#[cfg(all(feature = "unstable-exception", not(feature = "unstable-c-unwind")))]
|
||||
type TryCatchClosure = extern "C" fn(*mut c_void);
|
||||
#[cfg(all(feature = "unstable-exception", feature = "unstable-c-unwind"))]
|
||||
type TryCatchClosure = extern "C-unwind" fn(*mut c_void);
|
||||
|
||||
extern_c_unwind! {
|
||||
/// See [`objc-exception.h`].
|
||||
///
|
||||
/// [`objc-exception.h`]: https://github.com/apple-oss-distributions/objc4/blob/objc4-818.2/runtime/objc-exception.h
|
||||
pub fn objc_exception_throw(exception: *mut objc_object) -> !;
|
||||
|
||||
#[cfg(apple_new)]
|
||||
pub fn objc_exception_rethrow() -> !;
|
||||
|
||||
#[cfg(gnustep)]
|
||||
pub fn objc_exception_rethrow(exc_buf: *mut c_void) -> !;
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
#[cfg(any(doc, gnustep, apple_new))]
|
||||
pub fn objc_begin_catch(exc_buf: *mut c_void) -> *mut objc_object;
|
||||
#[cfg(any(doc, gnustep, apple_new))]
|
||||
pub fn objc_end_catch();
|
||||
|
||||
#[cfg(any(doc, apple_old))]
|
||||
pub fn objc_exception_try_enter(exception_data: *const c_void);
|
||||
|
||||
#[cfg(any(doc, apple_old))]
|
||||
pub fn objc_exception_try_exit(exception_data: *const c_void);
|
||||
|
||||
// objc_exception_extract
|
||||
// objc_exception_match
|
||||
// objc_exception_get_functions
|
||||
// objc_exception_set_functions
|
||||
|
||||
#[cfg(any(doc, apple_new))]
|
||||
pub fn objc_setExceptionMatcher(f: objc_exception_matcher) -> objc_exception_matcher;
|
||||
#[cfg(any(doc, apple_new))]
|
||||
pub fn objc_setExceptionPreprocessor(
|
||||
f: objc_exception_preprocessor,
|
||||
) -> objc_exception_preprocessor;
|
||||
#[cfg(any(doc, apple_new, objfw))]
|
||||
pub fn objc_setUncaughtExceptionHandler(
|
||||
f: objc_uncaught_exception_handler,
|
||||
) -> objc_uncaught_exception_handler;
|
||||
|
||||
#[cfg(any(doc, all(apple_new, target_os = "macos")))]
|
||||
pub fn objc_addExceptionHandler(f: objc_exception_handler, context: *mut c_void) -> usize;
|
||||
#[cfg(any(doc, all(apple_new, target_os = "macos")))]
|
||||
pub fn objc_removeExceptionHandler(token: usize);
|
||||
|
||||
// Only available when ENABLE_OBJCXX is set, and a useable C++ runtime is
|
||||
// present when building libobjc2.
|
||||
//
|
||||
// #[cfg(any(doc, gnustep))]
|
||||
// pub fn objc_set_apple_compatible_objcxx_exceptions(newValue: c_int) -> c_int;
|
||||
|
||||
/// Call the given function inside an Objective-C `@try/@catch` block.
|
||||
///
|
||||
/// Defined in `extern/exception.m` and compiled in `build.rs`.
|
||||
///
|
||||
/// Alternatively, we could manually write assembly for this function like
|
||||
/// [`objrs` does][manual-asm] does, that would cut down on a build stage
|
||||
/// (and would probably give us a bit better performance), but it gets
|
||||
/// unwieldy _very_ quickly, so I chose the much more stable option.
|
||||
///
|
||||
/// Another thing to remember: While Rust's and Objective-C's unwinding
|
||||
/// mechanisms are similar now, Rust's is explicitly unspecified, and they
|
||||
/// may diverge significantly in the future; so handling this in pure Rust
|
||||
/// (using mechanisms like core::intrinsics::r#try) is not an option!
|
||||
///
|
||||
/// [manual-asm]: https://gitlab.com/objrs/objrs/-/blob/b4f6598696b3fa622e6fddce7aff281770b0a8c2/src/exception.rs
|
||||
#[cfg(feature = "unstable-exception")]
|
||||
pub fn rust_objc_sys_0_2_try_catch_exception(
|
||||
f: TryCatchClosure,
|
||||
context: *mut c_void,
|
||||
error: *mut *mut objc_object,
|
||||
) -> c_uchar;
|
||||
}
|
||||
45
third-party/vendor/objc-sys/src/image_info.rs
vendored
Normal file
45
third-party/vendor/objc-sys/src/image_info.rs
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#[repr(C)]
|
||||
#[doc(hidden)] // Private for now
|
||||
pub struct __ImageInfo {
|
||||
// These are not actually `unsigned int`, even though the docs say so
|
||||
/// The version of the image info struct.
|
||||
version: u32,
|
||||
flags: u32,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
impl __ImageInfo {
|
||||
/// Unused
|
||||
const FIX_AND_CONTINUE: u32 = 1 << 0;
|
||||
const SUPPORTS_GARBAGE_COLLECTED: u32 = 1 << 1;
|
||||
const REQUIRES_GARBAGE_COLLECTION: u32 = 1 << 2;
|
||||
const OPTIMIZED_BY_DYLD: u32 = 1 << 3; // TODO
|
||||
/// Unused
|
||||
const CORRECTED_SYNTHESIZE: u32 = 1 << 4;
|
||||
/// Whether we're compiling this to run on a simulator.
|
||||
const IMAGE_IS_SIMULATED: u32 = 1 << 5;
|
||||
/// Whether we are generating class properties.
|
||||
const CLASS_PROPERTIES: u32 = 1 << 6;
|
||||
const DYLD_PREOPTIMIZED: u32 = 1 << 7;
|
||||
|
||||
const SWIFT_ABI_VERSION_SHIFT: u32 = 8;
|
||||
const SWIFT_ABI_VERSION_MASK: u32 = 0xff << Self::SWIFT_ABI_VERSION_SHIFT;
|
||||
const SWIFT_MINOR_VERSION_SHIFT: u32 = 16;
|
||||
const SWIFT_MINOR_VERSION_MASK: u32 = 0xff << Self::SWIFT_MINOR_VERSION_SHIFT;
|
||||
const SWIFT_MAJOR_VERSION_SHIFT: u32 = 24;
|
||||
const SWIFT_MAJOR_VERSION_MASK: u32 = 0xff << Self::SWIFT_MAJOR_VERSION_SHIFT;
|
||||
|
||||
/// Fetches the image info for the current runtime + target combination
|
||||
#[inline]
|
||||
pub const fn system() -> Self {
|
||||
// We don't currently do anything relating to class properties, but
|
||||
// let's just mimic what Clang does!
|
||||
let mut flags = Self::CLASS_PROPERTIES;
|
||||
|
||||
if cfg!(target_simulator) {
|
||||
flags |= Self::IMAGE_IS_SIMULATED;
|
||||
}
|
||||
|
||||
Self { version: 0, flags }
|
||||
}
|
||||
}
|
||||
190
third-party/vendor/objc-sys/src/lib.rs
vendored
Normal file
190
third-party/vendor/objc-sys/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
//! # Raw bindings to Objective-C runtimes
|
||||
//!
|
||||
//! These bindings contain almost no documentation, so it is highly
|
||||
//! recommended to read the documentation of the original libraries:
|
||||
//! - Apple's [official documentation][apple].
|
||||
//! - Apple's `objc4` [source code][objc4], in particular `runtime.h`.
|
||||
//! - GNUStep's `libobjc2` [source code][libobjc2], in particular `runtime.h`.
|
||||
//!
|
||||
//! See also the [`README.md`](https://crates.io/crates/objc-sys) for more
|
||||
//! background information, and for how to configure the desired runtime.
|
||||
//!
|
||||
//! [apple]: https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc
|
||||
//! [libobjc2]: https://github.com/gnustep/libobjc2/tree/v2.1/objc
|
||||
//! [objc4]: https://github.com/apple-oss-distributions/objc4
|
||||
|
||||
#![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)]
|
||||
#![allow(clippy::upper_case_acronyms)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_snake_case)]
|
||||
#![doc(html_root_url = "https://docs.rs/objc-sys/0.2.0-beta.2")]
|
||||
#![cfg_attr(feature = "unstable-c-unwind", feature(c_unwind))]
|
||||
#![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))]
|
||||
#![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))]
|
||||
|
||||
// TODO: Remove this and add "no-std" category to Cargo.toml
|
||||
// Requires a better solution for C-types in `no_std` crates.
|
||||
// See https://github.com/japaric/cty/issues/14.
|
||||
extern crate std;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
compile_error!("The `std` feature currently must be enabled.");
|
||||
|
||||
#[cfg(doctest)]
|
||||
#[doc = include_str!("../README.md")]
|
||||
extern "C" {}
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::marker::{PhantomData, PhantomPinned};
|
||||
|
||||
macro_rules! generate_linking_tests {
|
||||
{
|
||||
extern $abi:literal {$(
|
||||
$(#[$m:meta])*
|
||||
$v:vis fn $name:ident(
|
||||
$($(#[$a_m:meta])* $a:ident: $t:ty),* $(,)?
|
||||
) $(-> $r:ty)?;
|
||||
)+}
|
||||
mod $test_name:ident;
|
||||
} => {
|
||||
extern $abi {$(
|
||||
$(#[$m])*
|
||||
$v fn $name($($(#[$a_m])* $a: $t),*) $(-> $r)?;
|
||||
)+}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cfg(test)]
|
||||
mod $test_name {
|
||||
#[allow(unused)]
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
$(#[$m])*
|
||||
#[test]
|
||||
fn $name() {
|
||||
// Get function pointer to make the linker require the
|
||||
// symbol to be available.
|
||||
let f: unsafe extern $abi fn($($(#[$a_m])* $t),*) $(-> $r)? = crate::$name;
|
||||
// Workaround for https://github.com/rust-lang/rust/pull/92964
|
||||
#[cfg(feature = "unstable-c-unwind")]
|
||||
#[allow(clippy::useless_transmute)]
|
||||
let f: unsafe extern "C" fn() = unsafe { core::mem::transmute(f) };
|
||||
// Execute side-effect to ensure it is not optimized away.
|
||||
std::println!("{:p}", f);
|
||||
}
|
||||
)+
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! extern_c {
|
||||
{
|
||||
$(
|
||||
$(#[$m:meta])*
|
||||
$v:vis fn $name:ident(
|
||||
$($(#[$a_m:meta])* $a:ident: $t:ty),* $(,)?
|
||||
) $(-> $r:ty)?;
|
||||
)+
|
||||
} => {
|
||||
generate_linking_tests! {
|
||||
extern "C" {$(
|
||||
$(#[$m])*
|
||||
$v fn $name($($(#[$a_m])* $a: $t),*) $(-> $r)?;
|
||||
)+}
|
||||
mod test_linkable;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// A lot of places may call `+initialize`, but the runtime guards those calls
|
||||
// with `@try/@catch` blocks already, so we don't need to mark every function
|
||||
// "C-unwind", only certain ones!
|
||||
macro_rules! extern_c_unwind {
|
||||
{
|
||||
$(
|
||||
$(#[$m:meta])*
|
||||
$v:vis fn $name:ident(
|
||||
$($(#[$a_m:meta])* $a:ident: $t:ty),* $(,)?
|
||||
) $(-> $r:ty)?;
|
||||
)+
|
||||
} => {
|
||||
#[cfg(not(feature = "unstable-c-unwind"))]
|
||||
generate_linking_tests! {
|
||||
extern "C" {$(
|
||||
$(#[$m])*
|
||||
$v fn $name($($(#[$a_m])* $a: $t),*) $(-> $r)?;
|
||||
)+}
|
||||
mod test_linkable_unwind;
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-c-unwind")]
|
||||
generate_linking_tests! {
|
||||
extern "C-unwind" {$(
|
||||
$(#[$m])*
|
||||
$v fn $name($($(#[$a_m])* $a: $t),*) $(-> $r)?;
|
||||
)+}
|
||||
mod test_linkable_unwind;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod class;
|
||||
mod constants;
|
||||
|
||||
mod exception;
|
||||
mod image_info;
|
||||
mod message;
|
||||
mod method;
|
||||
mod object;
|
||||
mod property;
|
||||
mod protocol;
|
||||
mod rc;
|
||||
mod selector;
|
||||
mod types;
|
||||
mod various;
|
||||
|
||||
pub use class::*;
|
||||
pub use constants::*;
|
||||
pub use exception::*;
|
||||
pub use image_info::*;
|
||||
pub use message::*;
|
||||
pub use method::*;
|
||||
pub use object::*;
|
||||
pub use property::*;
|
||||
pub use protocol::*;
|
||||
pub use rc::*;
|
||||
pub use selector::*;
|
||||
pub use types::*;
|
||||
pub use various::*;
|
||||
|
||||
/// We don't know much about the actual structs, so better mark them `!Send`,
|
||||
/// `!Sync`, `!UnwindSafe`, `!RefUnwindSafe`, `!Unpin` and as mutable behind
|
||||
/// shared references.
|
||||
///
|
||||
/// Downstream libraries can always manually opt in to these types afterwards.
|
||||
/// (It's also less of a breaking change on our part if we re-add these).
|
||||
///
|
||||
/// TODO: Replace this with `extern type` to also mark it as `!Sized`.
|
||||
type OpaqueData = UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::ffi::CStr;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
// Verify that this library links and works fine by itself
|
||||
let name = CStr::from_bytes_with_nul(b"abc:def:\0").unwrap();
|
||||
let sel = unsafe { sel_registerName(name.as_ptr()) };
|
||||
let rtn = unsafe { CStr::from_ptr(sel_getName(sel)) };
|
||||
assert_eq!(name, rtn);
|
||||
}
|
||||
}
|
||||
87
third-party/vendor/objc-sys/src/message.rs
vendored
Normal file
87
third-party/vendor/objc-sys/src/message.rs
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
//! The `objc_msgSend` familiy of functions.
|
||||
//!
|
||||
//! Most of these are `cfg`-gated, these configs are semver-stable.
|
||||
//!
|
||||
//! TODO: Some of these are only supported on _some_ GNUStep targets!
|
||||
use crate::{objc_class, objc_object};
|
||||
#[cfg(any(doc, gnustep, objfw))]
|
||||
use crate::{objc_selector, IMP};
|
||||
|
||||
/// Specifies data used when sending messages to superclasses.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
// TODO: Does this belong in this file or in types.rs?
|
||||
pub struct objc_super {
|
||||
/// The object / instance to send a message to.
|
||||
pub receiver: *mut objc_object,
|
||||
/// The particular superclass of the instance to message.
|
||||
///
|
||||
/// Named `class` in older Objective-C versions.
|
||||
pub super_class: *const objc_class,
|
||||
}
|
||||
|
||||
// All message sending functions should use "C-unwind"!
|
||||
//
|
||||
// Note that lookup functions won't throw exceptions themselves, but they can
|
||||
// call hooks, `resolveClassMethod:` and `resolveInstanceMethod:`, so we have
|
||||
// to make those "C-unwind" as well!
|
||||
extern_c_unwind! {
|
||||
#[cfg(any(doc, gnustep, objfw))]
|
||||
pub fn objc_msg_lookup(receiver: *mut objc_object, sel: *const objc_selector) -> IMP;
|
||||
#[cfg(any(doc, objfw))]
|
||||
pub fn objc_msg_lookup_stret(receiver: *mut objc_object, sel: *const objc_selector) -> IMP;
|
||||
#[cfg(any(doc, gnustep, objfw))]
|
||||
pub fn objc_msg_lookup_super(sup: *const objc_super, sel: *const objc_selector) -> IMP;
|
||||
#[cfg(any(doc, objfw))]
|
||||
pub fn objc_msg_lookup_super_stret(sup: *const objc_super, sel: *const objc_selector) -> IMP;
|
||||
// #[cfg(any(doc, gnustep))]
|
||||
// objc_msg_lookup_sender
|
||||
// objc_msgLookup family available in macOS >= 10.12
|
||||
|
||||
// objc_msgSend_noarg
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_msgSend();
|
||||
// objc_msgSend_debug
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_msgSendSuper();
|
||||
// objc_msgSendSuper2
|
||||
// objc_msgSendSuper2_debug
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn method_invoke();
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn _objc_msgForward();
|
||||
pub fn class_getMethodImplementation();
|
||||
|
||||
// Struct return. Not available on __arm64__:
|
||||
|
||||
#[cfg(any(doc, all(not(objfw), not(target_arch = "aarch64"))))]
|
||||
pub fn objc_msgSend_stret();
|
||||
// objc_msgSend_stret_debug
|
||||
|
||||
#[cfg(any(doc, all(apple, not(target_arch = "aarch64"))))]
|
||||
pub fn objc_msgSendSuper_stret();
|
||||
// objc_msgSendSuper2_stret
|
||||
// objc_msgSendSuper2_stret_debug
|
||||
|
||||
#[cfg(any(doc, all(apple, not(target_arch = "aarch64"))))]
|
||||
pub fn method_invoke_stret();
|
||||
#[cfg(any(doc, all(apple, not(target_arch = "aarch64"))))]
|
||||
pub fn _objc_msgForward_stret();
|
||||
#[cfg(any(doc, objfw, not(target_arch = "aarch64")))]
|
||||
pub fn class_getMethodImplementation_stret();
|
||||
|
||||
// __x86_64__ and __i386__
|
||||
|
||||
#[cfg(any(doc, all(not(objfw), any(target_arch = "x86_64", target_arch = "x86"))))]
|
||||
pub fn objc_msgSend_fpret();
|
||||
// objc_msgSend_fpret_debug
|
||||
|
||||
// __x86_64__
|
||||
|
||||
#[cfg(any(doc, all(apple, target_arch = "x86_64")))]
|
||||
pub fn objc_msgSend_fp2ret();
|
||||
// objc_msgSend_fp2ret_debug
|
||||
}
|
||||
54
third-party/vendor/objc-sys/src/method.rs
vendored
Normal file
54
third-party/vendor/objc-sys/src/method.rs
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use std::os::raw::c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use std::os::raw::c_uint;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use crate::IMP;
|
||||
use crate::{objc_selector, OpaqueData};
|
||||
|
||||
/// A type that represents a method in a class definition.
|
||||
#[repr(C)]
|
||||
pub struct objc_method {
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
/// Describes an Objective-C method.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct objc_method_description {
|
||||
/// The name of the method.
|
||||
pub name: *const objc_selector,
|
||||
/// The types of the method arguments.
|
||||
pub types: *const c_char,
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_copyArgumentType(method: *const objc_method, index: c_uint) -> *mut c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_copyReturnType(method: *const objc_method) -> *mut c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_exchangeImplementations(method1: *mut objc_method, method2: *mut objc_method);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getArgumentType(
|
||||
method: *const objc_method,
|
||||
index: c_uint,
|
||||
dst: *mut c_char,
|
||||
dst_len: usize,
|
||||
);
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn method_getDescription(m: *const objc_method) -> *const objc_method_description;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getImplementation(method: *const objc_method) -> IMP;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getName(method: *const objc_method) -> *const objc_selector;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getNumberOfArguments(method: *const objc_method) -> c_uint;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getReturnType(method: *const objc_method, dst: *mut c_char, dst_len: usize);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_getTypeEncoding(method: *const objc_method) -> *const c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn method_setImplementation(method: *const objc_method, imp: IMP) -> IMP;
|
||||
}
|
||||
104
third-party/vendor/objc-sys/src/object.rs
vendored
Normal file
104
third-party/vendor/objc-sys/src/object.rs
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#[cfg(any(doc, not(objfw)))]
|
||||
use core::ffi::c_void;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use crate::objc_ivar;
|
||||
use crate::{objc_class, OpaqueData};
|
||||
|
||||
/// An opaque type that represents an object / an instance of a class.
|
||||
#[repr(C)]
|
||||
pub struct objc_object {
|
||||
// `isa` field is deprecated, so we don't expose it here.
|
||||
// Use `object_getClass` instead.
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
pub fn object_getClass(obj: *const objc_object) -> *const objc_class;
|
||||
pub fn object_getClassName(obj: *const objc_object) -> *const c_char;
|
||||
pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_getIndexedIvars(obj: *const objc_object) -> *const c_void;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_getIvar(obj: *const objc_object, ivar: *const objc_ivar) -> *const objc_object;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_setIvar(obj: *mut objc_object, ivar: *const objc_ivar, value: *mut objc_object);
|
||||
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn object_copy(obj: *const objc_object, size: usize) -> *mut objc_object;
|
||||
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_dispose(obj: *mut objc_object) -> *mut objc_object;
|
||||
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_setInstanceVariable(
|
||||
obj: *mut objc_object,
|
||||
name: *const c_char,
|
||||
value: *mut c_void,
|
||||
) -> *const objc_ivar;
|
||||
|
||||
// Available in macOS 10.12
|
||||
// #[deprecated = "Not needed since ARC"]
|
||||
// #[cfg(any(doc, apple))]
|
||||
// pub fn object_setInstanceVariableWithStrongDefault(
|
||||
// obj: *mut objc_object,
|
||||
// name: *const c_char,
|
||||
// value: *mut c_void,
|
||||
// ) -> *const objc_ivar;
|
||||
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn object_getInstanceVariable(
|
||||
obj: *const objc_object,
|
||||
name: *const c_char,
|
||||
out_value: *mut *const c_void,
|
||||
) -> *const objc_ivar;
|
||||
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_getFutureClass(name: *const c_char) -> *const objc_class;
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_constructInstance(cls: *const objc_class, bytes: *mut c_void) -> *mut objc_object;
|
||||
#[deprecated = "Not needed since ARC"]
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_destructInstance(obj: *mut objc_object) -> *mut c_void;
|
||||
|
||||
// TODO: Unsure if we should expose these; are they useful, and stable?
|
||||
// Defined in objc-abi.h
|
||||
// pub fn objc_getProperty(
|
||||
// obj: *const objc_object,
|
||||
// sel: *const objc_selector,
|
||||
// offset: isize,
|
||||
// atomic: BOOL,
|
||||
// ) -> *mut c_void;
|
||||
// pub fn objc_setProperty(
|
||||
// obj: *const objc_object,
|
||||
// sel: *const objc_selector,
|
||||
// offset: isize,
|
||||
// newValue: *const c_void,
|
||||
// atomic: BOOL,
|
||||
// shouldCopy: i8,
|
||||
// );
|
||||
// This is generated in setters to struct properties.
|
||||
// pub fn objc_copyStruct(
|
||||
// dest: *mut c_void,
|
||||
// src: *const c_void,
|
||||
// size: isize,
|
||||
// atomic: BOOL,
|
||||
// hasStrong: BOOL,
|
||||
// );
|
||||
|
||||
// #[deprecated = "use object_copy instead"]
|
||||
// #[cfg(any(doc, all(apple, target_os = "macos")))]
|
||||
// object_copyFromZone
|
||||
// #[deprecated = "use class_createInstance instead"]
|
||||
// #[cfg(any(doc, all(apple, target_os = "macos")))]
|
||||
// class_createInstanceFromZone
|
||||
}
|
||||
41
third-party/vendor/objc-sys/src/property.rs
vendored
Normal file
41
third-party/vendor/objc-sys/src/property.rs
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use std::os::raw::c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use std::os::raw::c_uint;
|
||||
|
||||
use crate::OpaqueData;
|
||||
|
||||
/// An opaque type that describes a property in a class.
|
||||
#[repr(C)]
|
||||
pub struct objc_property {
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
/// Describes an Objective-C property attribute.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct objc_property_attribute_t {
|
||||
/// The name of the attribute.
|
||||
pub name: *const c_char,
|
||||
/// The value of the attribute
|
||||
///
|
||||
/// Usually NULL.
|
||||
pub value: *const c_char,
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn property_copyAttributeList(
|
||||
property: *const objc_property,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut objc_property_attribute_t;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn property_copyAttributeValue(
|
||||
property: *const objc_property,
|
||||
attribute_name: *const c_char,
|
||||
) -> *mut c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn property_getAttributes(property: *const objc_property) -> *const c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn property_getName(property: *const objc_property) -> *const c_char;
|
||||
}
|
||||
98
third-party/vendor/objc-sys/src/protocol.rs
vendored
Normal file
98
third-party/vendor/objc-sys/src/protocol.rs
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
use std::os::raw::c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use std::os::raw::c_uint;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use crate::{objc_method_description, objc_property, objc_property_attribute_t, objc_selector};
|
||||
use crate::{OpaqueData, BOOL};
|
||||
|
||||
/// Opaque type for Objective-C protocols.
|
||||
///
|
||||
/// Note that, although protocols are objects, sending messages to them is
|
||||
/// deprecated and may not work in the future.
|
||||
///
|
||||
/// The naming of this follows GNUStep; this does not exist in Apple's
|
||||
/// original, there `Protocol` is just a type alias of `objc_object`.
|
||||
#[repr(C)]
|
||||
pub struct objc_protocol {
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_getProtocol(name: *const c_char) -> *const objc_protocol;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_copyProtocolList(out_len: *mut c_uint) -> *mut *const objc_protocol;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_allocateProtocol(name: *const c_char) -> *mut objc_protocol;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_registerProtocol(proto: *mut objc_protocol);
|
||||
|
||||
// TODO: Verify unwinding
|
||||
pub fn protocol_conformsToProtocol(
|
||||
proto: *const objc_protocol,
|
||||
other: *const objc_protocol,
|
||||
) -> BOOL;
|
||||
// TODO: Verify unwinding
|
||||
pub fn protocol_isEqual(proto: *const objc_protocol, other: *const objc_protocol) -> BOOL;
|
||||
pub fn protocol_getName(proto: *const objc_protocol) -> *const c_char;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_addMethodDescription(
|
||||
proto: *mut objc_protocol,
|
||||
name: *const objc_selector,
|
||||
types: *const c_char,
|
||||
is_required_method: BOOL,
|
||||
is_instance_method: BOOL,
|
||||
);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_addProperty(
|
||||
proto: *mut objc_protocol,
|
||||
name: *const c_char,
|
||||
attributes: *const objc_property_attribute_t,
|
||||
attributes_len: c_uint,
|
||||
is_required_property: BOOL,
|
||||
is_instance_property: BOOL,
|
||||
);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_addProtocol(proto: *mut objc_protocol, addition: *const objc_protocol);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_copyMethodDescriptionList(
|
||||
proto: *const objc_protocol,
|
||||
is_required_method: BOOL,
|
||||
is_instance_method: BOOL,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut objc_method_description;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_copyPropertyList(
|
||||
proto: *const objc_protocol,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_property;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_copyProtocolList(
|
||||
proto: *const objc_protocol,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const objc_protocol;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_getMethodDescription(
|
||||
proto: *const objc_protocol,
|
||||
sel: *const objc_selector,
|
||||
is_required_method: BOOL,
|
||||
is_instance_method: BOOL,
|
||||
) -> objc_method_description;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn protocol_getProperty(
|
||||
proto: *const objc_protocol,
|
||||
name: *const c_char,
|
||||
is_required_property: BOOL,
|
||||
is_instance_property: BOOL,
|
||||
) -> *const objc_property;
|
||||
|
||||
// #[cfg(any(doc, macos >= 10.12))]
|
||||
// protocol_copyPropertyList2
|
||||
|
||||
// #[cfg(any(doc, gnustep))]
|
||||
// _protocol_getMethodTypeEncoding
|
||||
}
|
||||
63
third-party/vendor/objc-sys/src/rc.rs
vendored
Normal file
63
third-party/vendor/objc-sys/src/rc.rs
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//! ARC functions.
|
||||
//!
|
||||
//! Is available in Clang's [documentation][ARC] so these are safe to rely on.
|
||||
//!
|
||||
//! All available since macOS `10.7`.
|
||||
//!
|
||||
//! Defined in:
|
||||
//! - Apple: `objc-internal.h`
|
||||
//! - GNUStep: `objc-arc.h`
|
||||
//! - ObjFW: `runtime/arc.m`
|
||||
//!
|
||||
//! [ARC]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support>
|
||||
use core::ffi::c_void;
|
||||
|
||||
use crate::objc_object;
|
||||
|
||||
// All of these very rarely unwind, but may if the user defined methods
|
||||
// `retain`, `release`, `autorelease` or `dealloc` do.
|
||||
extern_c_unwind! {
|
||||
// Autoreleasepool
|
||||
// ObjFW: Defined in `autorelease.h`, not available with libobjfw-rt!
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_autoreleasePoolPop(pool: *mut c_void);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_autoreleasePoolPush() -> *mut c_void;
|
||||
|
||||
// Autorelease
|
||||
|
||||
pub fn objc_autorelease(value: *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_autoreleaseReturnValue(value: *mut objc_object) -> *mut objc_object;
|
||||
|
||||
// Weak pointers
|
||||
|
||||
pub fn objc_copyWeak(to: *mut *mut objc_object, from: *mut *mut objc_object);
|
||||
pub fn objc_destroyWeak(addr: *mut *mut objc_object);
|
||||
pub fn objc_initWeak(addr: *mut *mut objc_object, value: *mut objc_object) -> *mut objc_object;
|
||||
// Defined in runtime.h
|
||||
pub fn objc_loadWeak(addr: *mut *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_loadWeakRetained(addr: *mut *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_moveWeak(to: *mut *mut objc_object, from: *mut *mut objc_object);
|
||||
|
||||
// Retain / release
|
||||
|
||||
pub fn objc_release(value: *mut objc_object);
|
||||
pub fn objc_retain(value: *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_retainAutorelease(value: *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_retainAutoreleaseReturnValue(value: *mut objc_object) -> *mut objc_object;
|
||||
pub fn objc_retainAutoreleasedReturnValue(value: *mut objc_object) -> *mut objc_object;
|
||||
// Defined in objc-abi.h
|
||||
pub fn objc_retainBlock(value: *mut objc_object) -> *mut objc_object;
|
||||
|
||||
// Storing values
|
||||
|
||||
pub fn objc_storeStrong(addr: *mut *mut objc_object, value: *mut objc_object);
|
||||
// Defined in runtime.h
|
||||
pub fn objc_storeWeak(addr: *mut *mut objc_object, value: *mut objc_object)
|
||||
-> *mut objc_object;
|
||||
|
||||
// TODO: Decide about nonstandard extensions like these:
|
||||
// #[cfg(any(doc, gnustep))]
|
||||
// pub fn objc_delete_weak_refs(obj: *mut objc_object) -> BOOL;
|
||||
}
|
||||
24
third-party/vendor/objc-sys/src/selector.rs
vendored
Normal file
24
third-party/vendor/objc-sys/src/selector.rs
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use std::os::raw::c_char;
|
||||
|
||||
use crate::{OpaqueData, BOOL};
|
||||
|
||||
/// An opaque type that represents a method selector.
|
||||
///
|
||||
/// Selectors are immutable.
|
||||
#[repr(C)]
|
||||
pub struct objc_selector {
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
pub fn sel_getName(sel: *const objc_selector) -> *const c_char;
|
||||
pub fn sel_isEqual(lhs: *const objc_selector, rhs: *const objc_selector) -> BOOL;
|
||||
pub fn sel_registerName(name: *const c_char) -> *const objc_selector;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn sel_getUid(name: *const c_char) -> *const objc_selector;
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn sel_isMapped(sel: *const objc_selector) -> BOOL;
|
||||
}
|
||||
195
third-party/vendor/objc-sys/src/types.rs
vendored
Normal file
195
third-party/vendor/objc-sys/src/types.rs
vendored
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
//! Objective-C type aliases.
|
||||
|
||||
use crate::{objc_object, objc_selector};
|
||||
|
||||
/// The BOOL typedef for Apple's objc4.
|
||||
///
|
||||
/// Don't be fooled by the backup definition in `objc.h`; __OBJC_BOOL_IS_BOOL
|
||||
/// is always defined by `clang` when compiling Objective-C sources. The below
|
||||
/// cfgs are determined experimentally via. cross compiling.
|
||||
#[cfg(apple)]
|
||||
mod inner {
|
||||
// __OBJC_BOOL_IS_BOOL
|
||||
#[cfg(any(
|
||||
// aarch64-apple-*
|
||||
target_arch = "aarch64",
|
||||
// + x86_64-apple-ios (but not x86_64-apple-ios-macabi)
|
||||
all(target_os = "ios", target_pointer_width = "64", not(target_abi_macabi)),
|
||||
// + x86_64-apple-tvos
|
||||
all(target_os = "tvos", target_pointer_width = "64"),
|
||||
// + *-apple-watchos (no Rust targets with this yet)
|
||||
target_os = "watchos",
|
||||
))]
|
||||
// C: _Bool
|
||||
pub(crate) type BOOL = bool;
|
||||
|
||||
// Inverse of the above
|
||||
#[cfg(not(any(
|
||||
target_arch = "aarch64",
|
||||
all(target_os = "ios", target_pointer_width = "64", not(target_abi_macabi)),
|
||||
all(target_os = "tvos", target_pointer_width = "64"),
|
||||
target_os = "watchos",
|
||||
)))]
|
||||
// C: (explicitly) signed char
|
||||
pub(crate) type BOOL = i8;
|
||||
}
|
||||
|
||||
// GNUStep's and Microsoft's libobjc2
|
||||
#[cfg(all(gnustep, libobjc2_strict_apple_compat))]
|
||||
mod inner {
|
||||
// C: (explicitly) signed char
|
||||
pub(crate) type BOOL = i8;
|
||||
}
|
||||
|
||||
#[cfg(all(gnustep, not(libobjc2_strict_apple_compat)))]
|
||||
mod inner {
|
||||
// windows && !32bit-MinGW
|
||||
#[cfg(all(windows, not(all(target_pointer_width = "64", target_env = "gnu"))))]
|
||||
pub(crate) type BOOL = std::os::raw::c_int;
|
||||
|
||||
// The inverse
|
||||
#[cfg(not(all(windows, not(all(target_pointer_width = "64", target_env = "gnu")))))]
|
||||
// C: unsigned char
|
||||
pub(crate) type BOOL = u8;
|
||||
}
|
||||
|
||||
// ObjFW
|
||||
#[cfg(objfw)]
|
||||
mod inner {
|
||||
// Defined in ObjFW-RT.h
|
||||
// C: signed char
|
||||
// This has changed since v0.90, but we don't support that yet.
|
||||
pub(crate) type BOOL = i8;
|
||||
|
||||
// Note that ObjFW uses `bool` in return types, but that doesn't change
|
||||
// the ABI, so we'll just use `BOOL` there for ease of use.
|
||||
}
|
||||
|
||||
/// The Objective-C `BOOL` type.
|
||||
///
|
||||
/// The type of this varies across platforms, so to convert an it into a Rust
|
||||
/// [`bool`], compare it with [`NO`][crate::NO].
|
||||
///
|
||||
/// Note that this does _not_ implement `objc2::Encode` on all platforms! You
|
||||
/// should only use this on FFI boundaries, otherwise prefer
|
||||
/// `objc2::runtime::Bool`.
|
||||
///
|
||||
/// See also the [corresponding documentation entry][docs].
|
||||
///
|
||||
/// [docs]: https://developer.apple.com/documentation/objectivec/bool?language=objc
|
||||
pub type BOOL = inner::BOOL;
|
||||
|
||||
// # Why isize/usize is correct for NSInteger/NSUInteger
|
||||
//
|
||||
// ## Apple
|
||||
// The documentation clearly states:
|
||||
//
|
||||
// > When building 32-bit applications, NSInteger is a 32-bit integer. A
|
||||
// 64-bit application treats NSInteger as a 64-bit integer.
|
||||
//
|
||||
// And the header file defines them like so:
|
||||
//
|
||||
// #if __LP64__ || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
|
||||
// typedef long NSInteger;
|
||||
// typedef unsigned long NSUInteger;
|
||||
// #else
|
||||
// typedef int NSInteger;
|
||||
// typedef unsigned int NSUInteger;
|
||||
// #endif
|
||||
//
|
||||
// Rust (or at least `libc`) has no targets where c_int/c_uint are not 32-bit,
|
||||
// so that part is correct. By manual inspection it is found that the only
|
||||
// platform where c_long/c_ulong differs from isize/usize is on Windows.
|
||||
// However Apple's libraries are only designed to work on 32-bit Windows, so
|
||||
// this case should be fine as well.
|
||||
//
|
||||
// Likewise for NSUInteger.
|
||||
//
|
||||
// ## GNUStep / WinObjC
|
||||
//
|
||||
// Defined as intptr_t/uintptr_t, which is exactly the same as isize/usize.
|
||||
//
|
||||
// ## ObjFW
|
||||
//
|
||||
// Doesn't define these, but e.g. `OFString -length` returns size_t, so our
|
||||
// definitions are should be correct on effectively all targets.
|
||||
//
|
||||
// Things might change slightly in the future, see
|
||||
// <https://internals.rust-lang.org/t/pre-rfc-usize-is-not-size-t/15369>.
|
||||
|
||||
/// A signed integer value type.
|
||||
///
|
||||
/// This is guaranteed to always be a type-alias to [`isize`]. That means it
|
||||
/// is valid to use `#[repr(isize)]` on enums and structs with size
|
||||
/// `NSInteger`.
|
||||
///
|
||||
/// See also the [corresponding documentation entry][docs].
|
||||
///
|
||||
/// [docs]: https://developer.apple.com/documentation/objectivec/nsinteger?language=objc
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #[repr(isize)] // NSInteger
|
||||
/// pub enum NSComparisonResult {
|
||||
/// NSOrderedAscending = -1,
|
||||
/// NSOrderedSame = 0,
|
||||
/// NSOrderedDescending = 1,
|
||||
/// }
|
||||
/// ```
|
||||
pub type NSInteger = isize;
|
||||
|
||||
/// Describes an unsigned integer.
|
||||
///
|
||||
/// This is guaranteed to always be a type-alias to [`usize`]. That means it
|
||||
/// is valid to use `#[repr(usize)]` on enums and structs with size
|
||||
/// `NSUInteger`.
|
||||
///
|
||||
/// See also the [corresponding documentation entry][docs].
|
||||
///
|
||||
/// [docs]: https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use objc_sys::NSUInteger;
|
||||
/// // Or:
|
||||
/// // use objc2::ffi::NSUInteger;
|
||||
/// // use objc2::foundation::NSUInteger;
|
||||
/// extern "C" {
|
||||
/// fn some_external_function() -> NSUInteger;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// #[repr(usize)] // NSUInteger
|
||||
/// enum NSRoundingMode {
|
||||
/// NSRoundPlain = 0,
|
||||
/// NSRoundDown = 1,
|
||||
/// NSRoundUp = 2,
|
||||
/// NSRoundBankers = 3,
|
||||
/// };
|
||||
/// ```
|
||||
pub type NSUInteger = usize;
|
||||
|
||||
/// The maximum value for an NSInteger.
|
||||
pub const NSIntegerMax: NSInteger = NSInteger::MAX;
|
||||
|
||||
/// The minimum value for an NSInteger.
|
||||
pub const NSIntegerMin: NSInteger = NSInteger::MIN;
|
||||
|
||||
/// The maximum value for an NSUInteger.
|
||||
pub const NSUIntegerMax: NSUInteger = NSUInteger::MAX;
|
||||
|
||||
/// An immutable pointer to a selector.
|
||||
///
|
||||
/// Type alias provided for convenience. See `objc2::runtime::Sel` for a
|
||||
/// higher level binding.
|
||||
pub type SEL = *const objc_selector;
|
||||
|
||||
/// A mutable pointer to an object / instance.
|
||||
///
|
||||
/// Type alias provided for convenience. See `objc2::runtime::Object` for a
|
||||
/// higher level binding, and `objc2::rc::Id` for an easier way of handling
|
||||
/// objects.
|
||||
pub type id = *mut objc_object;
|
||||
118
third-party/vendor/objc-sys/src/various.rs
vendored
Normal file
118
third-party/vendor/objc-sys/src/various.rs
vendored
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
use core::ffi::c_void;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use std::os::raw::c_char;
|
||||
use std::os::raw::c_int;
|
||||
#[cfg(any(doc, apple))]
|
||||
use std::os::raw::c_uint;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
use crate::{objc_AssociationPolicy, BOOL};
|
||||
use crate::{objc_object, OpaqueData};
|
||||
|
||||
/// An opaque type that represents an instance variable.
|
||||
#[repr(C)]
|
||||
pub struct objc_ivar {
|
||||
_priv: [u8; 0],
|
||||
_p: OpaqueData,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "unstable-c-unwind"))]
|
||||
type InnerImp = unsafe extern "C" fn();
|
||||
#[cfg(feature = "unstable-c-unwind")]
|
||||
type InnerImp = unsafe extern "C-unwind" fn();
|
||||
|
||||
/// A nullable pointer to the start of a method implementation.
|
||||
///
|
||||
/// Not all APIs are guaranteed to take NULL values; read the docs!
|
||||
pub type IMP = Option<InnerImp>;
|
||||
|
||||
// /// Remember that this is non-null!
|
||||
// #[cfg(any(doc, apple_new))]
|
||||
// pub type objc_hook_getClass =
|
||||
// unsafe extern "C" fn(name: *const c_char, out_cls: *mut *const crate::objc_class) -> BOOL;
|
||||
//
|
||||
// /// Remember that this is non-null!
|
||||
// #[cfg(any(doc, apple_new))]
|
||||
// pub type objc_hook_lazyClassNamer =
|
||||
// unsafe extern "C" fn(cls: *const crate::objc_class) -> *const c_char;
|
||||
|
||||
extern_c_unwind! {
|
||||
// Instead of being able to change this, it's a weak symbol on GNUStep.
|
||||
#[cfg(any(doc, apple, objfw))]
|
||||
pub fn objc_enumerationMutation(obj: *mut objc_object);
|
||||
}
|
||||
|
||||
extern_c! {
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn imp_getBlock(imp: IMP) -> *mut objc_object;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn imp_implementationWithBlock(block: *mut objc_object) -> IMP;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn imp_removeBlock(imp: IMP) -> BOOL;
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn ivar_getName(ivar: *const objc_ivar) -> *const c_char;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn ivar_getOffset(ivar: *const objc_ivar) -> isize;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn ivar_getTypeEncoding(ivar: *const objc_ivar) -> *const c_char;
|
||||
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_copyClassNamesForImage(
|
||||
image: *const c_char,
|
||||
out_len: *mut c_uint,
|
||||
) -> *mut *const c_char;
|
||||
#[cfg(any(doc, apple))]
|
||||
pub fn objc_copyImageNames(out_len: *mut c_uint) -> *mut *const c_char;
|
||||
|
||||
#[cfg(any(doc, apple, objfw))]
|
||||
pub fn objc_setEnumerationMutationHandler(
|
||||
handler: Option<unsafe extern "C" fn(obj: *mut objc_object)>,
|
||||
);
|
||||
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_getAssociatedObject(
|
||||
object: *const objc_object,
|
||||
key: *const c_void,
|
||||
) -> *const objc_object;
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_setAssociatedObject(
|
||||
object: *mut objc_object,
|
||||
key: *const c_void,
|
||||
value: *mut objc_object,
|
||||
policy: objc_AssociationPolicy,
|
||||
);
|
||||
#[cfg(any(doc, not(objfw)))]
|
||||
pub fn objc_removeAssociatedObjects(object: *mut objc_object);
|
||||
|
||||
#[cfg(any(doc, apple, objfw))]
|
||||
pub fn objc_setForwardHandler(fwd: *mut c_void, fwd_stret: *mut c_void);
|
||||
// These two are defined in:
|
||||
// - Apple: objc-sync.h
|
||||
// - GNUStep: dtable.h / associate.m
|
||||
// - ObjFW: ObjFW-RT.h
|
||||
pub fn objc_sync_enter(obj: *mut objc_object) -> c_int;
|
||||
pub fn objc_sync_exit(obj: *mut objc_object) -> c_int;
|
||||
|
||||
// Available in macOS 10.14.4
|
||||
// /// Remember that this is non-null!
|
||||
// #[cfg(any(doc, apple_new))]
|
||||
// pub fn objc_setHook_getClass(
|
||||
// new_value: objc_hook_getClass,
|
||||
// out_old_value: *mut objc_hook_getClass,
|
||||
// );
|
||||
// Available in macOS 11
|
||||
// /// Remember that this is non-null!
|
||||
// #[cfg(any(doc, apple_new))]
|
||||
// pub fn objc_setHook_lazyClassNamer(
|
||||
// new_value: objc_hook_lazyClassNamer,
|
||||
// out_old_value: *mut objc_hook_lazyClassNamer,
|
||||
// );
|
||||
|
||||
// #[deprecated = "not recommended"]
|
||||
// #[cfg(any(doc, apple))]
|
||||
// pub fn _objc_flush_caches
|
||||
|
||||
// #[cfg(any(doc, gnustep))]
|
||||
// objc_test_capability
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue