adium 4355:13a64cb2366c: Make sure the shared localizedDateForma...
commits at adium.im
commits at adium.im
Thu Dec 8 21:54:12 UTC 2011
details: http://hg.adium.im/adium/rev/13a64cb2366c
revision: 4355:13a64cb2366c
branch: (none)
author: Thijs Alkemade <thijsalkemade at gmail.com>
date: Thu Dec 08 22:53:57 2011 +0100
Make sure the shared localizedDateFormatter is only accessed from the main thread in the log indexer, as NSDateFormatter is not thread safe.
Fixes #15556
diffs (72 lines):
diff -r ba723c50ed40 -r 13a64cb2366c Source/AIXMLChatlogConverter.h
--- a/Source/AIXMLChatlogConverter.h Thu Dec 08 00:09:53 2011 +0100
+++ b/Source/AIXMLChatlogConverter.h Thu Dec 08 22:53:57 2011 +0100
@@ -28,7 +28,6 @@
@class AIHTMLDecoder;
@interface AIXMLChatlogConverter : NSObject {
- NSDateFormatter *dateFormatter;
NSDictionary *statusLookup;
NSAttributedString *newlineAttributedString;
AIHTMLDecoder *htmlDecoder;
diff -r ba723c50ed40 -r 13a64cb2366c Source/AIXMLChatlogConverter.m
--- a/Source/AIXMLChatlogConverter.m Thu Dec 08 00:09:53 2011 +0100
+++ b/Source/AIXMLChatlogConverter.m Thu Dec 08 22:53:57 2011 +0100
@@ -122,7 +122,6 @@
}
htmlDecoder = [[AIHTMLDecoder alloc] init];
- dateFormatter = [[NSDateFormatter localizedDateFormatterShowingSeconds:YES showingAMorPM:YES] retain];
statusLookup = [[NSDictionary alloc] initWithObjectsAndKeys:
AILocalizedString(@"Online", nil), @"online",
@@ -149,7 +148,6 @@
- (void)dealloc
{
- [dateFormatter release];
[statusLookup release];
[htmlDecoder release];
[super dealloc];
@@ -261,14 +259,19 @@
}
}
- NSString *timestampStr = [dateFormatter stringFromDate:date];
+ __block NSString *timestampStr = nil;
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ timestampStr = [[[NSDateFormatter localizedDateFormatterShowingSeconds:YES showingAMorPM:YES] stringFromDate:date] retain];
+ });
[output appendAttributedString:[htmlDecoder decodeHTML:[NSString stringWithFormat:
@"<div class=\"%@\">%@<span class=\"sender\">%@%@:</span></div> ",
(sentMessage ? @"send" : @"receive"),
(showTimestamps ? [NSString stringWithFormat:@"<span class=\"timestamp\">%@</span> ", timestampStr] : @""),
shownSender, (autoResponse ? AILocalizedString(@" (Autoreply)", nil) : @"")]]];
-
+ [timestampStr release];
+
NSAttributedString *attributedMessage = [htmlDecoder decodeHTML:messageXML];
if (showEmoticons) {
attributedMessage = [adium.contentController filterAttributedString:attributedMessage
@@ -300,11 +303,18 @@
displayMessage = [NSString stringWithFormat:AILocalizedString(@"Changed status to %@", nil), [statusLookup objectForKey:status]];
}
+ __block NSString *timestampStr = nil;
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ timestampStr = [[[NSDateFormatter localizedDateFormatterShowingSeconds:YES showingAMorPM:YES] stringFromDate:date] retain];
+ });
+
if([displayMessage length]) {
[output appendAttributedString:[htmlDecoder decodeHTML:[NSString stringWithFormat:@"<div class=\"status\">%@ (%@)</div>\n",
displayMessage,
- [dateFormatter stringFromDate:date]]]];
+ timestampStr]]];
}
+ [timestampStr release];
}
}
More information about the commits
mailing list