* 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,
* 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@
*/
/* CFStringEncodingConverter.c
- Copyright (c) 1998-2013, Apple Inc. All rights reserved.
+ Copyright (c) 1998-2014, Apple Inc. All rights reserved.
Responsibility: Aki Inoue
*/
const _CFEncodingConverter **commonConverterSlot = NULL;
static _CFEncodingConverter *commonConverters[3] = {NULL, NULL, NULL}; // UTF8, MacRoman/WinLatin1, and the default encoding*
static CFMutableDictionaryRef mappingTable = NULL;
- static CFSpinLock_t lock = CFSpinLockInit;
+ static OSSpinLock lock = OS_SPINLOCK_INIT;
switch (encoding) {
case kCFStringEncodingUTF8: commonConverterSlot = (const _CFEncodingConverter **)&(commonConverters[0]); break;
default: if (CFStringGetSystemEncoding() == encoding) commonConverterSlot = (const _CFEncodingConverter **)&(commonConverters[2]); break;
}
- __CFSpinLock(&lock);
+ OSSpinLockLock(&lock);
converter = ((NULL == commonConverterSlot) ? ((NULL == mappingTable) ? NULL : (const _CFEncodingConverter *)CFDictionaryGetValue(mappingTable, (const void *)(uintptr_t)encoding)) : *commonConverterSlot);
- __CFSpinUnlock(&lock);
+ OSSpinLockUnlock(&lock);
if (NULL == converter) {
const CFStringEncodingConverter *definition = __CFStringEncodingConverterGetDefinition(encoding);
if (NULL != definition) {
- __CFSpinLock(&lock);
+ OSSpinLockLock(&lock);
converter = ((NULL == commonConverterSlot) ? ((NULL == mappingTable) ? NULL : (const _CFEncodingConverter *)CFDictionaryGetValue(mappingTable, (const void *)(uintptr_t)encoding)) : *commonConverterSlot);
if (NULL == converter) {
*commonConverterSlot = converter;
}
}
- __CFSpinUnlock(&lock);
+ OSSpinLockUnlock(&lock);
}
}
CFIndex localUsedLen;
localUsedByteLen = 0;
- while ((usedLen < numChars) && !localUsedByteLen && (localUsedLen = TO_BYTE_FALLBACK(converter, characters + usedLen, numChars - usedLen, NULL, 0, &localUsedByteLen))) usedLen += localUsedLen;
+ while ((usedLen < numChars && theUsedByteLen < maxByteLen) && !localUsedByteLen && (localUsedLen = TO_BYTE_FALLBACK(converter, characters + usedLen, numChars - usedLen, NULL, 0, &localUsedByteLen))) usedLen += localUsedLen;
+
+ theUsedByteLen += localUsedByteLen;
}
if (usedLen < numChars) theResult = kCFStringEncodingInsufficientOutputBufferLength;
break;
CFIndex localUsedLen;
localUsedByteLen = 0;
- while ((usedLen < numChars) && !localUsedByteLen && (localUsedLen = TO_BYTE_FALLBACK(converter, characters + usedLen, numChars - usedLen, NULL, 0, &localUsedByteLen))) usedLen += localUsedLen;
+ while ((usedLen < numChars && theUsedByteLen < maxByteLen) && !localUsedByteLen && (localUsedLen = TO_BYTE_FALLBACK(converter, characters + usedLen, numChars - usedLen, NULL, 0, &localUsedByteLen))) usedLen += localUsedLen;
+
+ theUsedByteLen += localUsedByteLen;
}
if (usedLen < numChars) theResult = kCFStringEncodingInsufficientOutputBufferLength;
}