Revision: 28545
          http://sourceforge.net/p/bibdesk/svn/28545
Author:   hofman
Date:     2024-01-04 23:39:41 +0000 (Thu, 04 Jan 2024)
Log Message:
-----------
use CFBridgingRetain and CFBridgingRelease for invocations passed as contextInfo

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKTemplateDocument.m
    trunk/bibdesk/BibDocument.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2024-01-04 23:27:41 UTC (rev 28544)
+++ trunk/bibdesk/BDSKEditor.m  2024-01-04 23:39:41 UTC (rev 28545)
@@ -418,7 +418,8 @@
     if (delegate && didCommitSelector) {
         // - (void)editor:(id)editor didCommit:(BOOL)didCommit 
contextInfo:(void *)contextInfo
         NSInvocation *invocation = [NSInvocation invocationWithTarget:delegate 
selector:didCommitSelector];
-        [invocation setArgument:&self atIndex:2];
+        __unsafe_unretained id unretainedSelf = self;
+        [invocation setArgument:&unretainedSelf atIndex:2];
         [invocation setArgument:&didCommit atIndex:3];
         [invocation setArgument:&contextInfo atIndex:4];
         dispatch_async(dispatch_get_main_queue(), ^{ [invocation invoke]; });

Modified: trunk/bibdesk/BDSKTemplateDocument.m
===================================================================
--- trunk/bibdesk/BDSKTemplateDocument.m        2024-01-04 23:27:41 UTC (rev 
28544)
+++ trunk/bibdesk/BDSKTemplateDocument.m        2024-01-04 23:39:41 UTC (rev 
28545)
@@ -1008,7 +1008,8 @@
     } else if (delegate && shouldCloseSelector) {
         NSInvocation *invocation = [NSInvocation invocationWithTarget:delegate 
selector:shouldCloseSelector];
         BOOL no = NO;
-        [invocation setArgument:&self atIndex:2];
+        __unsafe_unretained id unretainedSelf = self;
+        [invocation setArgument:&unretainedSelf atIndex:2];
         [invocation setArgument:&no atIndex:3];
         [invocation setArgument:&contextInfo atIndex:4];
         [invocation invoke]; 

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2024-01-04 23:27:41 UTC (rev 28544)
+++ trunk/bibdesk/BibDocument.m 2024-01-04 23:39:41 UTC (rev 28545)
@@ -667,9 +667,10 @@
 }
 
 - (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose 
contextInfo:(void *)contextInfo {
-    NSInvocation *invocation = (id)contextInfo;
+    NSInvocation *invocation = (NSInvocation *)CFBridgingRelease(contextInfo);
     if (invocation) {
-        [invocation setArgument:&doc atIndex:2];
+        __unsafe_unretained NSDocument *theDoc = doc;
+        [invocation setArgument:&theDoc atIndex:2];
         [invocation setArgument:&shouldClose atIndex:3];
         // delay the closing when the document saved and we want to run a 
script hook
         if (shouldClose && docFlags.isSaving) {
@@ -676,7 +677,6 @@
             shouldCloseInvocation = invocation;
         } else {
             [invocation invoke];
-            [invocation release];
         }
     }
 }
@@ -684,10 +684,10 @@
 - (void)canCloseDocumentWithDelegate:(id)delegate 
shouldCloseSelector:(SEL)shouldCloseSelector contextInfo:(void *)contextInfo {
     NSInvocation *invocation = nil;
     if (delegate && shouldCloseSelector) {
-        invocation = [[NSInvocation invocationWithTarget:delegate 
selector:shouldCloseSelector] retain];
+        invocation = [NSInvocation invocationWithTarget:delegate 
selector:shouldCloseSelector];
         [invocation setArgument:&contextInfo atIndex:4];
     }
-    [super canCloseDocumentWithDelegate:self 
shouldCloseSelector:@selector(document:shouldClose:contextInfo:) 
contextInfo:invocation];
+    [super canCloseDocumentWithDelegate:self 
shouldCloseSelector:@selector(document:shouldClose:contextInfo:) 
contextInfo:(void *)CFBridgingRetain(invocation)];
 }
 
 - (BOOL)windowShouldClose:(id)sender {
@@ -1136,13 +1136,14 @@
 }
 
 - (void)document:(NSDocument *)doc didSave:(BOOL)didSave contextInfo:(void 
*)contextInfo {
-    NSInvocation *invocation = [(id)contextInfo autorelease];
+    NSInvocation *invocation = (NSInvocation *)CFBridgingRelease(contextInfo);
     
     docFlags.isExporting = NO;
     BDSKDESTROY(saveAccessoryController);
     
     if (invocation) {
-        [invocation setArgument:&doc atIndex:2];
+        __unsafe_unretained NSDocument *theDoc = doc;
+        [invocation setArgument:&theDoc atIndex:2];
         [invocation setArgument:&didSave atIndex:3];
         [invocation invoke];
     }
@@ -1153,10 +1154,10 @@
     docFlags.isExporting = BDSKIsSaveToOperation(saveOperation);
     NSInvocation *invocation = nil;
     if (delegate && didSaveSelector) {
-        invocation = [[NSInvocation invocationWithTarget:delegate 
selector:didSaveSelector] retain];
+        invocation = [NSInvocation invocationWithTarget:delegate 
selector:didSaveSelector];
         [invocation setArgument:&contextInfo atIndex:4];
     }
-    [super runModalSavePanelForSaveOperation:saveOperation delegate:self 
didSaveSelector:@selector(document:didSave:contextInfo:) 
contextInfo:invocation];
+    [super runModalSavePanelForSaveOperation:saveOperation delegate:self 
didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:(void 
*)CFBridgingRetain(invocation)];
 }
 
 // This is always used for saving on 10.7+, but does not exist on 10.6

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to