Revision: 28576
http://sourceforge.net/p/bibdesk/svn/28576
Author: hofman
Date: 2024-01-07 18:20:29 +0000 (Sun, 07 Jan 2024)
Log Message:
-----------
use @autoreleasepool blocks
Modified Paths:
--------------
trunk/bibdesk/BDSKAsyncObject.m
trunk/bibdesk/BDSKFileMatcher.m
trunk/bibdesk/BDSKFileSearchIndex.m
trunk/bibdesk/BDSKMetadataCacheOperation.m
trunk/bibdesk/BDSKNotesSearchIndex.m
trunk/bibdesk/BDSKSharingClient.m
trunk/bibdesk/BDSKSharingServer.m
trunk/bibdesk/BDSKTask.m
trunk/bibdesk/BDSKTemplateObjectProxy.m
trunk/bibdesk/BibDocument_Actions.m
Modified: trunk/bibdesk/BDSKAsyncObject.m
===================================================================
--- trunk/bibdesk/BDSKAsyncObject.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKAsyncObject.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -97,7 +97,6 @@
// detach a new thread to run this
NSAssert([NSThread isMainThread] == NO, @"do not run in the main thread");
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
NSPort *dummyPort = [[NSMachPort alloc] init];
@@ -113,9 +112,9 @@
// see
http://lists.apple.com/archives/cocoa-dev/2006/Jun/msg01054.html for a helpful
explanation of NSRunLoop
do {
- [pool release];
- pool = [NSAutoreleasePool new];
- didRun = [runLoop runMode:NSDefaultRunLoopMode
beforeDate:distantFuture];
+ @autoreleasepool {
+ didRun = [runLoop runMode:NSDefaultRunLoopMode
beforeDate:distantFuture];
+ }
} while (stopRunning == NO && didRun);
[distantFuture release];
@@ -130,8 +129,6 @@
[runLoop removePort:dummyPort forMode:NSDefaultRunLoopMode];
BDSKDESTROY(dummyPort);
-
- [pool release];
}
}
Modified: trunk/bibdesk/BDSKFileMatcher.m
===================================================================
--- trunk/bibdesk/BDSKFileMatcher.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKFileMatcher.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -466,72 +466,72 @@
if (atomic_load(&_matchFlags.shouldAbort)) break;
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- NSString *searchString = [node valueForKey:SEARCHSTRING_KEY];
-
- SKSearchRef search = SKSearchCreate(searchIndex, (__bridge
CFStringRef)searchString, kSKSearchOptionDefault);
-
- // if we get more than 10 matches back per pub, the results will be
pretty useless anyway
- SKDocumentID docID[MAX_SEARCHKIT_RESULTS];
- float scores[MAX_SEARCHKIT_RESULTS];
-
- CFIndex numFound;
-
- Boolean moreToFind;
- float thisScore, maxScore = 0.0;
- BOOL foundMatches = NO;
-
- do {
+ @autoreleasepool {
- moreToFind = SKSearchFindMatches(search, MAX_SEARCHKIT_RESULTS,
docID, scores, (CFTimeInterval)(MAX_SEARCHKIT_RESULTS/2.0), &numFound);
+ NSString *searchString = [node valueForKey:SEARCHSTRING_KEY];
- if (numFound) {
+ SKSearchRef search = SKSearchCreate(searchIndex, (__bridge
CFStringRef)searchString, kSKSearchOptionDefault);
+
+ // if we get more than 10 matches back per pub, the results will
be pretty useless anyway
+ SKDocumentID docID[MAX_SEARCHKIT_RESULTS];
+ float scores[MAX_SEARCHKIT_RESULTS];
+
+ CFIndex numFound;
+
+ Boolean moreToFind;
+ float thisScore, maxScore = 0.0;
+ BOOL foundMatches = NO;
+
+ do {
- CFURLRef urls[MAX_SEARCHKIT_RESULTS];
- SKIndexCopyDocumentURLsForDocumentIDs(searchIndex, numFound,
docID, urls);
+ moreToFind = SKSearchFindMatches(search,
MAX_SEARCHKIT_RESULTS, docID, scores,
(CFTimeInterval)(MAX_SEARCHKIT_RESULTS/2.0), &numFound);
- NSInteger i, iMax = numFound;
+ if (numFound) {
+
+ CFURLRef urls[MAX_SEARCHKIT_RESULTS];
+ SKIndexCopyDocumentURLsForDocumentIDs(searchIndex,
numFound, docID, urls);
+
+ NSInteger i, iMax = numFound;
+
+ // now we have a matching file; we could remove it from
the index, but multiple matches are reasonable
+ for (i = 0; i < iMax; i++) {
+ BDSKTreeNode *child = [[BDSKTreeNode alloc] init];
+ [child setValue:(__bridge NSURL *)urls[i]
forKey:FILEURL_KEY];
+ [child setValue:[[(__bridge NSURL *)urls[i] path]
stringByAbbreviatingWithTildeInPath] forKey:STRING_KEY];
+ [child setValue:[[NSWorkspace sharedWorkspace]
iconForFile:[(__bridge NSURL *)urls[i] path]] forKey:IMAGE_KEY];
+ [child setValue:searchString forKey:SEARCHSTRING_KEY];
+ thisScore = scores[i];
+ maxScore = MAX(maxScore, thisScore);
+ [child setValue:[NSNumber numberWithDouble:thisScore]
forKey:SCORE_KEY];
+ [[node mutableArrayValueForKey:CHILDREN_KEY]
addObject:child];
+ [child release];
+ CFRelease(urls[i]);
+ }
+ foundMatches = YES;
+ }
- // now we have a matching file; we could remove it from the
index, but multiple matches are reasonable
- for (i = 0; i < iMax; i++) {
- BDSKTreeNode *child = [[BDSKTreeNode alloc] init];
- [child setValue:(__bridge NSURL *)urls[i]
forKey:FILEURL_KEY];
- [child setValue:[[(__bridge NSURL *)urls[i] path]
stringByAbbreviatingWithTildeInPath] forKey:STRING_KEY];
- [child setValue:[[NSWorkspace sharedWorkspace]
iconForFile:[(__bridge NSURL *)urls[i] path]] forKey:IMAGE_KEY];
- [child setValue:searchString forKey:SEARCHSTRING_KEY];
- thisScore = scores[i];
- maxScore = MAX(maxScore, thisScore);
- [child setValue:[NSNumber numberWithDouble:thisScore]
forKey:SCORE_KEY];
- [[node mutableArrayValueForKey:CHILDREN_KEY]
addObject:child];
- [child release];
- CFRelease(urls[i]);
+ } while (numFound && moreToFind);
+
+ SKSearchCancel(search);
+ CFRelease(search);
+
+ normalizeScoresForItem(node, maxScore);
+ [node setValue:[NSString stringWithFormat:@"%ld", (long)[node
countOfChildren]] forKey:SCORE_KEY];
+ NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:SCORE_KEY ascending:NO];
+ NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sort,
nil];
+ [[node mutableArrayValueForKey:CHILDREN_KEY]
sortUsingDescriptors:sortDescriptors];
+ [sort release];
+ [sortDescriptors release];
+
+ val++;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (foundMatches) {
+ [matches addObject:node];
+ [outlineView reloadData];
}
- foundMatches = YES;
- }
-
- } while (numFound && moreToFind);
-
- SKSearchCancel(search);
- CFRelease(search);
-
- normalizeScoresForItem(node, maxScore);
- [node setValue:[NSString stringWithFormat:@"%ld", (long)[node
countOfChildren]] forKey:SCORE_KEY];
- NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:SCORE_KEY ascending:NO];
- NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sort, nil];
- [[node mutableArrayValueForKey:CHILDREN_KEY]
sortUsingDescriptors:sortDescriptors];
- [sort release];
- [sortDescriptors release];
-
- val++;
- dispatch_async(dispatch_get_main_queue(), ^{
- if (foundMatches) {
- [matches addObject:node];
- [outlineView reloadData];
- }
- [progressIndicator setDoubleValue:(val/max)];
- });
- [pool drain];
+ [progressIndicator setDoubleValue:(val/max)];
+ });
+ }
}
if (NO == atomic_load(&_matchFlags.shouldAbort)) {
Modified: trunk/bibdesk/BDSKFileSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKFileSearchIndex.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -443,24 +443,23 @@
- (void)indexFilesForItems:(NSArray *)items
numberPreviouslyIndexed:(double)numberIndexed
{
// Use a local pool since initial indexing can use a fair amount of
memory, and it's not released until the thread's run loop starts
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- double totalObjectCount = numberIndexed + [items count];
-
- for (id anObject in items) {
- if ([self shouldKeepRunning] == NO) break;
- [self indexFileURLs:[anObject objectForKey:BDSKBibItemURLsKey]
forIdentifierURL:[anObject objectForKey:BDSKBibItemIdentifierURLKey]];
- numberIndexed++;
- [self setProgressValue:(numberIndexed / totalObjectCount) * 100];
+ @autoreleasepool {
+ double totalObjectCount = numberIndexed + [items count];
- [pool release];
- pool = [NSAutoreleasePool new];
+ for (id anObject in items) {
+ @autoreleasepool {
+ if ([self shouldKeepRunning] == NO) break;
+ [self indexFileURLs:[anObject objectForKey:BDSKBibItemURLsKey]
forIdentifierURL:[anObject objectForKey:BDSKBibItemIdentifierURLKey]];
+ numberIndexed++;
+ [self setProgressValue:(numberIndexed / totalObjectCount) *
100];
+
+ [self didUpdate];
+ }
+ }
- [self didUpdate];
+ // caller queues a final update
+
}
-
- // caller queues a final update
-
- [pool release];
}
#pragma mark Change notification handling
@@ -595,32 +594,32 @@
for (id anItem in items) {
if ([self shouldKeepRunning] == NO) break;
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- NSMutableArray *missingURLs = nil;
- id signature;
-
- for (NSURL *url in [anItem objectForKey:BDSKBibItemURLsKey]) {
- signature = [signatures objectForKey:url];
- if (signature)
- [URLsToRemove removeObject:url];
- if (signature == nil || [signature
isEqual:signatureForURL(url)] == NO) {
- if (missingURLs == nil)
- missingURLs = [NSMutableArray array];
- [missingURLs addObject:url];
+ @autoreleasepool {
+
+ NSMutableArray *missingURLs = nil;
+ id signature;
+
+ for (NSURL *url in [anItem objectForKey:BDSKBibItemURLsKey]) {
+ signature = [signatures objectForKey:url];
+ if (signature)
+ [URLsToRemove removeObject:url];
+ if (signature == nil || [signature
isEqual:signatureForURL(url)] == NO) {
+ if (missingURLs == nil)
+ missingURLs = [NSMutableArray array];
+ [missingURLs addObject:url];
+ }
}
- }
-
- if ([missingURLs count]) {
- [itemsToAdd addObject:@{BDSKBibItemURLsKey:missingURLs}];
- } else {
- numberIndexed++;
- [self setProgressValue:(numberIndexed / totalObjectCount) *
100];
- [self didUpdate];
+ if ([missingURLs count]) {
+ [itemsToAdd addObject:@{BDSKBibItemURLsKey:missingURLs}];
+ } else {
+ numberIndexed++;
+ [self setProgressValue:(numberIndexed / totalObjectCount)
* 100];
+
+ [self didUpdate];
+ }
+
}
-
- [pool release];
}
// remove URLs we could not find in the database
Modified: trunk/bibdesk/BDSKMetadataCacheOperation.m
===================================================================
--- trunk/bibdesk/BDSKMetadataCacheOperation.m 2024-01-07 17:49:02 UTC (rev
28575)
+++ trunk/bibdesk/BDSKMetadataCacheOperation.m 2024-01-07 18:20:29 UTC (rev
28576)
@@ -67,76 +67,76 @@
return;
}
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ @autoreleasepool {
- NSError *error = nil;
- NSFileManager *fileManager = [[NSFileManager alloc] init];
-
- @try {
+ NSError *error = nil;
+ NSFileManager *fileManager = [[NSFileManager alloc] init];
+
+ @try {
- // hidden option to use XML plists for easier debugging, but the
binary plists are more efficient
- BOOL useXMLFormat = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseXMLSpotlightCacheKey];
- NSPropertyListFormat plistFormat = useXMLFormat ?
NSPropertyListXMLFormat_v1_0 : NSPropertyListBinaryFormat_v1_0;
+ // hidden option to use XML plists for easier debugging, but the
binary plists are more efficient
+ BOOL useXMLFormat = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseXMLSpotlightCacheKey];
+ NSPropertyListFormat plistFormat = useXMLFormat ?
NSPropertyListXMLFormat_v1_0 : NSPropertyListBinaryFormat_v1_0;
- NSURL *cacheURL = [fileManager
spotlightCacheFolderURLByCreating:&error];
- if (cacheURL == nil) {
- error = [NSError localErrorWithCode:kBDSKFileOperationFailed
localizedDescription:NSLocalizedString(@"Unable to create the cache folder for
Spotlight metadata.", @"Error description") underlyingError:error];
- @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to build metadata cache at path \"%@\"", [cacheURL
path]] userInfo:nil];
- }
-
- NSString *docPath = [documentURL path];
-
- // After this point, there should be no underlying NSError, so we'll
create one from scratch
-
- if ([documentURL checkResourceIsReachableAndReturnError:NULL] == NO) {
- error = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to find the file
associated with this item.", @"Error description"), NSLocalizedDescriptionKey,
docPath, NSFilePathErrorKey, nil]];
- @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to build metadata cache for document at path \"%@\"",
docPath] userInfo:nil];
- }
-
- NSData *bookmarkData = [documentURL bookmarkDataWithOptions:0
includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
- if (bookmarkData == nil) {
- error = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to create an alias for
this document.", @"Error description"), NSLocalizedDescriptionKey, docPath,
NSFilePathErrorKey, nil]];
- @throw [NSException
exceptionWithName:NSObjectNotAvailableException reason:[NSString
stringWithFormat:@"Unable to get an alias for file %@", docPath] userInfo:nil];
- }
-
- NSDictionary *docInfo = [NSDictionary
dictionaryWithObjectsAndKeys:docPath,
@"net_sourceforge_bibdesk_owningfilepath", bookmarkData, @"FileBookmark", nil];
-
- for (NSDictionary *anItem in publicationInfos) {
- if ([self isCancelled]) {
- NSLog(@"Application will quit without finishing writing
metadata cache.");
- break;
- } else {
- NSString *citeKey = [anItem
objectForKey:@"net_sourceforge_bibdesk_citekey"];
- if (citeKey) {
- NSURL *fileURL = [fileManager
spotlightCacheFileURLWithCiteKey:citeKey];
- // Save the plist; we can get an error if these are not
plist objects, or the file couldn't be written. The first case is a programmer
error, and the second should have been caught much earlier in this code.
- if (fileURL) {
- NSMutableDictionary *metadata = [docInfo mutableCopy];
- [metadata addEntriesFromDictionary:anItem];
- NSError *err = nil;
- NSData *data = [NSPropertyListSerialization
dataWithPropertyList:metadata format:plistFormat options:0 error:&err];
- [metadata release];
- if (nil == data) {
- error = [NSError
localErrorWithCode:kBDSKPropertyListSerializationFailed
localizedDescription:[NSString stringWithFormat:NSLocalizedString(@"Unable to
save metadata cache file for item with cite key \"%@\". The error was \"%@\"",
@"Error description"), citeKey, [err localizedDescription]]];
- @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to create cache file for %@", anItem] userInfo:nil];
- } else if (NO == [data writeToURL:fileURL
options:NSAtomicWrite error:&error]) {
- @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to create cache file for %@", anItem] userInfo:nil];
+ NSURL *cacheURL = [fileManager
spotlightCacheFolderURLByCreating:&error];
+ if (cacheURL == nil) {
+ error = [NSError localErrorWithCode:kBDSKFileOperationFailed
localizedDescription:NSLocalizedString(@"Unable to create the cache folder for
Spotlight metadata.", @"Error description") underlyingError:error];
+ @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to build metadata cache at path \"%@\"", [cacheURL
path]] userInfo:nil];
+ }
+
+ NSString *docPath = [documentURL path];
+
+ // After this point, there should be no underlying NSError, so
we'll create one from scratch
+
+ if ([documentURL checkResourceIsReachableAndReturnError:NULL] ==
NO) {
+ error = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to find the file
associated with this item.", @"Error description"), NSLocalizedDescriptionKey,
docPath, NSFilePathErrorKey, nil]];
+ @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to build metadata cache for document at path \"%@\"",
docPath] userInfo:nil];
+ }
+
+ NSData *bookmarkData = [documentURL bookmarkDataWithOptions:0
includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
+ if (bookmarkData == nil) {
+ error = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to create an alias for
this document.", @"Error description"), NSLocalizedDescriptionKey, docPath,
NSFilePathErrorKey, nil]];
+ @throw [NSException
exceptionWithName:NSObjectNotAvailableException reason:[NSString
stringWithFormat:@"Unable to get an alias for file %@", docPath] userInfo:nil];
+ }
+
+ NSDictionary *docInfo = [NSDictionary
dictionaryWithObjectsAndKeys:docPath,
@"net_sourceforge_bibdesk_owningfilepath", bookmarkData, @"FileBookmark", nil];
+
+ for (NSDictionary *anItem in publicationInfos) {
+ if ([self isCancelled]) {
+ NSLog(@"Application will quit without finishing writing
metadata cache.");
+ break;
+ } else {
+ NSString *citeKey = [anItem
objectForKey:@"net_sourceforge_bibdesk_citekey"];
+ if (citeKey) {
+ NSURL *fileURL = [fileManager
spotlightCacheFileURLWithCiteKey:citeKey];
+ // Save the plist; we can get an error if these are
not plist objects, or the file couldn't be written. The first case is a
programmer error, and the second should have been caught much earlier in this
code.
+ if (fileURL) {
+ NSMutableDictionary *metadata = [docInfo
mutableCopy];
+ [metadata addEntriesFromDictionary:anItem];
+ NSError *err = nil;
+ NSData *data = [NSPropertyListSerialization
dataWithPropertyList:metadata format:plistFormat options:0 error:&err];
+ [metadata release];
+ if (nil == data) {
+ error = [NSError
localErrorWithCode:kBDSKPropertyListSerializationFailed
localizedDescription:[NSString stringWithFormat:NSLocalizedString(@"Unable to
save metadata cache file for item with cite key \"%@\". The error was \"%@\"",
@"Error description"), citeKey, [err localizedDescription]]];
+ @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to create cache file for %@", anItem] userInfo:nil];
+ } else if (NO == [data writeToURL:fileURL
options:NSAtomicWrite error:&error]) {
+ @throw [NSException
exceptionWithName:NSInternalInconsistencyException reason:[NSString
stringWithFormat:@"Unable to create cache file for %@", anItem] userInfo:nil];
+ }
}
}
}
}
}
- }
- @catch (id localException) {
- NSLog(@"-[%@ %@] discarding exception %@", [self class],
NSStringFromSelector(_cmd), [localException description]);
- // log the error since presentError: only gives minimum info
- NSLog(@"%@", [error description]);
- [NSApp performSelectorOnMainThread:@selector(presentError:)
withObject:error waitUntilDone:NO];
+ @catch (id localException) {
+ NSLog(@"-[%@ %@] discarding exception %@", [self class],
NSStringFromSelector(_cmd), [localException description]);
+ // log the error since presentError: only gives minimum info
+ NSLog(@"%@", [error description]);
+ [NSApp performSelectorOnMainThread:@selector(presentError:)
withObject:error waitUntilDone:NO];
+ }
+ @finally {
+ [fileManager release];
+ }
}
- @finally {
- [fileManager release];
- [pool release];
- }
}
@end
@@ -172,13 +172,13 @@
NSDictionary *cacheInfo;
for (BibItem *anItem in publications) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- @try {
- if(cacheInfo = [anItem metadataCacheInfoForUpdate:update])
- [pubsInfo addObject:cacheInfo];
+ @autoreleasepool {
+ @try {
+ if(cacheInfo = [anItem metadataCacheInfoForUpdate:update])
+ [pubsInfo addObject:cacheInfo];
+ }
+ @catch (id e) { @throw(e); }
}
- @catch (id e) { @throw(e); }
- @finally { [pool release]; }
}
BDSKMetadataCacheOperation *operation = [[BDSKMetadataCacheOperation
alloc] initWithPublicationInfos:pubsInfo forDocumentURL:url];
Modified: trunk/bibdesk/BDSKNotesSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKNotesSearchIndex.m 2024-01-07 17:49:02 UTC (rev
28575)
+++ trunk/bibdesk/BDSKNotesSearchIndex.m 2024-01-07 18:20:29 UTC (rev
28576)
@@ -214,69 +214,69 @@
- (void)indexItemForIdentifierURL:(NSURL *)identifierURL fileURLs:(NSArray
*)fileURLs removeEmpty:(BOOL)removeEmpty
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- @try {
- SKDocumentRef doc = SKDocumentCreateWithURL((__bridge
CFURLRef)identifierURL);
- if (doc) {
-
- NSMutableString *searchText = nil;
- if ([fileURLs count]) {
- searchText = [NSMutableString string];
- for (NSURL *fileURL in fileURLs) {
- NSString *notesString = nil;
- NSWorkspace *ws = [NSWorkspace sharedWorkspace];
- NSString *type = [ws typeOfFile:[fileURL path] error:NULL];
- if (type && [ws type:type
conformsToType:@"net.sourceforge.skim-app.pdfd"])
- notesString = [fileManager
readSkimTextNotesFromPDFBundleAtURL:fileURL error:NULL];
- else
- notesString = [fileManager
readSkimTextNotesFromExtendedAttributesAtURL:fileURL error:NULL];
- if (notesString == nil) {
- NSArray *notes = nil;
+ @autoreleasepool {
+
+ @try {
+ SKDocumentRef doc = SKDocumentCreateWithURL((__bridge
CFURLRef)identifierURL);
+ if (doc) {
+
+ NSMutableString *searchText = nil;
+ if ([fileURLs count]) {
+ searchText = [NSMutableString string];
+ for (NSURL *fileURL in fileURLs) {
+ NSString *notesString = nil;
+ NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+ NSString *type = [ws typeOfFile:[fileURL path]
error:NULL];
if (type && [ws type:type
conformsToType:@"net.sourceforge.skim-app.pdfd"])
- notes = [fileManager
readSkimNotesFromPDFBundleAtURL:fileURL error:NULL];
- else if (type && [ws type:type
conformsToType:@"net.sourceforge.skim-app.skimnotes"])
- notes = [fileManager
readSkimNotesFromSkimFileAtURL:fileURL error:NULL];
+ notesString = [fileManager
readSkimTextNotesFromPDFBundleAtURL:fileURL error:NULL];
else
- notes = [fileManager
readSkimNotesFromExtendedAttributesAtURL:fileURL error:NULL];
- if (notes)
- notesString = SKNSkimTextNotes(notes);
+ notesString = [fileManager
readSkimTextNotesFromExtendedAttributesAtURL:fileURL error:NULL];
+ if (notesString == nil) {
+ NSArray *notes = nil;
+ if (type && [ws type:type
conformsToType:@"net.sourceforge.skim-app.pdfd"])
+ notes = [fileManager
readSkimNotesFromPDFBundleAtURL:fileURL error:NULL];
+ else if (type && [ws type:type
conformsToType:@"net.sourceforge.skim-app.skimnotes"])
+ notes = [fileManager
readSkimNotesFromSkimFileAtURL:fileURL error:NULL];
+ else
+ notes = [fileManager
readSkimNotesFromExtendedAttributesAtURL:fileURL error:NULL];
+ if (notes)
+ notesString = SKNSkimTextNotes(notes);
+ }
+ if ([notesString length]) {
+ if ([searchText length])
+ [searchText appendString:@"\n"];
+ [searchText appendString:notesString];
+ }
}
- if ([notesString length]) {
- if ([searchText length])
- [searchText appendString:@"\n"];
- [searchText appendString:notesString];
+ }
+
+ SKIndexRef theIndex = NULL;
+ [lock lockForReading];
+ if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
+ [lock unlock];
+ if (theIndex) {
+ BOOL didUpdate = NO;
+ if ([searchText length]) {
+ didUpdate = YES;
+ SKIndexAddDocumentWithText(theIndex, doc, (__bridge
CFStringRef)searchText, TRUE);
+ } else if (removeEmpty && kSKDocumentStateNotIndexed !=
(SKIndexGetDocumentState(theIndex, doc) % 3)) {
+ didUpdate = YES;
+ SKIndexRemoveDocument(theIndex, doc);
}
+ CFRelease(theIndex);
+ if (didUpdate) {
+ atomic_store(&needsFlushing, YES);
+ [self didUpdate];
+ }
}
+ CFRelease(doc);
}
-
- SKIndexRef theIndex = NULL;
- [lock lockForReading];
- if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
- [lock unlock];
- if (theIndex) {
- BOOL didUpdate = NO;
- if ([searchText length]) {
- didUpdate = YES;
- SKIndexAddDocumentWithText(theIndex, doc, (__bridge
CFStringRef)searchText, TRUE);
- } else if (removeEmpty && kSKDocumentStateNotIndexed !=
(SKIndexGetDocumentState(theIndex, doc) % 3)) {
- didUpdate = YES;
- SKIndexRemoveDocument(theIndex, doc);
- }
- CFRelease(theIndex);
- if (didUpdate) {
- atomic_store(&needsFlushing, YES);
- [self didUpdate];
- }
- }
- CFRelease(doc);
}
+ @catch(id e) {
+ NSLog(@"Ignored exception %@ when executing an index update", e);
+ }
+
}
- @catch(id e) {
- NSLog(@"Ignored exception %@ when executing an index update", e);
- }
-
- [pool drain];
}
@end
Modified: trunk/bibdesk/BDSKSharingClient.m
===================================================================
--- trunk/bibdesk/BDSKSharingClient.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKSharingClient.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -477,42 +477,40 @@
// set so we don't try calling this multiple times
atomic_store(&failedDownload, NO);
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- @try {
- NSDictionary *archive = nil;
- NSData *proxyData = [[self remoteServer]
archivedSnapshotOfPublications];
+ @autoreleasepool {
- if([proxyData length] != 0){
- if([proxyData mightBeCompressed])
- proxyData = [proxyData decompressedData];
- NSError *error = nil;
- archive = [NSPropertyListSerialization
propertyListWithData:proxyData options:NSPropertyListImmutable format:NULL
error:&error];
- if(error != nil){
- NSString *errorStr = [NSString stringWithFormat:@"Error
reading shared data: %@", error];
- @throw errorStr;
+ @try {
+ NSDictionary *archive = nil;
+ NSData *proxyData = [[self remoteServer]
archivedSnapshotOfPublications];
+
+ if([proxyData length] != 0){
+ if([proxyData mightBeCompressed])
+ proxyData = [proxyData decompressedData];
+ NSError *error = nil;
+ archive = [NSPropertyListSerialization
propertyListWithData:proxyData options:NSPropertyListImmutable format:NULL
error:&error];
+ if(error != nil){
+ NSString *errorStr = [NSString stringWithFormat:@"Error
reading shared data: %@", error];
+ @throw errorStr;
+ }
}
+ // use the main thread; this avoids an extra (un)archiving between
threads and it ends up posting notifications for UI updates
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ [client setArchivedPublicationsAndMacros:archive];
+ });
+ // the client will reset the isRetriving flag when the data is set
}
- // use the main thread; this avoids an extra (un)archiving between
threads and it ends up posting notifications for UI updates
- dispatch_sync(dispatch_get_main_queue(), ^{
- [client setArchivedPublicationsAndMacros:archive];
- });
- // the client will reset the isRetriving flag when the data is set
+ @catch(id exception){
+ NSLog(@"%@: discarding exception \"%@\" while retrieving
publications", [self class], exception);
+ atomic_store(&failedDownload, YES);
+ [self setErrorMessage:NSLocalizedString(@"Failed to retrieve
publications", @"")];
+
+ // this posts a notification that the publications of the client
changed, forcing a redisplay of the table cell
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [client setArchivedPublicationsAndMacros:nil];
+ });
+ // the client will reset the isRetriving flag when the data is set
+ }
}
- @catch(id exception){
- NSLog(@"%@: discarding exception \"%@\" while retrieving
publications", [self class], exception);
- atomic_store(&failedDownload, YES);
- [self setErrorMessage:NSLocalizedString(@"Failed to retrieve
publications", @"")];
-
- // this posts a notification that the publications of the client
changed, forcing a redisplay of the table cell
- dispatch_async(dispatch_get_main_queue(), ^{
- [client setArchivedPublicationsAndMacros:nil];
- });
- // the client will reset the isRetriving flag when the data is set
- }
- @finally{
- [pool release];
- }
}
- (void)didFinish;
Modified: trunk/bibdesk/BDSKSharingServer.m
===================================================================
--- trunk/bibdesk/BDSKSharingServer.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKSharingServer.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -83,15 +83,15 @@
// convert this to an NSNotification
static void SCDynamicStoreChanged(SCDynamicStoreRef store, CFArrayRef
changedKeys, void *info)
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- CFIndex cnt = CFArrayGetCount(changedKeys);
- CFStringRef key;
- while(cnt--){
- key = CFArrayGetValueAtIndex(changedKeys, cnt);
- if (key && BDSKComputerNameChangedKey && CFEqual(key,
BDSKComputerNameChangedKey))
- BDSKENSURE_MAIN_THREAD( [[NSNotificationCenter defaultCenter]
postNotificationName:BDSKComputerNameChangedNotification object:nil]; );
+ @autoreleasepool {
+ CFIndex cnt = CFArrayGetCount(changedKeys);
+ CFStringRef key;
+ while(cnt--){
+ key = CFArrayGetValueAtIndex(changedKeys, cnt);
+ if (key && BDSKComputerNameChangedKey && CFEqual(key,
BDSKComputerNameChangedKey))
+ BDSKENSURE_MAIN_THREAD( [[NSNotificationCenter defaultCenter]
postNotificationName:BDSKComputerNameChangedNotification object:nil]; );
+ }
}
- [pool release];
}
@interface NSConnection (BDSKPrivateDeclarations)
Modified: trunk/bibdesk/BDSKTask.m
===================================================================
--- trunk/bibdesk/BDSKTask.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BDSKTask.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -500,59 +500,60 @@
{
do {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- struct kevent evt;
-
- if (HANDLE_EINTR(kevent(_kqueue, NULL, 0, &evt, 1, NULL))) {
+ @autoreleasepool {
- struct BDSKTaskInternal *internal = evt.udata;
- pthread_mutex_lock(&internal->_lock);
+ struct kevent evt;
- // can only fail if _disableNotification is called immediately
after kevent unblocks
- if (internal->_canNotify) {
-
- // retain a pointer to the task before unlocking
- BDSKTask *task = [internal->_task retain];
- pthread_mutex_unlock(&internal->_lock);
-
- // may be called multiple times; no need to free anything
- if (evt.fflags & NOTE_SIGNAL)
- [task _taskSignaled];
+ if (HANDLE_EINTR(kevent(_kqueue, NULL, 0, &evt, 1, NULL))) {
- /*
- Only called once; can free stuff on this code path, as
-dealloc will not be called
- while it's executing because we have a retain on the task.
- */
- if (evt.fflags & NOTE_EXIT)
- [task _taskExited];
+ struct BDSKTaskInternal *internal = evt.udata;
+ pthread_mutex_lock(&internal->_lock);
- [task release];
-
- }
- else {
+ // can only fail if _disableNotification is called immediately
after kevent unblocks
+ if (internal->_canNotify) {
+
+ // retain a pointer to the task before unlocking
+ BDSKTask *task = [internal->_task retain];
+ pthread_mutex_unlock(&internal->_lock);
- //NSLog(@"Not posting NSTaskDidTerminateNotification for
deallocated task %p", internal->_task);
+ // may be called multiple times; no need to free anything
+ if (evt.fflags & NOTE_SIGNAL)
+ [task _taskSignaled];
+
+ /*
+ Only called once; can free stuff on this code path, as
-dealloc will not be called
+ while it's executing because we have a retain on the task.
+ */
+ if (evt.fflags & NOTE_EXIT)
+ [task _taskExited];
+
+ [task release];
+
+ }
+ else {
- // delete this event to make sure we don't get anything else
- internal->_event.flags = EV_DELETE;
- (void) HANDLE_EINTR(kevent(_kqueue, &internal->_event, 1,
NULL, 0, NULL));
+ //NSLog(@"Not posting NSTaskDidTerminateNotification for
deallocated task %p", internal->_task);
- /*
- -dealloc or -finalize have called _disableNotification, and it
- is now our responsibility to free the _internal pointer.
- */
- pthread_mutex_unlock(&internal->_lock);
- pthread_mutex_destroy(&internal->_lock);
+ // delete this event to make sure we don't get anything
else
+ internal->_event.flags = EV_DELETE;
+ (void) HANDLE_EINTR(kevent(_kqueue, &internal->_event, 1,
NULL, 0, NULL));
- // runloop and source were freed in _disableNotification
- NSParameterAssert(NULL == internal->_rl);
- NSParameterAssert(NULL == internal->_rlsource);
- free(internal);
+ /*
+ -dealloc or -finalize have called _disableNotification,
and it
+ is now our responsibility to free the _internal pointer.
+ */
+ pthread_mutex_unlock(&internal->_lock);
+ pthread_mutex_destroy(&internal->_lock);
+
+ // runloop and source were freed in _disableNotification
+ NSParameterAssert(NULL == internal->_rl);
+ NSParameterAssert(NULL == internal->_rlsource);
+ free(internal);
+
+ }
- }
-
+ }
}
- [pool drain];
} while (1);
}
Modified: trunk/bibdesk/BDSKTemplateObjectProxy.m
===================================================================
--- trunk/bibdesk/BDSKTemplateObjectProxy.m 2024-01-07 17:49:02 UTC (rev
28575)
+++ trunk/bibdesk/BDSKTemplateObjectProxy.m 2024-01-07 18:20:29 UTC (rev
28576)
@@ -142,7 +142,6 @@
BDSKPRECONDITION(nil != template);
BDSKTemplateFormat format = [template templateFormat];
id returnString = nil;
- NSAutoreleasePool *pool = nil;
NSMutableDictionary *parsedTemplates = [NSMutableDictionary dictionary];
NSArray *parsedTemplate;
NSInteger currentIndex = 0;
@@ -151,27 +150,27 @@
returnString = [NSMutableString stringWithString:@""];
for (pub in [self publications]){
- pool = [NSAutoreleasePool new];
- parsedTemplate = [parsedTemplates objectForKey:[pub pubType]];
- if (parsedTemplate == nil) {
- if ([template templateURLForType:[pub pubType]]) {
- parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateString:[template stringForType:[pub pubType]]
isSubtemplate:NO];
- } else {
- parsedTemplate = [parsedTemplates
objectForKey:BDSKTemplateDefaultItemString];
- if (parsedTemplate == nil) {
- parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateString:[template
stringForType:BDSKTemplateDefaultItemString] isSubtemplate:NO];
- BDSKPRECONDITION(nil != parsedTemplate);
- [parsedTemplates setObject:parsedTemplate
forKey:BDSKTemplateDefaultItemString];
+ @autoreleasepool {
+ parsedTemplate = [parsedTemplates objectForKey:[pub pubType]];
+ if (parsedTemplate == nil) {
+ if ([template templateURLForType:[pub pubType]]) {
+ parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateString:[template stringForType:[pub pubType]]
isSubtemplate:NO];
+ } else {
+ parsedTemplate = [parsedTemplates
objectForKey:BDSKTemplateDefaultItemString];
+ if (parsedTemplate == nil) {
+ parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateString:[template
stringForType:BDSKTemplateDefaultItemString] isSubtemplate:NO];
+ BDSKPRECONDITION(nil != parsedTemplate);
+ [parsedTemplates setObject:parsedTemplate
forKey:BDSKTemplateDefaultItemString];
+ }
}
+ BDSKPRECONDITION(nil != parsedTemplate);
+ if (parsedTemplate)
+ [parsedTemplates setObject:parsedTemplate forKey:[pub
pubType]];
}
- BDSKPRECONDITION(nil != parsedTemplate);
- if (parsedTemplate)
- [parsedTemplates setObject:parsedTemplate forKey:[pub
pubType]];
+ [pub prepareForTemplateParsing];
+ [returnString appendString:[BDSKTemplateParser
stringFromTemplateArray:parsedTemplate usingObject:pub atIndex:++currentIndex]];
+ [pub cleanupAfterTemplateParsing];
}
- [pub prepareForTemplateParsing];
- [returnString appendString:[BDSKTemplateParser
stringFromTemplateArray:parsedTemplate usingObject:pub atIndex:++currentIndex]];
- [pub cleanupAfterTemplateParsing];
- [pool release];
}
} else if (format & BDSKTemplateFormatRichText) {
@@ -178,24 +177,24 @@
returnString = [[[NSMutableAttributedString alloc] init] autorelease];
for (pub in [self publications]){
- pool = [NSAutoreleasePool new];
- parsedTemplate = [parsedTemplates objectForKey:[pub pubType]];
- if (parsedTemplate == nil) {
- if ([template templateURLForType:[pub pubType]]) {
- parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateAttributedString:[template attributedStringForType:[pub
pubType]] isSubtemplate:NO];
- } else {
- parsedTemplate = [parsedTemplates
objectForKey:BDSKTemplateDefaultItemString];
- if (parsedTemplate == nil) {
- parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateAttributedString:[template
attributedStringForType:BDSKTemplateDefaultItemString] isSubtemplate:NO];
- [parsedTemplates setObject:parsedTemplate
forKey:BDSKTemplateDefaultItemString];
+ @autoreleasepool {
+ parsedTemplate = [parsedTemplates objectForKey:[pub pubType]];
+ if (parsedTemplate == nil) {
+ if ([template templateURLForType:[pub pubType]]) {
+ parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateAttributedString:[template attributedStringForType:[pub
pubType]] isSubtemplate:NO];
+ } else {
+ parsedTemplate = [parsedTemplates
objectForKey:BDSKTemplateDefaultItemString];
+ if (parsedTemplate == nil) {
+ parsedTemplate = [BDSKTemplateParser
arrayByParsingTemplateAttributedString:[template
attributedStringForType:BDSKTemplateDefaultItemString] isSubtemplate:NO];
+ [parsedTemplates setObject:parsedTemplate
forKey:BDSKTemplateDefaultItemString];
+ }
}
+ [parsedTemplates setObject:parsedTemplate forKey:[pub
pubType]];
}
- [parsedTemplates setObject:parsedTemplate forKey:[pub
pubType]];
+ [pub prepareForTemplateParsing];
+ [returnString appendAttributedString:[BDSKTemplateParser
attributedStringFromTemplateArray:parsedTemplate usingObject:pub
atIndex:++currentIndex]];
+ [pub cleanupAfterTemplateParsing];
}
- [pub prepareForTemplateParsing];
- [returnString appendAttributedString:[BDSKTemplateParser
attributedStringFromTemplateArray:parsedTemplate usingObject:pub
atIndex:++currentIndex]];
- [pub cleanupAfterTemplateParsing];
- [pool release];
}
}
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2024-01-07 17:49:02 UTC (rev 28575)
+++ trunk/bibdesk/BibDocument_Actions.m 2024-01-07 18:20:29 UTC (rev 28576)
@@ -1502,34 +1502,28 @@
NSMutableArray *arrayOfNewValues = [NSMutableArray array];
NSInteger numChanged = 0;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
for (BibItem *aPub in pubs){
- NSString *oldKey = [aPub citeKey];
- NSString *newKey = [aPub suggestedCiteKey];
- NSString *crossref = [aPub valueOfField:BDSKCrossrefString
inherit:NO];
- if (crossref != nil && [crossref isCaseInsensitiveEqual:newKey]) {
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert setMessageText:NSLocalizedString(@"Could not generate
cite key", @"Message in alert dialog when failing to generate cite key")];
- [alert setInformativeText:[NSString
stringWithFormat:NSLocalizedString(@"The cite key for \"%@\" could not be
generated because the generated key would be the same as the crossref key.",
@"Informative text in alert dialog"), [aPub citeKey]]];
- [alert beginSheetModalForWindow:documentWindow
completionHandler:NULL];
- continue;
+ @autoreleasepool {
+ NSString *oldKey = [aPub citeKey];
+ NSString *newKey = [aPub suggestedCiteKey];
+ NSString *crossref = [aPub valueOfField:BDSKCrossrefString
inherit:NO];
+ if (crossref != nil && [crossref
isCaseInsensitiveEqual:newKey]) {
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:NSLocalizedString(@"Could not
generate cite key", @"Message in alert dialog when failing to generate cite
key")];
+ [alert setInformativeText:[NSString
stringWithFormat:NSLocalizedString(@"The cite key for \"%@\" could not be
generated because the generated key would be the same as the crossref key.",
@"Informative text in alert dialog"), [aPub citeKey]]];
+ [alert beginSheetModalForWindow:documentWindow
completionHandler:NULL];
+ continue;
+ }
+ [arrayOfPubs addObject:aPub];
+ [arrayOfOldValues addObject:oldKey];
+ [arrayOfNewValues addObject:newKey];
+ if ([newKey isEqualToString:oldKey] == NO) {
+ [aPub setCiteKey:newKey];
+ ++numChanged;
+ }
}
- [arrayOfPubs addObject:aPub];
- [arrayOfOldValues addObject:oldKey];
- [arrayOfNewValues addObject:newKey];
- if ([newKey isEqualToString:oldKey] == NO) {
- [aPub setCiteKey:newKey];
- ++numChanged;
- }
-
- [pool release];
- pool = [[NSAutoreleasePool alloc] init];
}
- // should be safe to release here since arrays were created outside
the scope of this local pool
- [pool release];
-
if (numChanged > 0)
[[self undoManager] setActionName:(numChanged > 1 ?
NSLocalizedString(@"Generate Cite Keys", @"Undo action name") :
NSLocalizedString(@"Generate Cite Key", @"Undo action name"))];
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