X-Git-Url: https://git.saurik.com/apple/cf.git/blobdiff_plain/d8b101a4f6aa03fafcaee9105fbfdea9132c942c..d73847987a99375010c6d6ace0abb0a25cb9b034:/CFLocale.c diff --git a/CFLocale.c b/CFLocale.c index e8cc764..c0fc91e 100644 --- a/CFLocale.c +++ b/CFLocale.c @@ -2,14 +2,14 @@ * Copyright (c) 2014 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -17,12 +17,12 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ /* CFLocale.c - Copyright (c) 2002-2013, Apple Inc. All rights reserved. + Copyright (c) 2002-2014, Apple Inc. All rights reserved. Responsibility: David Smith */ @@ -142,7 +142,7 @@ static struct key_table __CFLocaleKeyTable[__kCFLocaleKeyTableCount] = { static CFLocaleRef __CFLocaleSystem = NULL; static CFMutableDictionaryRef __CFLocaleCache = NULL; -static CFSpinLock_t __CFLocaleGlobalLock = CFSpinLockInit; +static CFLock_t __CFLocaleGlobalLock = CFLockInit; struct __CFLocale { CFRuntimeBase _base; @@ -150,15 +150,17 @@ struct __CFLocale { CFMutableDictionaryRef _cache; CFMutableDictionaryRef _overrides; CFDictionaryRef _prefs; - CFSpinLock_t _lock; + CFLock_t _lock; Boolean _nullLocale; }; CF_PRIVATE Boolean __CFLocaleGetNullLocale(struct __CFLocale *locale) { + CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), Boolean, (NSLocale *)locale, _nullLocale); return locale->_nullLocale; } CF_PRIVATE void __CFLocaleSetNullLocale(struct __CFLocale *locale) { + CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), void, (NSLocale *)locale, _setNullLocale); locale->_nullLocale = true; } @@ -179,19 +181,19 @@ CF_INLINE void __CFLocaleSetType(CFLocaleRef locale, CFIndex type) { } CF_INLINE void __CFLocaleLockGlobal(void) { - __CFSpinLock(&__CFLocaleGlobalLock); + __CFLock(&__CFLocaleGlobalLock); } CF_INLINE void __CFLocaleUnlockGlobal(void) { - __CFSpinUnlock(&__CFLocaleGlobalLock); + __CFUnlock(&__CFLocaleGlobalLock); } CF_INLINE void __CFLocaleLock(CFLocaleRef locale) { - __CFSpinLock(&((struct __CFLocale *)locale)->_lock); + __CFLock(&((struct __CFLocale *)locale)->_lock); } CF_INLINE void __CFLocaleUnlock(CFLocaleRef locale) { - __CFSpinUnlock(&((struct __CFLocale *)locale)->_lock); + __CFUnlock(&((struct __CFLocale *)locale)->_lock); } @@ -249,20 +251,18 @@ static const CFRuntimeClass __CFLocaleClass = { __CFLocaleCopyDescription }; -static void __CFLocaleInitialize(void) { - CFIndex idx; - __kCFLocaleTypeID = _CFRuntimeRegisterClass(&__CFLocaleClass); - for (idx = 0; idx < __kCFLocaleKeyTableCount; idx++) { - // table fixup to workaround compiler/language limitations - __CFLocaleKeyTable[idx].key = *((CFStringRef *)__CFLocaleKeyTable[idx].key); - if (NULL != __CFLocaleKeyTable[idx].context) { - __CFLocaleKeyTable[idx].context = *((CFStringRef *)__CFLocaleKeyTable[idx].context); - } - } -} - CFTypeID CFLocaleGetTypeID(void) { - if (_kCFRuntimeNotATypeID == __kCFLocaleTypeID) __CFLocaleInitialize(); + static dispatch_once_t initOnce; + dispatch_once(&initOnce, ^{ + __kCFLocaleTypeID = _CFRuntimeRegisterClass(&__CFLocaleClass); // initOnce covered + for (CFIndex idx = 0; idx < __kCFLocaleKeyTableCount; idx++) { + // table fixup to workaround compiler/language limitations + __CFLocaleKeyTable[idx].key = *((CFStringRef *)__CFLocaleKeyTable[idx].key); + if (NULL != __CFLocaleKeyTable[idx].context) { + __CFLocaleKeyTable[idx].context = *((CFStringRef *)__CFLocaleKeyTable[idx].context); + } + } + }); return __kCFLocaleTypeID; } @@ -353,7 +353,7 @@ static CFLocaleRef _CFLocaleCopyCurrentGuts(CFStringRef name, Boolean useCache, locale->_cache = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks); locale->_overrides = NULL; locale->_prefs = prefs; - locale->_lock = CFSpinLockInit; + locale->_lock = CFLockInit; locale->_nullLocale = false; if (useCache) { @@ -432,7 +432,7 @@ CFLocaleRef CFLocaleCreate(CFAllocatorRef allocator, CFStringRef identifier) { locale->_cache = CFDictionaryCreateMutable(allocator, 0, NULL, &kCFTypeDictionaryValueCallBacks); locale->_overrides = NULL; locale->_prefs = NULL; - locale->_lock = CFSpinLockInit; + locale->_lock = CFLockInit; if (canCache) { if (NULL == __CFLocaleCache) { __CFLocaleCache = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); @@ -444,6 +444,7 @@ CFLocaleRef CFLocaleCreate(CFAllocatorRef allocator, CFStringRef identifier) { } CFLocaleRef CFLocaleCreateCopy(CFAllocatorRef allocator, CFLocaleRef locale) { + CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), CFLocaleRef, (NSLocale *)locale, copy); return (CFLocaleRef)CFRetain(locale); } @@ -948,7 +949,13 @@ static bool __CFLocaleCopyCalendarID(CFLocaleRef locale, bool user, CFTypeRef *c } else if (CFEqual(*cf, kCFCalendarIdentifierEthiopicAmeteAlem)) { CFRelease(*cf); *cf = CFRetain(kCFCalendarIdentifierEthiopicAmeteAlem); - } else { + } else if (CFEqual(*cf, kCFCalendarIdentifierIslamicTabular)) { + CFRelease(*cf); + *cf = CFRetain(kCFCalendarIdentifierIslamicTabular); + } else if (CFEqual(*cf, kCFCalendarIdentifierIslamicUmmAlQura)) { + CFRelease(*cf); + *cf = CFRetain(kCFCalendarIdentifierIslamicUmmAlQura); + } else { CFRelease(*cf); *cf = NULL; return false;