Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
76
third-party/vendor/objc2/tests/id_retain_autoreleased.rs
vendored
Normal file
76
third-party/vendor/objc2/tests/id_retain_autoreleased.rs
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
use std::ffi::c_void;
|
||||
|
||||
use objc2::rc::{autoreleasepool, Id, Shared};
|
||||
use objc2::runtime::Object;
|
||||
use objc2::{class, msg_send};
|
||||
|
||||
#[cfg(feature = "gnustep-1-7")]
|
||||
#[test]
|
||||
fn ensure_linkage() {
|
||||
unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
|
||||
}
|
||||
|
||||
fn retain_count(obj: &Object) -> usize {
|
||||
unsafe { msg_send![obj, retainCount] }
|
||||
}
|
||||
|
||||
fn create_data(bytes: &[u8]) -> Id<Object, Shared> {
|
||||
let bytes_ptr: *const c_void = bytes.as_ptr().cast();
|
||||
unsafe {
|
||||
// let obj: *mut Object = msg_send![
|
||||
// class!(NSMutableData),
|
||||
// dataWithBytes: bytes_ptr,
|
||||
// length: bytes.len(),
|
||||
// ];
|
||||
//
|
||||
// On x86 (and perhaps others), dataWithBytes does not tail call
|
||||
// `autorelease` and hence the return address points into that instead
|
||||
// of our code, making the fast autorelease scheme fail.
|
||||
//
|
||||
// So instead, we call `autorelease` manually here.
|
||||
let obj: *mut Object = msg_send![class!(NSMutableData), alloc];
|
||||
let obj: *mut Object = msg_send![
|
||||
obj,
|
||||
initWithBytes: bytes_ptr,
|
||||
length: bytes.len(),
|
||||
];
|
||||
let obj: *mut Object = msg_send![obj, autorelease];
|
||||
// All code between the `msg_send!` and the `retain_autoreleased` must
|
||||
// be able to be optimized away for this to work.
|
||||
Id::retain_autoreleased(obj).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_retain_autoreleased() {
|
||||
autoreleasepool(|_| {
|
||||
// Run once to allow DYLD to resolve the symbol stubs.
|
||||
// Required for making `retain_autoreleased` work on x86_64.
|
||||
let _data = create_data(b"12");
|
||||
|
||||
// When compiled in release mode / with optimizations enabled,
|
||||
// subsequent usage of `retain_autoreleased` will succeed in retaining
|
||||
// the autoreleased value!
|
||||
let expected = if cfg!(feature = "gnustep-1-7") {
|
||||
1
|
||||
} else if cfg!(any(
|
||||
debug_assertions,
|
||||
feature = "exception",
|
||||
feature = "verify_message"
|
||||
)) {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
let data = create_data(b"34");
|
||||
assert_eq!(retain_count(&data), expected);
|
||||
|
||||
let data = create_data(b"56");
|
||||
assert_eq!(retain_count(&data), expected);
|
||||
|
||||
// Here we manually clean up the autorelease, so it will always be 1.
|
||||
let data = autoreleasepool(|_| create_data(b"78"));
|
||||
assert_eq!(retain_count(&data), 1);
|
||||
});
|
||||
}
|
||||
116
third-party/vendor/objc2/tests/no_prelude.rs
vendored
Normal file
116
third-party/vendor/objc2/tests/no_prelude.rs
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//! Tests macros in a hostile environment (`#![no_implicit_prelude]` and all
|
||||
//! functions, modules, traits, and types replaced with custom bogus user
|
||||
//! replacements).
|
||||
//!
|
||||
//! Heavy inspiration for this file taken from `objrs`:
|
||||
//! https://gitlab.com/objrs/objrs/-/blob/b4f6598696b3fa622e6fddce7aff281770b0a8c2/test/src/no_prelude.rs
|
||||
#![no_implicit_prelude]
|
||||
#![allow(dead_code, non_camel_case_types)]
|
||||
|
||||
extern crate objc2 as new_objc2;
|
||||
|
||||
#[cfg(feature = "gnustep-1-7")]
|
||||
#[test]
|
||||
fn ensure_linkage() {
|
||||
unsafe { new_objc2::__gnustep_hack::get_class_to_force_linkage() };
|
||||
}
|
||||
|
||||
mod core {}
|
||||
mod std {}
|
||||
mod libc {}
|
||||
mod objc2 {}
|
||||
|
||||
enum BogusType {}
|
||||
type u8 = BogusType;
|
||||
type u16 = BogusType;
|
||||
type u32 = BogusType;
|
||||
type u64 = BogusType;
|
||||
type u128 = BogusType;
|
||||
type usize = BogusType;
|
||||
|
||||
type i8 = BogusType;
|
||||
type i16 = BogusType;
|
||||
type i32 = BogusType;
|
||||
type i64 = BogusType;
|
||||
type i128 = BogusType;
|
||||
type isize = BogusType;
|
||||
|
||||
type bool = BogusType;
|
||||
type char = BogusType;
|
||||
type str = BogusType;
|
||||
|
||||
type f32 = BogusType;
|
||||
type f64 = BogusType;
|
||||
|
||||
type Option = BogusType;
|
||||
type Some = BogusType;
|
||||
type None = BogusType;
|
||||
|
||||
type Result = BogusType;
|
||||
type Ok = BogusType;
|
||||
type Err = BogusType;
|
||||
|
||||
type Box = BogusType;
|
||||
type String = BogusType;
|
||||
type Vec = BogusType;
|
||||
|
||||
type drop = BogusType;
|
||||
|
||||
type Copy = BogusType;
|
||||
type Send = BogusType;
|
||||
type Sized = BogusType;
|
||||
type Sync = BogusType;
|
||||
type Drop = BogusType;
|
||||
type Fn = BogusType;
|
||||
type FnMut = BogusType;
|
||||
type FnOnce = BogusType;
|
||||
|
||||
type ToOwned = BogusType;
|
||||
type Clone = BogusType;
|
||||
type PartialEq = BogusType;
|
||||
type PartialOrd = BogusType;
|
||||
type Eq = BogusType;
|
||||
type Ord = BogusType;
|
||||
type AsRef = BogusType;
|
||||
type AsMut = BogusType;
|
||||
type Into = BogusType;
|
||||
type From = BogusType;
|
||||
type Default = BogusType;
|
||||
type Hash = BogusType;
|
||||
type Debug = BogusType;
|
||||
type Iterator = BogusType;
|
||||
type Extend = BogusType;
|
||||
type IntoIterator = BogusType;
|
||||
type DoubleEndedIterator = BogusType;
|
||||
type ExactSizeIterator = BogusType;
|
||||
type SliceConcatExt = BogusType;
|
||||
type ToString = BogusType;
|
||||
|
||||
pub fn test_selector() {
|
||||
let _sel = new_objc2::sel!(abc);
|
||||
let _sel = new_objc2::sel!(abc:def:);
|
||||
}
|
||||
|
||||
pub fn test_class() {
|
||||
let _class = new_objc2::class!(NSObject);
|
||||
}
|
||||
|
||||
pub fn test_msg_send(obj: &new_objc2::foundation::NSString) {
|
||||
let superclass = obj.class().superclass().unwrap();
|
||||
let _: () = unsafe { new_objc2::msg_send![obj, a] };
|
||||
let _: () = unsafe { new_objc2::msg_send![obj, a: obj, b: obj] };
|
||||
let _: () = unsafe { new_objc2::msg_send![super(obj), a] };
|
||||
let _: () = unsafe { new_objc2::msg_send![super(obj), a: obj, b: obj] };
|
||||
let _: () = unsafe { new_objc2::msg_send![super(obj, superclass), a] };
|
||||
let _: () = unsafe { new_objc2::msg_send![super(obj, superclass), a: obj, b: obj] };
|
||||
}
|
||||
|
||||
pub fn test_msg_send_id(obj: &new_objc2::runtime::Object) {
|
||||
let _: new_objc2::rc::Id<new_objc2::runtime::Object, new_objc2::rc::Shared> =
|
||||
unsafe { new_objc2::msg_send_id![obj, a] };
|
||||
let _: new_objc2::__macro_helpers::Option<
|
||||
new_objc2::rc::Id<new_objc2::runtime::Object, new_objc2::rc::Shared>,
|
||||
> = unsafe { new_objc2::msg_send_id![obj, a] };
|
||||
let _: new_objc2::rc::Id<new_objc2::runtime::Object, new_objc2::rc::Shared> =
|
||||
unsafe { new_objc2::msg_send_id![obj, a: obj, b: obj] };
|
||||
}
|
||||
59
third-party/vendor/objc2/tests/use_macros.rs
vendored
Normal file
59
third-party/vendor/objc2/tests/use_macros.rs
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use objc2::foundation::NSString;
|
||||
use objc2::runtime::{Class, Object};
|
||||
use objc2::{class, msg_send, sel};
|
||||
|
||||
#[cfg(feature = "gnustep-1-7")]
|
||||
#[test]
|
||||
fn ensure_linkage() {
|
||||
unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_class_and_msg_send() {
|
||||
unsafe {
|
||||
let cls = class!(NSObject);
|
||||
let obj: *mut Object = msg_send![cls, new];
|
||||
let _hash: usize = msg_send![obj, hash];
|
||||
let _: () = msg_send![obj, release];
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_sel() {
|
||||
let _sel = sel!(description);
|
||||
let _sel = sel!(setObject:forKey:);
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn test_msg_send_comma_handling(obj: &NSString, superclass: &Class) {
|
||||
unsafe {
|
||||
let _: () = msg_send![obj, a];
|
||||
let _: () = msg_send![obj, a,];
|
||||
let _: () = msg_send![obj, a: 32i32];
|
||||
let _: () = msg_send![obj, a: 32i32,];
|
||||
let _: () = msg_send![obj, a: 32i32 b: 32i32];
|
||||
let _: () = msg_send![obj, a: 32i32 b: 32i32,];
|
||||
let _: () = msg_send![obj, a: 32i32, b: 32i32];
|
||||
let _: () = msg_send![obj, a: 32i32, b: 32i32,];
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let _: () = msg_send![super(obj, superclass), a];
|
||||
let _: () = msg_send![super(obj, superclass), a,];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32,];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32 b: 32i32];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32 b: 32i32,];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32, b: 32i32];
|
||||
let _: () = msg_send![super(obj, superclass), a: 32i32, b: 32i32,];
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let _: () = msg_send![super(obj), a];
|
||||
let _: () = msg_send![super(obj), a,];
|
||||
let _: () = msg_send![super(obj), a: 32i32];
|
||||
let _: () = msg_send![super(obj), a: 32i32,];
|
||||
let _: () = msg_send![super(obj), a: 32i32, b: 32i32];
|
||||
let _: () = msg_send![super(obj), a: 32i32, b: 32i32,];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue