From cd323c703c83d96068ea6d25b321e5588dfb90d5 Mon Sep 17 00:00:00 2001 From: LunaTheFoxgirl Date: Wed, 27 Nov 2024 02:49:08 +0100 Subject: [PATCH] add access to manual auto-release pool creation --- source/foundation/nsurl.d | 2 +- source/objc/autorelease.d | 19 +++++++++++++++++++ source/objc/rt.d | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/source/foundation/nsurl.d b/source/foundation/nsurl.d index 90158ee..7c77e0d 100644 --- a/source/foundation/nsurl.d +++ b/source/foundation/nsurl.d @@ -159,7 +159,7 @@ public: have identical URL strings and base URLs. */ extern(D) - bool opEquals(NSURL other) { + final bool opEquals(NSURL other) { return self.send!bool("isEqual:", other); } } diff --git a/source/objc/autorelease.d b/source/objc/autorelease.d index fd17cd1..7d4d37c 100644 --- a/source/objc/autorelease.d +++ b/source/objc/autorelease.d @@ -17,6 +17,7 @@ import numem.core.memory.alloc : assumeNoGC; /** Creates an auto-release pool scope with the given delegate. */ +@trusted void autoreleasepool(scope void delegate() scope_) { auto scope_fn = assumeNoGC!(typeof(scope_))(scope_); @@ -28,6 +29,24 @@ void autoreleasepool(scope void delegate() scope_) { objc_autoreleasePoolPop(ctx); } +/** + Forcefully pushes an auto-release pool onto the auto-release pool stack. +*/ +@system +arpool_ctx autoreleasepool_push() { + return arpool_ctx(objc_autoreleasePoolPush()); +} + +/** + Forcefully pops an auto-release pool from the auto-release pool stack. +*/ +@system +void autoreleasepool_pop(arpool_ctx ctx) { + return objc_autoreleasePoolPop(ctx.ctxptr); +} + +/// Opaque type for auto release pool contexts. +struct arpool_ctx { void* ctxptr; alias ctxptr this; } private: extern(C) @nogc nothrow: diff --git a/source/objc/rt.d b/source/objc/rt.d index bb20270..f7140d7 100644 --- a/source/objc/rt.d +++ b/source/objc/rt.d @@ -897,12 +897,22 @@ private { extern id objc_autorelease(id obj); extern bool objc_isUniquelyReferenced(id obj); + extern id objc_releaseAndReturn(id obj); + extern id objc_retainAutoreleaseAndReturn(id obj); + extern id objc_autoreleaseReturnValue(id obj); + // Obtaining Class Definitions extern int objc_getClassList(Class* buffer, int bufferCount); extern Class* objc_copyClassList(uint* outCount); extern Class objc_lookUpClass(const(char)* name); extern id objc_getClass(const(char)* name); extern id objc_getMetaClass(const(char)* name); + extern id objc_retainAutoreleaseReturnValue(id obj); + extern id objc_retainAutoreleasedReturnValue(id obj); + extern id objc_claimAutoreleasedReturnValue(id obj); + extern id objc_unsafeClaimAutoreleasedReturnValue(id obj); + extern id objc_retainAutorelease(id obj); + // Working with Instance Variables extern const(char)* ivar_getName(Ivar v);