Skip to content

Commit

Permalink
A bit of re-ordering to try to avoid premature initialisation of NSUs…
Browse files Browse the repository at this point in the history
…erDefaults.
  • Loading branch information
rfm committed Nov 27, 2024
1 parent 7d4771e commit f236808
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 64 deletions.
109 changes: 49 additions & 60 deletions Source/Additions/GSMime.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ A container for the actual data (and headers) of a mime/http
static Class NSStringClass = 0;
static Class NSDataClass = 0;
static Class documentClass = 0;
static Class headerClass = 0;

static BOOL oldStyleFolding = NO;
static NSString *Cte7bit = @"7bit";
Expand Down Expand Up @@ -888,6 +887,29 @@ + (GSMimeDocument*) documentFromData: (NSData*)mimeData

+ (void) initialize
{
NSMutableCharacterSet *m = [[NSMutableCharacterSet alloc] init];

[m formUnionWithCharacterSet:
[NSCharacterSet characterSetWithCharactersInString:
@".()<>@,;:[]\"\\"]];
[m formUnionWithCharacterSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[m formUnionWithCharacterSet:
[NSCharacterSet controlCharacterSet]];
[m formUnionWithCharacterSet:
[NSCharacterSet illegalCharacterSet]];
rfc822Specials = [m copy];
[[NSObject leakAt: &rfc822Specials] release];
[m formUnionWithCharacterSet:
[NSCharacterSet characterSetWithCharactersInString:
@"/?="]];
[m removeCharactersInString: @"."];
rfc2045Specials = [m copy];
[[NSObject leakAt: &rfc2045Specials] release];
[m release];
whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]);
[[NSObject leakAt: &whitespace] release];

if (NSArrayClass == 0)
{
NSArrayClass = [NSArray class];
Expand All @@ -904,10 +926,6 @@ + (void) initialize
{
documentClass = [GSMimeDocument class];
}
if (headerClass == 0)
{
headerClass = [GSMimeHeader class];
}
}

/**
Expand Down Expand Up @@ -1745,9 +1763,9 @@ - (BOOL) parseHeader: (NSString*)aHeader
/*
* Set the header name.
*/
info = [headerClass headerWithName: name
value: nil
parameters: nil];
info = [GSMimeHeader headerWithName: name
value: nil
parameters: nil];
name = [info name];

/*
Expand Down Expand Up @@ -3395,10 +3413,6 @@ + (void) initialize
{
documentClass = [GSMimeDocument class];
}
if (headerClass == 0)
{
headerClass = [GSMimeHeader class];
}
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(_defaultsChanged:)
name: NSUserDefaultsDidChangeNotification
Expand Down Expand Up @@ -3607,7 +3621,7 @@ - (id) copyWithZone: (NSZone*)z
NSEnumerator *e;
NSString *k;

c = [headerClass allocWithZone: z];
c = [[self class] allocWithZone: z];
c = [c initWithName: [self namePreservingCase: YES]
value: [self value]
parameters: [self parametersPreservingCase: YES]];
Expand Down Expand Up @@ -3722,7 +3736,7 @@ - (NSString*) fullValue
{
NSString *v;

v = [headerClass makeQuoted: [params objectForKey: k] always: NO];
v = [[self class] makeQuoted: [params objectForKey: k] always: NO];
[m appendString: @"; "];
[m appendString: k];
[m appendString: @"="];
Expand Down Expand Up @@ -3769,7 +3783,7 @@ - (id) initWithName: (NSString*)n
value: (NSString*)v
parameters: (NSDictionary*)p
{
n = [headerClass makeToken: n preservingCase: YES];
n = [[self class] makeToken: n preservingCase: YES];
if ([n length] == 0)
{
n = @"unknown";
Expand Down Expand Up @@ -3807,7 +3821,7 @@ - (BOOL) isEqual: (id)other
{
return YES;
}
if (NO == [other isKindOfClass: headerClass])
if (NO == [other isKindOfClass: [self class]])
{
return NO;
}
Expand Down Expand Up @@ -3876,7 +3890,7 @@ - (NSString*) parameterForKey: (NSString*)k

if (p == nil)
{
k = [headerClass makeToken: k];
k = [[self class] makeToken: k];
p = [params objectForKey: k];
}
return p;
Expand Down Expand Up @@ -4540,7 +4554,7 @@ - (void) rawMimeDataPreservingCase: (BOOL)preserve
NSUInteger kLength;
NSUInteger vLength;

v = [headerClass makeQuoted: [params objectForKey: k] always: NO];
v = [[self class] makeQuoted: [params objectForKey: k] always: NO];
if (preserve == NO)
{
k = [k lowercaseString];
Expand Down Expand Up @@ -4628,7 +4642,7 @@ - (void) setObject: (id)o forKey: (NSString*)k
*/
- (void) setParameter: (NSString*)v forKey: (NSString*)k
{
k = [headerClass makeToken: k preservingCase: YES];
k = [[self class] makeToken: k preservingCase: YES];
if (v == nil)
{
[params removeObjectForKey: k];
Expand Down Expand Up @@ -4662,7 +4676,7 @@ - (void) setParameters: (NSDictionary*)d
{
NSString *v = [d objectForKey: k];

k = [headerClass makeToken: k preservingCase: YES];
k = [[self class] makeToken: k preservingCase: YES];
[m setObject: v forKey: k];
}
}
Expand Down Expand Up @@ -5216,32 +5230,11 @@ + (void) initialize
{
if (self == [GSMimeDocument class])
{
NSMutableCharacterSet *m = [[NSMutableCharacterSet alloc] init];

if (documentClass == 0)
{
documentClass = [GSMimeDocument class];
}
[m formUnionWithCharacterSet:
[NSCharacterSet characterSetWithCharactersInString:
@".()<>@,;:[]\"\\"]];
[m formUnionWithCharacterSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[m formUnionWithCharacterSet:
[NSCharacterSet controlCharacterSet]];
[m formUnionWithCharacterSet:
[NSCharacterSet illegalCharacterSet]];
rfc822Specials = [m copy];
[[NSObject leakAt: &rfc822Specials] release];
[m formUnionWithCharacterSet:
[NSCharacterSet characterSetWithCharactersInString:
@"/?="]];
[m removeCharactersInString: @"."];
rfc2045Specials = [m copy];
[[NSObject leakAt: &rfc2045Specials] release];
[m release];
whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]);
[[NSObject leakAt: &whitespace] release];

if (NSArrayClass == 0)
{
NSArrayClass = [NSArray class];
Expand Down Expand Up @@ -5812,10 +5805,6 @@ + (void) initialize
(void*)@"gb18030");
#endif
}
if (headerClass == 0)
{
headerClass = [GSMimeHeader class];
}
}
}

Expand Down Expand Up @@ -5926,7 +5915,7 @@ - (GSMimeHeader*) addHeader: (NSString*)name
{
GSMimeHeader *hdr;

hdr = [headerClass alloc];
hdr = [GSMimeHeader alloc];
hdr = [hdr initWithName: name
value: value
parameters: parameters];
Expand Down Expand Up @@ -6685,7 +6674,7 @@ - (GSMimeHeader*) headerNamed: (NSString*)name
oaiIMP imp1;
boolIMP imp2;

name = [headerClass makeToken: name preservingCase: NO];
name = [GSMimeHeader makeToken: name preservingCase: NO];
imp1 = (oaiIMP)[headers methodForSelector: @selector(objectAtIndex:)];
imp2 = (boolIMP)[name methodForSelector: @selector(isEqualToString:)];
for (index = 0; index < count; index++)
Expand All @@ -6710,7 +6699,7 @@ - (NSArray*) headersNamed: (NSString*)name
{
NSUInteger count;

name = [headerClass makeToken: name preservingCase: NO];
name = [GSMimeHeader makeToken: name preservingCase: NO];
count = [headers count];
if (count > 0)
{
Expand Down Expand Up @@ -6841,9 +6830,9 @@ - (GSMimeHeader*) makeHeader: (NSString*)name
{
GSMimeHeader *hdr;

hdr = [[headerClass alloc] initWithName: name
value: value
parameters: parameters];
hdr = [[GSMimeHeader alloc] initWithName: name
value: value
parameters: parameters];
[self setHeader: hdr];
RELEASE(hdr);
return hdr;
Expand Down Expand Up @@ -7504,9 +7493,9 @@ - (void) setContent: (id)newContent
GSMimeParser *p = AUTORELEASE([GSMimeParser new]);
NSScanner *scanner = [NSScanner scannerWithString: type];

hdr = [headerClass headerWithName: @"Content-Type"
value: nil
parameters: nil];
hdr = [GSMimeHeader headerWithName: @"Content-Type"
value: nil
parameters: nil];
if ([p scanHeaderBody: scanner into: hdr] == NO)
{
[NSException raise: NSInvalidArgumentException
Expand All @@ -7519,7 +7508,7 @@ - (void) setContent: (id)newContent
NSString *val;

val = [NSStringClass stringWithFormat: @"%@/%@", type, subtype];
hdr = [headerClass alloc];
hdr = [GSMimeHeader alloc];
hdr = [hdr initWithName: @"Content-Type" value: val parameters: nil];
[hdr setObject: type forKey: @"Type"];
[hdr setObject: subtype forKey: @"Subtype"];
Expand Down Expand Up @@ -7565,9 +7554,9 @@ - (void) setContentType: (NSString *)newType

p = AUTORELEASE([GSMimeParser new]);
scanner = [NSScanner scannerWithString: newType];
hdr = [headerClass headerWithName: @"Content-Type"
value: nil
parameters: nil];
hdr = [GSMimeHeader headerWithName: @"Content-Type"
value: nil
parameters: nil];
if ([p scanHeaderBody: scanner into: hdr] == NO)
{
[NSException raise: NSInvalidArgumentException
Expand Down Expand Up @@ -7600,7 +7589,7 @@ - (GSMimeHeader*) setHeader: (NSString*)name
{
GSMimeHeader *hdr;

hdr = [headerClass alloc];
hdr = [GSMimeHeader alloc];
hdr = [hdr initWithName: name
value: value
parameters: parameters];
Expand Down
14 changes: 10 additions & 4 deletions Source/NSBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,11 @@ + (NSString**) frameworkClasses;

if (localization)
{
primary = [primary stringByAppendingPathComponent:
[localization stringByAppendingPathExtension: @"lproj"]];
if ([localization length])
{
primary = [primary stringByAppendingPathComponent:
[localization stringByAppendingPathExtension: @"lproj"]];
}
contents = bundle_directory_readable(primary);
addBundlePath(array, contents, primary, nil, nil);
}
Expand All @@ -861,8 +864,11 @@ + (NSString**) frameworkClasses;
}
if (localization)
{
primary = [originalPrimary stringByAppendingPathComponent:
[localization stringByAppendingPathExtension: @"lproj"]];
if ([localization length])
{
primary = [originalPrimary stringByAppendingPathComponent:
[localization stringByAppendingPathExtension: @"lproj"]];
}
contents = bundle_directory_readable(primary);
addBundlePath(array, contents, primary, nil, nil);
}
Expand Down

0 comments on commit f236808

Please sign in to comment.