- some garbage collection fixes
* Misc.subproj/WebNSObjectExtras.h: (WebCFAutorelease): Replaced the old WebNSRetainCFRelease with this
much-easier-to-understand function cribbed from what David Harrison did in WebCore.
* Misc.subproj/WebKitNSStringExtras.m: (+[NSString _web_encodingForResource:]): Use CFRelease here to
get rid of an unnecessary use of WebNSRetainCFRelease.
* Misc.subproj/WebNSURLExtras.m:
(+[NSURL _web_URLWithData:relativeToURL:]): Use WebCFAutorelease instead of WebNSRetainCFRelease and autorelease.
(-[NSURL _web_URLWithLowercasedScheme]): Ditto.
(-[NSString _web_mapHostNameWithRange:encode:makeString:]): Use WebCFAutorelease here; the old code would not
work correctly under GC.
* Plugins.subproj/WebNetscapePluginPackage.m: (+[WebNetscapePluginPackage preferredLocalizationName]):
Use WebCFAutorelease here; the old code would not work correctly under GC.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8255
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2004-12-19 Darin Adler <darin@apple.com>
+
+ Reviewed by Kevin.
+
+ - some garbage collection fixes
+
+ * Misc.subproj/WebNSObjectExtras.h: (WebCFAutorelease): Replaced the old WebNSRetainCFRelease with this
+ much-easier-to-understand function cribbed from what David Harrison did in WebCore.
+
+ * Misc.subproj/WebKitNSStringExtras.m: (+[NSString _web_encodingForResource:]): Use CFRelease here to
+ get rid of an unnecessary use of WebNSRetainCFRelease.
+ * Misc.subproj/WebNSURLExtras.m:
+ (+[NSURL _web_URLWithData:relativeToURL:]): Use WebCFAutorelease instead of WebNSRetainCFRelease and autorelease.
+ (-[NSURL _web_URLWithLowercasedScheme]): Ditto.
+ (-[NSString _web_mapHostNameWithRange:encode:makeString:]): Use WebCFAutorelease here; the old code would not
+ work correctly under GC.
+ * Plugins.subproj/WebNetscapePluginPackage.m: (+[WebNetscapePluginPackage preferredLocalizationName]):
+ Use WebCFAutorelease here; the old code would not work correctly under GC.
+
2004-12-18 Chris Blumenberg <cblu@apple.com>
Fixed: <rdar://problem/3766915> PDF content needs search to work
}
NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
- NSString *locale = WebNSRetainCFRelease(CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName));
- if (locale == nil) {
+ CFStringRef locale = CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName);
+ if (locale == NULL) {
return NSMacOSRomanStringEncoding;
}
LangCode lang;
RegionCode region;
- error = LocaleStringToLangAndRegionCodes([locale UTF8String], &lang, ®ion);
- [locale release];
+ error = LocaleStringToLangAndRegionCodes([(NSString *)locale UTF8String], &lang, ®ion);
+ CFRelease(locale);
if (error != noErr) {
return NSMacOSRomanStringEncoding;
}
#import <Foundation/Foundation.h>
-static inline id WebNSRetainCFRelease(CFTypeRef obj)
+// Use WebCFAutorelease to return an object made by a CoreFoundation
+// "create" or "copy" function as an autoreleased and garbage collected
+// object. CF objects need to be "made collectable" for autorelease to work
+// properly under GC.
+
+static inline id WebCFAutorelease(CFTypeRef obj)
{
-#if BUILDING_ON_PANTHER
- return (id)obj;
-#else
- return (id)CFMakeCollectable(obj);
+#if !BUILDING_ON_PANTHER
+ if (obj) CFMakeCollectable(obj);
#endif
+ [(id)obj autorelease];
+ return (id)obj;
}
#if BUILDING_ON_PANTHER
// (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
// could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
// onto using ISO Latin 1 in those cases.
- result = WebNSRetainCFRelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
+ result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
if (!result) {
- result = WebNSRetainCFRelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
+ result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
}
- [result autorelease];
}
else {
result = [NSURL URLWithString:@""];
}
NSURL *result = changed
- ? [WebNSRetainCFRelease(CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES)) autorelease]
+ ? WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES))
: self;
if (buffer != static_buffer) {
NSString *string = self;
if (encode && [self rangeOfString:@"%" options:NSLiteralSearch range:range].location != NSNotFound) {
NSString *substring = [self substringWithRange:range];
- substring = (NSString *)CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)substring, CFSTR(""));
+ substring = WebCFAutorelease(CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)substring, CFSTR("")));
if (substring != nil) {
- string = [[substring retain] autorelease];
- CFRelease(substring);
range = NSMakeRange(0, [string length]);
}
}
#import <WebKit/WebKitLogging.h>
#import <WebKit/WebKitNSStringExtras.h>
+#import <WebKit/WebNSObjectExtras.h>
#import <JavaScriptCore/npruntime_impl.h>
CFStringEncoding stringEncoding;
CFBundleGetLocalizationInfoForLocalization(NULL, &languageCode, ®ionCode, &scriptCode, &stringEncoding);
- NSString *localizationName = (NSString *)CFBundleCopyLocalizationForLocalizationInfo(languageCode, regionCode, scriptCode, stringEncoding);
- return [localizationName autorelease];
+ return WebCFAutorelease(CFBundleCopyLocalizationForLocalizationInfo(languageCode, regionCode, scriptCode, stringEncoding));
}
- (SInt16)openResourceFile