feat: v1.10.9, add se supprot
This commit is contained in:
26
swift-rs/src-rs/autorelease.rs
Normal file
26
swift-rs/src-rs/autorelease.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
/// Run code with its own autorelease pool. Semantically, this is identical
|
||||
/// to [`@autoreleasepool`](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html)
|
||||
/// in Objective-C
|
||||
///
|
||||
///
|
||||
/// ```no_run
|
||||
/// use swift_rs::autoreleasepool;
|
||||
///
|
||||
/// autoreleasepool!({
|
||||
/// // do something memory intensive stuff
|
||||
/// })
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! autoreleasepool {
|
||||
( $expr:expr ) => {{
|
||||
extern "C" {
|
||||
fn objc_autoreleasePoolPush() -> *mut std::ffi::c_void;
|
||||
fn objc_autoreleasePoolPop(context: *mut std::ffi::c_void);
|
||||
}
|
||||
|
||||
let pool = unsafe { objc_autoreleasePoolPush() };
|
||||
let r = { $expr };
|
||||
unsafe { objc_autoreleasePoolPop(pool) };
|
||||
r
|
||||
}};
|
||||
}
|
||||
Reference in New Issue
Block a user