Skip to content

Replace calls to CFStringCreateWithCString with CFSTR macro #4717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions CoreFoundation/Base.subproj/CFPlatform.c
Original file line number Diff line number Diff line change
@@ -278,8 +278,11 @@ CF_PRIVATE CFStringRef _CFProcessNameString(void) {
static CFStringRef __CFProcessNameString = NULL;
if (!__CFProcessNameString) {
const char *processName = *_CFGetProgname();
if (!processName) processName = "";
CFStringRef newStr = CFStringCreateWithCString(kCFAllocatorSystemDefault, processName, kCFPlatformInterfaceStringEncoding);
CFStringRef newStr;
if (processName)
newStr = CFStringCreateWithCString(kCFAllocatorSystemDefault, processName, kCFPlatformInterfaceStringEncoding);
else
newStr = CFSTR("");
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
if (!OSAtomicCompareAndSwapPtrBarrier(NULL, (void *) newStr, (void * volatile *)& __CFProcessNameString)) {
@@ -392,7 +395,7 @@ CF_PRIVATE CFStringRef _CFStringCreateHostName(void) {
char myName[CFMaxHostNameSize];

// return @"" instead of nil a la CFUserName() and Ali Ozer
if (0 != gethostname(myName, CFMaxHostNameSize)) myName[0] = '\0';
if (0 != gethostname(myName, CFMaxHostNameSize)) return CFSTR("");
return CFStringCreateWithCString(kCFAllocatorSystemDefault, myName, kCFPlatformInterfaceStringEncoding);
}

2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
@@ -274,7 +274,7 @@ bool (*__CFObjCIsCollectable)(void *) = NULL;
// The constant string class reference is set at link time to _NSCFConstantString
void *__CFConstantStringClassReferencePtr = &_CF_CONSTANT_STRING_SWIFT_CLASS;
#else
#if !__CONSTANT_CFSTRINGS__
#ifndef __CONSTANT_CFSTRINGS__
// Compiler uses this symbol name; must match compiler built-in decl, so we use 'int'
#if TARGET_RT_64_BIT
int __CFConstantStringClassReference[24] = {0};
3 changes: 1 addition & 2 deletions CoreFoundation/Locale.subproj/CFDateFormatter.c
Original file line number Diff line number Diff line change
@@ -979,7 +979,7 @@ static CFMutableStringRef __createISO8601FormatString(CFISO8601DateFormatOptions
}

CFDateFormatterRef CFDateFormatterCreateISO8601Formatter(CFAllocatorRef allocator, CFISO8601DateFormatOptions formatOptions) {
CFStringRef localeStr = CFStringCreateWithCString(kCFAllocatorSystemDefault, "en_US_POSIX", kCFStringEncodingUTF8);
CFStringRef localeStr = CFSTR("en_US_POSIX");
CFLocaleRef locale = CFLocaleCreate(kCFAllocatorSystemDefault, localeStr);
CFDateFormatterRef ISO8601Formatter = __CreateCFDateFormatter(allocator, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle, kCFBooleanTrue); // dateStyle and timeStyle are not relevant for ISO8601

@@ -991,7 +991,6 @@ CFDateFormatterRef CFDateFormatterCreateISO8601Formatter(CFAllocatorRef allocato
}
}

CFRelease(localeStr);
CFRelease(locale);

return ISO8601Formatter;
2 changes: 1 addition & 1 deletion CoreFoundation/Preferences.subproj/CFPreferences.c
Original file line number Diff line number Diff line change
@@ -558,7 +558,7 @@ CF_PRIVATE CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFSt
return NULL;
}
if (hostName == kCFPreferencesAnyHost) {
suffix = CFStringCreateWithCString(prefAlloc, ".plist", kCFStringEncodingASCII);
suffix = CFSTR(".plist");
} else if (hostName == kCFPreferencesCurrentHost) {
CFStringRef hostID = _CFPreferencesGetByHostIdentifierString();
suffix = CFStringCreateWithFormat(prefAlloc, NULL, CFSTR(".%@.plist"), hostID);
4 changes: 2 additions & 2 deletions CoreFoundation/URL.subproj/CFURL.c
Original file line number Diff line number Diff line change
@@ -4058,9 +4058,9 @@ static CFStringRef WindowsPathToURLPath(CFStringRef path, CFAllocatorRef alloc,
CFArrayRef urlComponents;
CFStringRef str;

if (CFStringGetLength(path) == 0) return CFStringCreateWithCString(alloc, "", kCFStringEncodingASCII);
if (CFStringGetLength(path) == 0) return CFSTR("");
urlComponents = WindowsPathToURLComponents(path, alloc, isDir, isAbsolute);
if (!urlComponents) return CFStringCreateWithCString(alloc, "", kCFStringEncodingASCII);
if (!urlComponents) return CFSTR("");

// WindowsPathToURLComponents already added percent escapes for us; no need to add them again here.
str = CFStringCreateByCombiningStrings(alloc, urlComponents, CFSTR("/"));