Revision: 4142
http://skim-app.svn.sourceforge.net/skim-app/?rev=4142&view=rev
Author: hofman
Date: 2008-07-07 10:05:56 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
Make framework code GC compatible. Use an NSHashTable if GC is enabled. Code
protected by compiler setting checks. We don't support GC in the build settings
though, but it should be safe to change that now if it would be needed.
Modified Paths:
--------------
trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
Modified: trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/PDFAnnotation_SKNExtensions.m 2008-07-07 00:10:31 UTC
(rev 4141)
+++ trunk/SkimNotes/PDFAnnotation_SKNExtensions.m 2008-07-07 17:05:56 UTC
(rev 4142)
@@ -84,30 +84,42 @@
@implementation PDFAnnotation (SKNExtensions)
-static CFMutableSetRef SkimNotes = NULL;
+static id SkimNotes = nil;
static IMP originalDealloc = NULL;
-- (void)skn_replacementDealloc {
- CFSetRemoveValue(SkimNotes, self);
+void skn_replacementDealloc(id self, SEL _cmd) {
+ [SkimNotes removeObject:self];
originalDealloc(self, _cmd);
}
+ (void)load {
- Method aMethod = class_getInstanceMethod(self, @selector(dealloc));
- Method impMethod = class_getInstanceMethod(self,
@selector(skn_replacementDealloc));
- IMP anImp = NULL;
- 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);
+#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >=
MAC_OS_X_VERSION_10_5
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4 &&
[NSGarbageCollector defaultCollector])
+ SkimNotes = [[NSHashTable alloc]
initWithOptions:NSHashTableZeroingWeakMemory capacity:0];
+ else
+#endif
+ {
+ Method deallocMethod = class_getInstanceMethod(self,
@selector(dealloc));
+#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_5
+ originalDealloc = method_setImplementation(deallocMethod,
(IMP)skn_replacementDealloc);
+#else
+#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >=
MAC_OS_X_VERSION_10_5
+ if (method_setImplementation != NULL)
+ originalDealloc = method_setImplementation(deallocMethod,
(IMP)skn_replacementDealloc);
+ else
+#endif
+ {
+ originalDealloc = deallocMethod->method_imp;
+ deallocMethod->method_imp = (IMP)skn_replacementDealloc;
+ // Flush the method cache
+ extern void _objc_flush_caches(Class);
+ if (_objc_flush_caches != NULL)
+ _objc_flush_caches(self);
+ }
+#endif
+ SkimNotes = (NSMutableSet *)CFSetCreateMutable(kCFAllocatorDefault, 0,
NULL);
}
- SkimNotes = CFSetCreateMutable(kCFAllocatorDefault, 0, NULL);
}
- (id)initSkimNoteWithBounds:(NSRect)bounds {
@@ -200,14 +212,12 @@
}
- (BOOL)isSkimNote {
- return CFSetContainsValue(SkimNotes, self);
+ return [SkimNotes containsObject:self];
}
- (void)setSkimNote:(BOOL)flag {
- if (flag)
- CFSetAddValue(SkimNotes, self);
- else
- CFSetRemoveValue(SkimNotes, self);
+ if (flag) [SkimNotes addObject:self];
+ else [SkimNotes removeObject:self];
}
- (NSString *)string {
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