Revision: 4140
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4140&view=rev
Author:   hofman
Date:     2008-07-06 16:57:16 -0700 (Sun, 06 Jul 2008)

Log Message:
-----------
Make code GC safe

Modified Paths:
--------------
    trunk/SkimNotes/PDFAnnotation_SKNExtensions.m

Modified: trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/PDFAnnotation_SKNExtensions.m       2008-07-06 21:30:58 UTC 
(rev 4139)
+++ trunk/SkimNotes/PDFAnnotation_SKNExtensions.m       2008-07-06 23:57:16 UTC 
(rev 4140)
@@ -82,31 +82,44 @@
 
 NSString *SKNPDFAnnotationIconTypeKey = @"iconType";
 
+static IMP SKNReplaceMethodImplementationWithSelector(Class aClass, SEL 
aSelector, SEL impSelector) {
+    Method aMethod = class_getInstanceMethod(aClass, aSelector);
+    Method impMethod = class_getInstanceMethod(aClass, impSelector);
+    IMP anImp = NULL;
+    if (method_getImplementation != NULL && method_setImplementation != NULL) {
+        anImp = method_setImplementation(aMethod, 
method_getImplementation(impMethod));
+    } else {
+        anImp = aMethod->method_imp;
+        aMethod->method_imp = impMethod->method_imp;
+        // Flush the method cache
+        extern void _objc_flush_caches(Class);
+        if (_objc_flush_caches != NULL)
+            _objc_flush_caches(aClass);
+    }
+    return anImp;
+}
 
 @implementation PDFAnnotation (SKNExtensions)
 
 static CFMutableSetRef SkimNotes = NULL;
 
 static IMP originalDealloc = NULL;
+static IMP originalFinalize = NULL;
 
-- (void)replacementDealloc {
+- (void)skn_replacementDealloc {
     CFSetRemoveValue(SkimNotes, self);
     originalDealloc(self, _cmd);
 }
 
+- (void)skn_replacementFinalize {
+    CFSetRemoveValue(SkimNotes, self);
+    originalFinalize(self, _cmd);
+}
+
 + (void)load {
-    Method aMethod = class_getInstanceMethod(self, @selector(dealloc));
-    Method impMethod = class_getInstanceMethod(self, 
@selector(replacementDealloc));
-    if (method_getImplementation != NULL && method_setImplementation != NULL) {
-        originalDealloc = method_setImplementation(aMethod, 
method_getImplementation(impMethod));
-    } else {
-        originalDealloc = aMethod->method_imp;
-        aMethod->method_imp = impMethod->method_imp;
-        // Flush the method cache
-        extern void _objc_flush_caches(Class);
-        if (_objc_flush_caches != NULL)
-            _objc_flush_caches(self);
-    }
+    originalDealloc = SKNReplaceMethodImplementationWithSelector(self, 
@selector(dealloc), @selector(skn_replacementDealloc));
+    if ([self instancesRespondToSelector:@selector(finalize)])
+        originalFinalize = SKNReplaceMethodImplementationWithSelector(self, 
@selector(finalize), @selector(skn_replacementFinalize));
     SkimNotes = CFSetCreateMutable(kCFAllocatorDefault, 0, NULL);
 }
 


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

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to