pkg/objc: autorelease pools

This commit is contained in:
Mitchell Hashimoto
2022-11-14 09:59:09 -08:00
parent b4eef60380
commit 69b91a951b
2 changed files with 17 additions and 0 deletions

16
pkg/objc/autorelease.zig Normal file
View File

@ -0,0 +1,16 @@
const std = @import("std");
pub const AutoreleasePool = opaque {
pub inline fn init() *AutoreleasePool {
return @ptrCast(*AutoreleasePool, objc_autoreleasePoolPush().?);
}
pub inline fn deinit(self: *AutoreleasePool) void {
objc_autoreleasePoolPop(self);
}
};
// I'm not sure if these are internal or not... they aren't in any headers,
// but its how autorelease pools are implemented.
extern "c" fn objc_autoreleasePoolPush() ?*anyopaque;
extern "c" fn objc_autoreleasePoolPop(?*anyopaque) void;

View File

@ -1,6 +1,7 @@
const std = @import("std");
pub const c = @import("c.zig");
pub usingnamespace @import("autorelease.zig");
pub usingnamespace @import("class.zig");
pub usingnamespace @import("object.zig");
pub usingnamespace @import("property.zig");