From e5c2cedd49c612ad5a0940baa54e9f88d55b5d5e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 30 Apr 2021 20:29:48 +0100 Subject: [PATCH] Rename LSUUID and checkLuaSkinInstance to variations of 'GCCanary' --- LuaSkin/LuaSkin/Skin.h | 10 ++++----- LuaSkin/LuaSkin/Skin.m | 26 +++++++++++----------- extensions/audiodevice/internal.m | 8 +++---- extensions/battery/watcher.m | 8 +++---- extensions/caffeinate/watcher.m | 8 +++---- extensions/eventtap/internal.m | 8 +++---- extensions/hotkey/internal.m | 8 +++---- extensions/network/configurationinternal.m | 8 +++---- extensions/network/hostinternal.m | 8 +++---- extensions/network/reachabilityinternal.m | 8 +++---- extensions/pathwatcher/internal.m | 8 +++---- extensions/serial/internal.m | 26 +++++++++++----------- extensions/timer/internal.m | 12 +++++----- extensions/usb/watcher.m | 8 +++---- extensions/webview/internal.m | 20 ++++++++--------- extensions/webview/webview.h | 2 +- 16 files changed, 88 insertions(+), 88 deletions(-) diff --git a/LuaSkin/LuaSkin/Skin.h b/LuaSkin/LuaSkin/Skin.h index 4d43c34fd..a40fa8102 100644 --- a/LuaSkin/LuaSkin/Skin.h +++ b/LuaSkin/LuaSkin/Skin.h @@ -50,9 +50,9 @@ extern int luaopen_luaskin_internal(lua_State* L) ; // entry vector to luaskin.m typedef int LSRefTable; #define LSUUIDLen 37 -typedef struct LSUUID { +typedef struct LSGCCanary { char uuid[LSUUIDLen]; -} LSUUID; +} LSGCCanary; // Define some bits for masking operations in the argument checker /*! @@ -283,9 +283,9 @@ NSString *specMaskToString(int spec); */ - (void)resetLuaState; -- (BOOL)checkLuaSkinInstance:(LSUUID)lsUUID; -- (LSUUID)getLuaSkinUUID; -- (void)gcLuaSkinUUID:(LSUUID *)lsUUID; +- (BOOL)checkGCCanary:(LSGCCanary)canary; +- (LSGCCanary)createGCCanary; +- (void)destroyGCCanary:(LSGCCanary *)canary; #pragma mark - Methods for calling into Lua from C diff --git a/LuaSkin/LuaSkin/Skin.m b/LuaSkin/LuaSkin/Skin.m index 079ba0928..a7e8c73e1 100644 --- a/LuaSkin/LuaSkin/Skin.m +++ b/LuaSkin/LuaSkin/Skin.m @@ -333,37 +333,37 @@ - (void)resetLuaState { [self createLuaState]; } -- (BOOL)checkLuaSkinInstance:(LSUUID)lsUUID { +- (BOOL)checkGCCanary:(LSGCCanary)canary { if (!self.L) { [self logBreadcrumb:@"LuaSkin nil lua_State detected"]; return NO; } - NSString *NSlsUUID = [NSString stringWithCString:lsUUID.uuid encoding:NSUTF8StringEncoding]; - if (!NSlsUUID || ![self.uuid.UUIDString isEqualToString:NSlsUUID]) { - [self logKnownBug:[NSString stringWithFormat:@"LuaSkin UUID mismatch detected: %s from the callback, %@ from the current LuaSkin instance", lsUUID.uuid, self.uuid.UUIDString]]; + NSString *NSlsCanary = [NSString stringWithCString:canary.uuid encoding:NSUTF8StringEncoding]; + if (!NSlsCanary || ![self.uuid.UUIDString isEqualToString:NSlsCanary]) { + [self logWarn:@"LuaSkin has caught an attempt to operate on an object that has been garbage collected."]; return NO; } return YES; } -- (LSUUID)getLuaSkinUUID { - LSUUID lsUUID; - memset(lsUUID.uuid, 0, LSUUIDLen); - strncpy(lsUUID.uuid, "UNINITIALISED", 13); +- (LSGCCanary)createGCCanary { + LSGCCanary canary; + memset(canary.uuid, 0, LSUUIDLen); + strncpy(canary.uuid, "UNINITIALISED", 13); const char *tmpUUID = [self.uuid.UUIDString cStringUsingEncoding:NSUTF8StringEncoding]; if (tmpUUID) { - strncpy(lsUUID.uuid, tmpUUID, LSUUIDLen); + strncpy(canary.uuid, tmpUUID, LSUUIDLen); } - return lsUUID; + return canary; } -- (void)gcLuaSkinUUID:(LSUUID *)lsUUID { - memset(lsUUID->uuid, 0, LSUUIDLen); - strncpy(lsUUID->uuid, "GC", 2); +- (void)destroyGCCanary:(LSGCCanary *)canary { + memset(canary->uuid, 0, LSUUIDLen); + strncpy(canary->uuid, "GC", 2); } #pragma mark - Methods for calling into Lua from C diff --git a/extensions/audiodevice/internal.m b/extensions/audiodevice/internal.m index 022de86a2..81bc3201c 100644 --- a/extensions/audiodevice/internal.m +++ b/extensions/audiodevice/internal.m @@ -19,7 +19,7 @@ AudioDeviceID deviceId; int callback; BOOL watcherRunning; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } audioDeviceUserData; // Define a datatype for hs.audiodevice.datasource objects @@ -82,7 +82,7 @@ OSStatus audiodevice_callback(AudioDeviceID deviceID, UInt32 numAddresses, const audioDeviceUserData *userData = (audioDeviceUserData *)clientData; LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:userData->luaSkinUUID]) { + if (![skin checkGCCanary:userData->lsCanary]) { return; } @@ -145,7 +145,7 @@ void new_device(lua_State* L, AudioDeviceID deviceId) { audioDevice->watcherRunning = NO; LuaSkin *skin = [LuaSkin sharedWithState:L]; - audioDevice->luaSkinUUID = [skin getLuaSkinUUID]; + audioDevice->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG); lua_setmetatable(L, -2); @@ -1711,7 +1711,7 @@ static int audiodevice_gc(lua_State* L) { audiodevice_watcherStop(L); audioDevice->callback = [skin luaUnref:refTable ref:audioDevice->callback]; - [skin gcLuaSkinUUID:&(audioDevice->luaSkinUUID)]; + [skin destroyGCCanary:&(audioDevice->lsCanary)]; return 0; } diff --git a/extensions/battery/watcher.m b/extensions/battery/watcher.m index d674e356a..44f5e2190 100644 --- a/extensions/battery/watcher.m +++ b/extensions/battery/watcher.m @@ -21,7 +21,7 @@ CFRunLoopSourceRef t; int fn; bool started; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } battery_watcher_t; static void callback(void *info) { @@ -29,7 +29,7 @@ static void callback(void *info) { battery_watcher_t* t = info; - if (![skin checkLuaSkinInstance:t->luaSkinUUID]) { + if (![skin checkGCCanary:t->lsCanary]) { return; } @@ -69,7 +69,7 @@ static int battery_watcher_new(lua_State* L) { watcher->t = IOPSNotificationCreateRunLoopSource(callback, watcher); watcher->started = false; - watcher->luaSkinUUID = [skin getLuaSkinUUID]; + watcher->lsCanary = [skin createGCCanary]; return 1; } @@ -123,7 +123,7 @@ static int battery_watcher_gc(lua_State* L) { lua_pushcfunction(L, battery_watcher_stop) ; lua_pushvalue(L,1); lua_call(L, 1, 1); watcher->fn = [skin luaUnref:refTable ref:watcher->fn]; - [skin gcLuaSkinUUID:&(watcher->luaSkinUUID)]; + [skin destroyGCCanary:&(watcher->lsCanary)]; CFRunLoopSourceInvalidate(watcher->t); CFRelease(watcher->t); return 0; diff --git a/extensions/caffeinate/watcher.m b/extensions/caffeinate/watcher.m index 920b0049b..b517064a7 100644 --- a/extensions/caffeinate/watcher.m +++ b/extensions/caffeinate/watcher.m @@ -70,7 +70,7 @@ bool running; int fn; void* obj; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } caffeinatewatcher_t; typedef enum _event_t { @@ -105,7 +105,7 @@ - (id)initWithObject:(caffeinatewatcher_t*)object { - (void)callback:(NSDictionary* __unused)dict withEvent:(event_t)event { if (self.object->fn != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - [skin checkLuaSkinInstance:self.object->luaSkinUUID]; + [skin checkGCCanary:self.object->lsCanary]; lua_State *L = skin.L; _lua_stackguard_entry(L); @@ -188,7 +188,7 @@ static int caffeinate_watcher_new(lua_State* L) { caffeinateWatcher->fn = [skin luaRef:refTable]; caffeinateWatcher->running = NO; caffeinateWatcher->obj = (__bridge_retained void*) [[CaffeinateWatcher alloc] initWithObject:caffeinateWatcher]; - caffeinateWatcher->luaSkinUUID = [skin getLuaSkinUUID]; + caffeinateWatcher->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG); lua_setmetatable(L, -2); @@ -331,7 +331,7 @@ static int caffeinate_watcher_gc(lua_State* L) { caffeinate_watcher_stop(L); caffeinateWatcher->fn = [skin luaUnref:refTable ref:caffeinateWatcher->fn]; - [skin gcLuaSkinUUID:&(caffeinateWatcher->luaSkinUUID)]; + [skin destroyGCCanary:&(caffeinateWatcher->lsCanary)]; CaffeinateWatcher* object = (__bridge_transfer CaffeinateWatcher*)caffeinateWatcher->obj; object = nil; diff --git a/extensions/eventtap/internal.m b/extensions/eventtap/internal.m index 828b17136..5b572be3f 100644 --- a/extensions/eventtap/internal.m +++ b/extensions/eventtap/internal.m @@ -9,7 +9,7 @@ CGEventMask mask; CFMachPortRef tap; CFRunLoopSourceRef runloopsrc; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } eventtap_t; CGEventRef eventtap_callback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { @@ -19,7 +19,7 @@ CGEventRef eventtap_callback(CGEventTapProxy proxy, CGEventType type, CGEventRef eventtap_t* e = refcon; // Guard against this callback being delivered at a point where LuaSkin has been reset and our references wouldn't make sense anymore - if (![skin checkLuaSkinInstance:e->luaSkinUUID]) { + if (![skin checkGCCanary:e->lsCanary]) { return event; // Allow the event to pass through unmodified } @@ -166,7 +166,7 @@ static int eventtap_new(lua_State* L) { memset(eventtap, 0, sizeof(eventtap_t)); eventtap->tap = NULL ; - eventtap->luaSkinUUID = [skin getLuaSkinUUID]; + eventtap->lsCanary = [skin createGCCanary]; lua_pushnil(L); while (lua_next(L, 1) != 0) { @@ -447,7 +447,7 @@ static int eventtap_gc(lua_State* L) { } eventtap->fn = [skin luaUnref:refTable ref:eventtap->fn]; - [skin gcLuaSkinUUID:&(eventtap->luaSkinUUID)]; + [skin destroyGCCanary:&(eventtap->lsCanary)]; return 0; } diff --git a/extensions/hotkey/internal.m b/extensions/hotkey/internal.m index 8fc875c3c..734226c29 100644 --- a/extensions/hotkey/internal.m +++ b/extensions/hotkey/internal.m @@ -99,7 +99,7 @@ static int remove_hotkey(lua_State* L, int x) { int repeatfn; BOOL enabled; EventHotKeyRef carbonHotKey; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } hotkey_t; @@ -135,7 +135,7 @@ static int hotkey_new(lua_State* L) { hotkey_t* hotkey = lua_newuserdata(L, sizeof(hotkey_t)); memset(hotkey, 0, sizeof(hotkey_t)); - hotkey->luaSkinUUID = [skin getLuaSkinUUID]; + hotkey->lsCanary = [skin createGCCanary]; hotkey->carbonHotKey = nil; hotkey->keycode = keycode; @@ -308,7 +308,7 @@ static int hotkey_gc(lua_State* L) { hotkey->pressedfn = [skin luaUnref:refTable ref:hotkey->pressedfn]; hotkey->releasedfn = [skin luaUnref:refTable ref:hotkey->releasedfn]; hotkey->repeatfn = [skin luaUnref:refTable ref:hotkey->repeatfn]; - [skin gcLuaSkinUUID:&(hotkey->luaSkinUUID)]; + [skin destroyGCCanary:&(hotkey->lsCanary)]; return 0; } @@ -343,7 +343,7 @@ static OSStatus trigger_hotkey_callback(int eventUID, int eventKind, BOOL isRepe hotkey_t* hotkey = push_hotkey(L, eventUID); lua_pop(L, 1); - if (![skin checkLuaSkinInstance:hotkey->luaSkinUUID]) { + if (![skin checkGCCanary:hotkey->lsCanary]) { return noErr; } diff --git a/extensions/network/configurationinternal.m b/extensions/network/configurationinternal.m index 979fc76c8..66e059ff9 100644 --- a/extensions/network/configurationinternal.m +++ b/extensions/network/configurationinternal.m @@ -16,7 +16,7 @@ int callbackRef ; int selfRef ; BOOL watcherEnabled ; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } dynamicstore_t; static void doDynamicStoreCallback(__unused SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) { @@ -26,7 +26,7 @@ static void doDynamicStoreCallback(__unused SCDynamicStoreRef store, CFArrayRef if ((thePtr->callbackRef != LUA_NOREF) && (thePtr->selfRef != LUA_NOREF)) { LuaSkin *skin = [LuaSkin sharedWithState:NULL] ; lua_State *L = [skin L] ; - if (![skin checkLuaSkinInstance:thePtr->luaSkinUUID]) { + if (![skin checkGCCanary:thePtr->lsCanary]) { return; } _lua_stackguard_entry(L); @@ -69,7 +69,7 @@ static int newStoreObject(lua_State *L) { thePtr->callbackRef = LUA_NOREF ; thePtr->selfRef = LUA_NOREF ; thePtr->watcherEnabled = NO ; - thePtr->luaSkinUUID = [skin getLuaSkinUUID]; + thePtr->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG) ; lua_setmetatable(L, -2) ; @@ -654,7 +654,7 @@ static int userdata_gc(lua_State* L) { } } thePtr->selfRef = [skin luaUnref:refTable ref:thePtr->selfRef] ; - [skin gcLuaSkinUUID:&(thePtr->luaSkinUUID)]; + [skin destroyGCCanary:&(thePtr->lsCanary)]; CFRelease(thePtr->storeObject) ; lua_pushnil(L) ; diff --git a/extensions/network/hostinternal.m b/extensions/network/hostinternal.m index b9b8a2466..8423774bc 100644 --- a/extensions/network/hostinternal.m +++ b/extensions/network/hostinternal.m @@ -19,7 +19,7 @@ CFHostInfoType resolveType ; int selfRef ; BOOL running ; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } hshost_t; static int pushCFHost(lua_State *L, CFHostRef theHost, CFHostInfoType resolveType) { @@ -38,7 +38,7 @@ static int pushCFHost(lua_State *L, CFHostRef theHost, CFHostInfoType resolveTyp thePtr->resolveType = resolveType ; thePtr->selfRef = LUA_NOREF ; thePtr->running = NO ; - thePtr->luaSkinUUID = [skin getLuaSkinUUID]; + thePtr->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG) ; lua_setmetatable(L, -2) ; @@ -151,7 +151,7 @@ void handleCallback(__unused CFHostRef theHost, __unused CFHostInfoType typeInfo LuaSkin *skin = [LuaSkin sharedWithState:NULL] ; if (theRef->callbackRef != LUA_NOREF) { lua_State *L = [skin L] ; - if (![skin checkLuaSkinInstance:theRef->luaSkinUUID]) { + if (![skin checkGCCanary:theRef->lsCanary]) { return; } _lua_stackguard_entry(L); @@ -421,7 +421,7 @@ static int userdata_gc(lua_State* L) { theRef->callbackRef = [skin luaUnref:refTable ref:theRef->callbackRef] ; // in case __gc forced by reload theRef->selfRef = [skin luaUnref:refTable ref:theRef->selfRef] ; - [skin gcLuaSkinUUID:&(theRef->luaSkinUUID)]; + [skin destroyGCCanary:&(theRef->lsCanary)]; lua_pushcfunction(L, cancelResolution) ; lua_pushvalue(L, 1) ; diff --git a/extensions/network/reachabilityinternal.m b/extensions/network/reachabilityinternal.m index 1e03bbceb..f1c8ff3e9 100644 --- a/extensions/network/reachabilityinternal.m +++ b/extensions/network/reachabilityinternal.m @@ -19,7 +19,7 @@ int callbackRef ; int selfRef ; BOOL watcherEnabled ; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } reachability_t; static int pushSCNetworkReachability(lua_State *L, SCNetworkReachabilityRef theRef) { @@ -31,7 +31,7 @@ static int pushSCNetworkReachability(lua_State *L, SCNetworkReachabilityRef theR thePtr->callbackRef = LUA_NOREF ; thePtr->selfRef = LUA_NOREF ; thePtr->watcherEnabled = NO ; - thePtr->luaSkinUUID = [skin getLuaSkinUUID]; + thePtr->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG) ; lua_setmetatable(L, -2) ; @@ -44,7 +44,7 @@ static void doReachabilityCallback(__unused SCNetworkReachabilityRef target, SCN if ((theRef->callbackRef != LUA_NOREF) && (theRef->selfRef != LUA_NOREF)) { LuaSkin *skin = [LuaSkin sharedWithState:NULL] ; lua_State *L = [skin L] ; - if (![skin checkLuaSkinInstance:theRef->luaSkinUUID]) { + if (![skin checkGCCanary:theRef->lsCanary]) { return; } _lua_stackguard_entry(L); @@ -386,7 +386,7 @@ static int userdata_gc(lua_State* L) { SCNetworkReachabilitySetDispatchQueue(theRef->reachabilityObj, NULL); } theRef->selfRef = [skin luaUnref:refTable ref:theRef->selfRef] ; - [skin gcLuaSkinUUID:&(theRef->luaSkinUUID)]; + [skin destroyGCCanary:&(theRef->lsCanary)]; CFRelease(theRef->reachabilityObj) ; lua_pushnil(L) ; diff --git a/extensions/pathwatcher/internal.m b/extensions/pathwatcher/internal.m index 57131d7fe..2d64fba3d 100644 --- a/extensions/pathwatcher/internal.m +++ b/extensions/pathwatcher/internal.m @@ -12,7 +12,7 @@ int closureref; FSEventStreamRef stream; bool started; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } watcher_path_t; #if MAC_OS_X_VERSION_MAX_ALLOWED < 1090 @@ -55,7 +55,7 @@ void event_callback(ConstFSEventStreamRef __unused streamRef, void *clientCallBa LuaSkin *skin = [LuaSkin sharedWithState:NULL]; lua_State *L = skin.L; - if (![skin checkLuaSkinInstance:pw->luaSkinUUID]) { + if (![skin checkGCCanary:pw->lsCanary]) { return; } @@ -125,7 +125,7 @@ static int watcher_path_new(lua_State* L) { watcher_path_t* watcher_path = lua_newuserdata(L, sizeof(watcher_path_t)); watcher_path->started = NO; - watcher_path->luaSkinUUID = [skin getLuaSkinUUID]; + watcher_path->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG); lua_setmetatable(L, -2); @@ -205,7 +205,7 @@ static int watcher_path_gc(lua_State* L) { FSEventStreamRelease(watcher_path->stream); watcher_path->closureref = [skin luaUnref:refTable ref:watcher_path->closureref]; - [skin gcLuaSkinUUID:&(watcher_path->luaSkinUUID)]; + [skin destroyGCCanary:&(watcher_path->lsCanary)]; return 0; } diff --git a/extensions/serial/internal.m b/extensions/serial/internal.m index e806cec26..2f128e036 100755 --- a/extensions/serial/internal.m +++ b/extensions/serial/internal.m @@ -49,7 +49,7 @@ @interface HSSerialPort : NSObject @property NSString* portName; @property NSString* portPath; -@property LSUUID luaSkinUUID; +@property LSGCCanary lsCanary; @property ORSSerialPortParity parity; @property NSNumber* baudRate; @@ -130,7 +130,7 @@ - (void)serialPortWasOpened:(ORSSerialPort *)serialPort if (_callbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -148,7 +148,7 @@ - (void)serialPortWasClosed:(ORSSerialPort *)serialPort if (_callbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -166,7 +166,7 @@ - (void)serialPort:(ORSSerialPort *)serialPort didReceiveData:(NSData *)data if (_callbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -192,7 +192,7 @@ - (void)serialPortWasRemovedFromSystem:(ORSSerialPort *)serialPort; if (_callbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -214,7 +214,7 @@ - (void)serialPort:(ORSSerialPort *)serialPort didEncounterError:(NSError *)erro NSString *errorString = [NSString stringWithFormat:@"%@", error]; LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -235,7 +235,7 @@ - (void)serialPortsWereConnected:(NSNotification *)notification if (_deviceCallbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -262,7 +262,7 @@ - (void)serialPortsWereDisconnected:(NSNotification *)notification if (_deviceCallbackRef != LUA_NOREF) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -474,7 +474,7 @@ static int serial_newFromName(lua_State *L) { HSSerialPort *serialPort = [[HSSerialPort alloc] init]; - serialPort.luaSkinUUID = [skin getLuaSkinUUID]; + serialPort.lsCanary = [skin createGCCanary]; bool result = [serialPort isPortNameValid:portName]; @@ -507,7 +507,7 @@ static int serial_newFromPath(lua_State *L) { HSSerialPort *serialPort = [[HSSerialPort alloc] init]; - serialPort.luaSkinUUID = [skin getLuaSkinUUID]; + serialPort.lsCanary = [skin createGCCanary]; bool result = [serialPort isPathValid:path]; @@ -1100,9 +1100,9 @@ static int userdata_gc(lua_State* L) { } obj = nil; - LSUUID tmpluaSkinUUID = obj.luaSkinUUID; - [skin gcLuaSkinUUID:&tmpluaSkinUUID]; - obj.luaSkinUUID = tmpluaSkinUUID; + LSGCCanary tmplsCanary = obj.lsCanary; + [skin destroyGCCanary:&tmplsCanary]; + obj.lsCanary = tmplsCanary; } } diff --git a/extensions/timer/internal.m b/extensions/timer/internal.m index c663b631d..7437412f6 100644 --- a/extensions/timer/internal.m +++ b/extensions/timer/internal.m @@ -17,7 +17,7 @@ @interface HSTimer : NSObject @property BOOL continueOnError; @property BOOL repeats; @property NSTimeInterval interval; -@property LSUUID luaSkinUUID; +@property LSGCCanary lsCanary; - (void)create:(NSTimeInterval)interval repeat:(BOOL)repeat; - (void)callback:(NSTimer *)timer; @@ -37,7 +37,7 @@ - (void)create:(NSTimeInterval)interval repeat:(BOOL)repeat { - (void)callback:(NSTimer *)timer { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } @@ -119,7 +119,7 @@ - (void)trigger { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; // NOTE: The stringWithString call here is vital, so we get a true copy of UUIDString - we must not simply point at it, or we'll never be able to use it to detect an inconsistency later. - timer.luaSkinUUID = [skin getLuaSkinUUID]; + timer.lsCanary = [skin createGCCanary]; return timer; } @@ -384,9 +384,9 @@ static int timer_gc(lua_State* L) { timer.fnRef = [skin luaUnref:refTable ref:timer.fnRef]; timer.t = nil; - LSUUID tmpLSUUID = timer.luaSkinUUID; - [skin gcLuaSkinUUID:&tmpLSUUID]; - timer.luaSkinUUID = tmpLSUUID; + LSGCCanary tmpLSUUID = timer.lsCanary; + [skin destroyGCCanary:&tmpLSUUID]; + timer.lsCanary = tmpLSUUID; timer = nil; } diff --git a/extensions/usb/watcher.m b/extensions/usb/watcher.m index 4130a5029..bde758090 100644 --- a/extensions/usb/watcher.m +++ b/extensions/usb/watcher.m @@ -25,7 +25,7 @@ IONotificationPortRef gNotifyPort; io_iterator_t gAddedIter; CFRunLoopSourceRef runLoopSource; - LSUUID luaSkinUUID; + LSGCCanary lsCanary; } usbwatcher_t; // private data for each USB device @@ -46,7 +46,7 @@ void DeviceNotification(void *refCon, io_service_t service __unused, natural_t m if (messageType == kIOMessageServiceIsTerminated) { LuaSkin *skin = [LuaSkin sharedWithState:NULL]; lua_State *L = skin.L; - if (![skin checkLuaSkinInstance:watcher->luaSkinUUID]) { + if (![skin checkGCCanary:watcher->lsCanary]) { return; } _lua_stackguard_entry(L); @@ -201,7 +201,7 @@ static int usb_watcher_new(lua_State* L) { usbwatcher->running = NO; usbwatcher->gNotifyPort = IONotificationPortCreate(kIOMasterPortDefault); usbwatcher->runLoopSource = IONotificationPortGetRunLoopSource(usbwatcher->gNotifyPort); - usbwatcher->luaSkinUUID = [skin getLuaSkinUUID]; + usbwatcher->lsCanary = [skin createGCCanary]; luaL_getmetatable(L, USERDATA_TAG); lua_setmetatable(L, -2); @@ -278,7 +278,7 @@ static int usb_watcher_gc(lua_State* L) { lua_pushcfunction(L, usb_watcher_stop) ; lua_pushvalue(L,1); lua_call(L, 1, 1); usbwatcher->fn = [skin luaUnref:refTable ref:usbwatcher->fn]; - [skin gcLuaSkinUUID:&(usbwatcher->luaSkinUUID)]; + [skin destroyGCCanary:&(usbwatcher->lsCanary)]; IONotificationPortDestroy(usbwatcher->gNotifyPort); diff --git a/extensions/webview/internal.m b/extensions/webview/internal.m index e9b5bf555..a4899a813 100644 --- a/extensions/webview/internal.m +++ b/extensions/webview/internal.m @@ -106,7 +106,7 @@ - (id)initWithContentRect:(NSRect)contentRect _allowKeyboardEntry = NO; _closeOnEscape = NO; _darkMode = NO; -// _luaSkinUUID = nil; +// _lsCanary = nil; // can't be set before the callback which acts on delegate methods is defined self.delegate = self; @@ -134,7 +134,7 @@ - (void)windowWillClose:(__unused NSNotification *)notification { LuaSkin *skin = [LuaSkin sharedWithState:NULL] ; lua_State *L = [skin L] ; - if (![skin checkLuaSkinInstance:self.luaSkinUUID]) { + if (![skin checkGCCanary:self.lsCanary]) { return; } _lua_stackguard_entry(L); @@ -581,7 +581,7 @@ - (WKWebView *)webView:(WKWebView *)theView createWebViewWithConfiguration:(WKWe newWindow.parent = parent ; newWindow.deleteOnClose = YES ; newWindow.opaque = parent.opaque ; - newWindow.luaSkinUUID = [skin getLuaSkinUUID]; + newWindow.lsCanary = [skin createGCCanary]; if (((HSWebViewWindow *)theView.window).windowCallback != LUA_NOREF) { [skin pushLuaRef:refTable ref:((HSWebViewWindow *)theView.window).windowCallback]; @@ -1702,14 +1702,14 @@ static int webview_evaluateJavaScript(lua_State *L) { callbackRef = [skin luaRef:refTable] ; } - LSUUID luaSkinUUID = [skin getLuaSkinUUID]; + LSGCCanary lsCanary = [skin createGCCanary]; [theView evaluateJavaScript:javascript completionHandler:^(id obj, NSError *error){ if (callbackRef != LUA_NOREF) { dispatch_async(dispatch_get_main_queue(), ^{ LuaSkin *blockSkin = [LuaSkin sharedWithState:L] ; - if (![blockSkin checkLuaSkinInstance:luaSkinUUID]) { + if (![blockSkin checkGCCanary:lsCanary]) { return; } [blockSkin pushLuaRef:refTable ref:callbackRef] ; @@ -1718,7 +1718,7 @@ static int webview_evaluateJavaScript(lua_State *L) { [blockSkin protectedCallAndError:@"hs.webview:evaluateJavaScript callback" nargs:2 nresults:0]; [blockSkin luaUnref:refTable ref:callbackRef] ; - [skin gcLuaSkinUUID:&luaSkinUUID]; + [skin destroyGCCanary:&lsCanary]; }); } }] ; @@ -1834,7 +1834,7 @@ static int webview_new(lua_State *L) { defer:YES]; if (theWindow) { - theWindow.luaSkinUUID = [skin getLuaSkinUUID]; + theWindow.lsCanary = [skin createGCCanary]; // Don't create until actually used... if (!HSWebViewProcessPool) HSWebViewProcessPool = [[WKProcessPool alloc] init] ; @@ -3093,9 +3093,9 @@ static int userdata_gc(lua_State* L) { theWindow.contentView = nil ; theView = nil ; - LSUUID tmpLSUUID = theWindow.luaSkinUUID; - [skin gcLuaSkinUUID:&tmpLSUUID]; - theWindow.luaSkinUUID = tmpLSUUID; + LSGCCanary tmpLSUUID = theWindow.lsCanary; + [skin destroyGCCanary:&tmpLSUUID]; + theWindow.lsCanary = tmpLSUUID; theWindow.delegate = nil ; theWindow = nil; diff --git a/extensions/webview/webview.h b/extensions/webview/webview.h index 47ec15654..145d3f45c 100644 --- a/extensions/webview/webview.h +++ b/extensions/webview/webview.h @@ -27,7 +27,7 @@ @property BOOL titleFollow ; @property BOOL deleteOnClose ; @property BOOL closeOnEscape ; -@property LSUUID luaSkinUUID ; +@property LSGCCanary lsCanary ; @end @interface HSWebViewView : WKWebView