diff --git a/pkg/objc/autorelease.zig b/pkg/objc/autorelease.zig new file mode 100644 index 000000000..18adf1433 --- /dev/null +++ b/pkg/objc/autorelease.zig @@ -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; diff --git a/pkg/objc/main.zig b/pkg/objc/main.zig index 9d1da6847..fe18b06ed 100644 --- a/pkg/objc/main.zig +++ b/pkg/objc/main.zig @@ -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");