From 4c91a73d097ee1413f0eb1002c25b91869124a26 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Oct 2005 22:39:54 +0000 Subject: [PATCH] CF-368.18.tar.gz --- Base.subproj/CFBase.c | 2 + Base.subproj/CFBase.h | 6 +- Makefile | 2 +- NumberDate.subproj/CFDate.c | 20 +++--- PlugIn.subproj/CFBundle.c | 20 +++--- PlugIn.subproj/CFBundle_Internal.h | 4 +- PlugIn.subproj/CFBundle_Resources.c | 14 ++-- .../CFApplicationPreferences.c | 6 ++ Preferences.subproj/CFPreferences.c | 2 + Preferences.subproj/CFXMLPreferencesDomain.c | 29 +++++++- RunLoop.subproj/CFMachPort.c | 69 ++++++++++--------- String.subproj/CFString.c | 2 +- 12 files changed, 110 insertions(+), 66 deletions(-) diff --git a/Base.subproj/CFBase.c b/Base.subproj/CFBase.c index 92691f9..c807675 100644 --- a/Base.subproj/CFBase.c +++ b/Base.subproj/CFBase.c @@ -722,6 +722,7 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context context->reallocate = __CFAllocatorGetReallocateFunction(&allocator->_context); context->deallocate = __CFAllocatorGetDeallocateFunction(&allocator->_context); context->preferredSize = __CFAllocatorGetPreferredSizeFunction(&allocator->_context); +#if defined(__ppc__) context->retain = (void *)((uintptr_t)context->retain & ~0x3); context->release = (void *)((uintptr_t)context->release & ~0x3); context->copyDescription = (void *)((uintptr_t)context->copyDescription & ~0x3); @@ -729,6 +730,7 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context context->reallocate = (void *)((uintptr_t)context->reallocate & ~0x3); context->deallocate = (void *)((uintptr_t)context->deallocate & ~0x3); context->preferredSize = (void *)((uintptr_t)context->preferredSize & ~0x3); +#endif } void *_CFAllocatorAllocateGC(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint) diff --git a/Base.subproj/CFBase.h b/Base.subproj/CFBase.h index 1de0fff..7bc8b60 100644 --- a/Base.subproj/CFBase.h +++ b/Base.subproj/CFBase.h @@ -130,8 +130,10 @@ extern "C" { #endif #if !defined(CF_INLINE) - #if defined(__GNUC__) - #define CF_INLINE static __inline__ + #if defined(__GNUC__) && (__GNUC__ == 4) + #define CF_INLINE static __inline__ __attribute__((always_inline)) + #elif defined(__GNUC__) + #define CF_INLINE static __inline__ #elif defined(__MWERKS__) || defined(__cplusplus) #define CF_INLINE static inline #elif defined(_MSC_VER) diff --git a/Makefile b/Makefile index 801a306..4685bde 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ include framework.make # Misc additional options # -CURRENT_PROJECT_VERSION = 368.11 +CURRENT_PROJECT_VERSION = 368.18 # common items all build styles should be defining CFLAGS += -DCF_BUILDING_CF=1 diff --git a/NumberDate.subproj/CFDate.c b/NumberDate.subproj/CFDate.c index 557e2d3..3f774f0 100644 --- a/NumberDate.subproj/CFDate.c +++ b/NumberDate.subproj/CFDate.c @@ -245,13 +245,17 @@ static void __CFYMDFromAbsolute(int32_t absolute, int32_t *year, int8_t *month, } /* year arg is absolute year; Gregorian 2001 == year 0; 2001/1/1 = absolute date 0 */ -static int32_t __CFAbsoluteFromYMD(int32_t year, int8_t month, int8_t day) { - int32_t absolute = 0, idx; +static double __CFAbsoluteFromYMD(int32_t year, int8_t month, int8_t day) { + double absolute = 0.0; + int32_t idx; + int32_t b = year / 400; // take care of as many multiples of 400 years as possible + absolute += b * 146097.0; + year -= b * 400; if (year < 0) { for (idx = year; idx < 0; idx++) absolute -= __CFDaysAfterMonth(0, idx, isleap(idx)); } else { - for (idx = year - 1; 0 <= idx; idx--) + for (idx = 0; idx < year; idx++) absolute += __CFDaysAfterMonth(0, idx, isleap(idx)); } /* Now add the days into the original year */ @@ -451,7 +455,6 @@ SInt32 CFAbsoluteTimeGetDayOfYear(CFAbsoluteTime at, CFTimeZoneRef tz) { SInt32 CFAbsoluteTimeGetWeekOfYear(CFAbsoluteTime at, CFTimeZoneRef tz) { int32_t absolute, year; int8_t month, day; - int32_t absolute0101, dow0101; CFAbsoluteTime fixedat; if (NULL != tz) { __CFGenericValidateType(tz, CFTimeZoneGetTypeID()); @@ -459,8 +462,8 @@ SInt32 CFAbsoluteTimeGetWeekOfYear(CFAbsoluteTime at, CFTimeZoneRef tz) { fixedat = at + (NULL != tz ? CFTimeZoneGetSecondsFromGMT(tz, at) : 0.0); absolute = (int32_t)(float)floor(fixedat / 86400.0); __CFYMDFromAbsolute(absolute, &year, &month, &day); - absolute0101 = __CFAbsoluteFromYMD(year, 1, 1); - dow0101 = (absolute0101 < 0) ? ((absolute0101 + 1) % 7 + 7) : (absolute0101 % 7 + 1); + double absolute0101 = __CFAbsoluteFromYMD(year, 1, 1); + int32_t dow0101 = __CFDoubleModToInt(absolute0101, 7) + 1; /* First three and last three days of a year can end up in a week of a different year */ if (1 == month && day < 4) { if ((day < 4 && 5 == dow0101) || (day < 3 && 6 == dow0101) || (day < 2 && 7 == dow0101)) { @@ -468,9 +471,8 @@ SInt32 CFAbsoluteTimeGetWeekOfYear(CFAbsoluteTime at, CFTimeZoneRef tz) { } } if (12 == month && 28 < day) { - int32_t absolute20101, dow20101; - absolute20101 = __CFAbsoluteFromYMD(year + 1, 1, 1); - dow20101 = (absolute20101 < 0) ? ((absolute20101 + 1) % 7 + 7) : (absolute20101 % 7 + 1); + double absolute20101 = __CFAbsoluteFromYMD(year + 1, 1, 1); + int32_t dow20101 = __CFDoubleModToInt(absolute20101, 7) + 1; if ((28 < day && 4 == dow20101) || (29 < day && 3 == dow20101) || (30 < day && 2 == dow20101)) { return 1; } diff --git a/PlugIn.subproj/CFBundle.c b/PlugIn.subproj/CFBundle.c index b46201d..3586455 100644 --- a/PlugIn.subproj/CFBundle.c +++ b/PlugIn.subproj/CFBundle.c @@ -2286,12 +2286,12 @@ Boolean CFBundleLoadExecutable(CFBundleRef bundle) { switch (bundle->_binaryType) { -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) case __CFBundleCFMBinary: case __CFBundleUnreadableBinary: result = _CFBundleCFMLoad(bundle); break; -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DYLD) case __CFBundleDYLDBundleBinary: result = _CFBundleDYLDLoadBundle(bundle); @@ -2343,11 +2343,11 @@ void CFBundleUnloadExecutable(CFBundleRef bundle) { _CFPlugInWillUnload(bundle); switch (bundle->_binaryType) { -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) case __CFBundleCFMBinary: _CFBundleCFMUnload(bundle); break; -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DYLD) case __CFBundleDYLDBundleBinary: _CFBundleDYLDUnloadBundle(bundle); @@ -2417,11 +2417,11 @@ void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef funcName } switch (bundle->_binaryType) { -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) case __CFBundleCFMBinary: tvp = _CFBundleCFMGetSymbolByName(bundle, funcName, kTVectorCFragSymbol); break; -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DYLD) case __CFBundleDYLDBundleBinary: case __CFBundleDYLDFrameworkBinary: @@ -2461,11 +2461,11 @@ void *_CFBundleGetCFMFunctionPointerForName(CFBundleRef bundle, CFStringRef func } switch (bundle->_binaryType) { -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) case __CFBundleCFMBinary: return _CFBundleCFMGetSymbolByName(bundle, funcName, kTVectorCFragSymbol); break; -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DYLD) case __CFBundleDYLDBundleBinary: case __CFBundleDYLDFrameworkBinary: @@ -2522,11 +2522,11 @@ void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName) } switch (bundle->_binaryType) { -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) case __CFBundleCFMBinary: dp = _CFBundleCFMGetSymbolByName(bundle, symbolName, kDataCFragSymbol); break; -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DYLD) case __CFBundleDYLDBundleBinary: case __CFBundleDYLDFrameworkBinary: diff --git a/PlugIn.subproj/CFBundle_Internal.h b/PlugIn.subproj/CFBundle_Internal.h index 6b94916..503bf36 100644 --- a/PlugIn.subproj/CFBundle_Internal.h +++ b/PlugIn.subproj/CFBundle_Internal.h @@ -114,7 +114,7 @@ extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsIfChanged(void); extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsForHint(CFStringRef hint); #endif -#if defined(BINARY_SUPPORT_CFM) +#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__) // CFM API #if defined(__MACOS8__) #include @@ -125,7 +125,7 @@ extern void _CFBundleCFMConnect(CFBundleRef bundle); extern void _CFBundleCFMUnload(CFBundleRef bundle); extern void *__CFBundleCFMGetSymbol(void *connID, ConstStr255Param name, CFragSymbolClass class); extern void *_CFBundleCFMGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName, CFragSymbolClass class); -#endif /* BINARY_SUPPORT_CFM */ +#endif /* BINARY_SUPPORT_CFM && __ppc__ */ #if defined(BINARY_SUPPORT_DLL) extern Boolean _CFBundleDLLLoad(CFBundleRef bundle); diff --git a/PlugIn.subproj/CFBundle_Resources.c b/PlugIn.subproj/CFBundle_Resources.c index c2bce54..cd21ecd 100644 --- a/PlugIn.subproj/CFBundle_Resources.c +++ b/PlugIn.subproj/CFBundle_Resources.c @@ -1962,22 +1962,22 @@ static Boolean _CFBundleGetPackageInfoInDirectoryWithInfoDictionary(CFAllocatorR startOfExtension = _CFStartOfPathExtension(buff, strLen); if (((strLen - startOfExtension == 4) || (strLen - startOfExtension == 5)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'a') && (buff[startOfExtension+2] == (UniChar)'p') && (buff[startOfExtension+3] == (UniChar)'p') && ((strLen - startOfExtension == 4) || (buff[startOfExtension+4] == (UniChar)'/'))) { // This is an app - *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL' + *packageType = 0x4150504c; // 'APPL' } else if (((strLen - startOfExtension == 6) || (strLen - startOfExtension == 7)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'d') && (buff[startOfExtension+2] == (UniChar)'e') && (buff[startOfExtension+3] == (UniChar)'b') && (buff[startOfExtension+4] == (UniChar)'u') && (buff[startOfExtension+5] == (UniChar)'g') && ((strLen - startOfExtension == 6) || (buff[startOfExtension+6] == (UniChar)'/'))) { // This is an app (debug version) - *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL' + *packageType = 0x4150504c; // 'APPL' } else if (((strLen - startOfExtension == 8) || (strLen - startOfExtension == 9)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'p') && (buff[startOfExtension+2] == (UniChar)'r') && (buff[startOfExtension+3] == (UniChar)'o') && (buff[startOfExtension+4] == (UniChar)'f') && (buff[startOfExtension+5] == (UniChar)'i') && (buff[startOfExtension+6] == (UniChar)'l') && (buff[startOfExtension+7] == (UniChar)'e') && ((strLen - startOfExtension == 8) || (buff[startOfExtension+8] == (UniChar)'/'))) { // This is an app (profile version) - *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL' + *packageType = 0x4150504c; // 'APPL' } else if (((strLen - startOfExtension == 8) || (strLen - startOfExtension == 9)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'s') && (buff[startOfExtension+2] == (UniChar)'e') && (buff[startOfExtension+3] == (UniChar)'r') && (buff[startOfExtension+4] == (UniChar)'v') && (buff[startOfExtension+5] == (UniChar)'i') && (buff[startOfExtension+6] == (UniChar)'c') && (buff[startOfExtension+7] == (UniChar)'e') && ((strLen - startOfExtension == 8) || (buff[startOfExtension+8] == (UniChar)'/'))) { // This is a service - *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL' + *packageType = 0x4150504c; // 'APPL' } else if (((strLen - startOfExtension == 10) || (strLen - startOfExtension == 11)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'f') && (buff[startOfExtension+2] == (UniChar)'r') && (buff[startOfExtension+3] == (UniChar)'a') && (buff[startOfExtension+4] == (UniChar)'m') && (buff[startOfExtension+5] == (UniChar)'e') && (buff[startOfExtension+6] == (UniChar)'w') && (buff[startOfExtension+7] == (UniChar)'o') && (buff[startOfExtension+8] == (UniChar)'r') && (buff[startOfExtension+9] == (UniChar)'k') && ((strLen - startOfExtension == 10) || (buff[startOfExtension+10] == (UniChar)'/'))) { // This is a framework - *packageType = CFSwapInt32BigToHost(0x464d574b); // 'FMWK' + *packageType = 0x464d574b; // 'FMWK' } else { // Default to BNDL for generic bundle - *packageType = CFSwapInt32BigToHost(0x424e444C); // 'BNDL' + *packageType = 0x424e444c; // 'BNDL' } } retVal = true; @@ -1992,7 +1992,7 @@ CF_EXPORT void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, U CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); if (!_CFBundleGetPackageInfoInDirectoryWithInfoDictionary(CFGetAllocator(bundle), bundleURL, CFBundleGetInfoDictionary(bundle), packageType, packageCreator)) { if (packageType != NULL) { - *packageType = CFSwapInt32BigToHost(0x424e444C); // 'BNDL' + *packageType = 0x424e444c; // 'BNDL' } if (packageCreator != NULL) { *packageCreator = 0x3f3f3f3f; // '????' diff --git a/Preferences.subproj/CFApplicationPreferences.c b/Preferences.subproj/CFApplicationPreferences.c index f18b93a..764e68c 100644 --- a/Preferences.subproj/CFApplicationPreferences.c +++ b/Preferences.subproj/CFApplicationPreferences.c @@ -378,6 +378,11 @@ void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef d void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName) { CFPreferencesDomainRef appDomain; + void *defs = NULL; + __CFSpinLock(&userDefaultsLock); + defs = userDefaults; + __CFSpinUnlock(&userDefaultsLock); + CF_OBJC_KVO_WILLCHANGE(defs, defaultName); __CFSpinLock(&__CFApplicationPreferencesLock); appDomain = _CFPreferencesStandardDomain(self->_appName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if(appDomain) { @@ -388,6 +393,7 @@ void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRe } } __CFSpinUnlock(&__CFApplicationPreferencesLock); + CF_OBJC_KVO_DIDCHANGE(defs, defaultName); } static Boolean _CFApplicationPreferencesSynchronizeNoLock(_CFApplicationPreferences *self) { diff --git a/Preferences.subproj/CFPreferences.c b/Preferences.subproj/CFPreferences.c index 1d31eae..abfcd21 100644 --- a/Preferences.subproj/CFPreferences.c +++ b/Preferences.subproj/CFPreferences.c @@ -86,6 +86,8 @@ CF_EXPORT void CFPreferencesDumpMem(void) { } #endif +static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef domainName, CFStringRef userName, CFStringRef hostName, unsigned long safeLevel); + static unsigned long __CFSafeLaunchLevel = 0; static CFURLRef _preferencesDirectoryForUserHostSafetyLevel(CFStringRef userName, CFStringRef hostName, unsigned long safeLevel) { diff --git a/Preferences.subproj/CFXMLPreferencesDomain.c b/Preferences.subproj/CFXMLPreferencesDomain.c index e259c44..c2473b9 100644 --- a/Preferences.subproj/CFXMLPreferencesDomain.c +++ b/Preferences.subproj/CFXMLPreferencesDomain.c @@ -289,15 +289,29 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes int fd = -1; char auxPath[CFMaxPathSize + 16]; char cpath[CFMaxPathSize]; - int fsyncErr = 0; + uid_t owner = getuid(); + gid_t group = getgid(); + Boolean writingFileAsRoot = ((getuid() != geteuid()) && (geteuid() == 0)); if (!CFURLGetFileSystemRepresentation(url, true, cpath, CFMaxPathSize)) { return false; } - if (-1 == mode) { + + if (-1 == mode || writingFileAsRoot) { struct stat statBuf; - mode = (0 == stat(cpath, &statBuf)) ? statBuf.st_mode : 0600; + if (0 == stat(cpath, &statBuf)) { + mode = statBuf.st_mode; + owner = statBuf.st_uid; + group = statBuf.st_gid; + } else { + mode = 0664; + if (writingFileAsRoot && (0 == strncmp(cpath, "/Library/Preferences", 20))) { + owner = geteuid(); + group = 80; + } + } } + if (atomic) { CFURLRef dir = CFURLCreateCopyDeletingLastPathComponent(NULL, url); CFURLRef tempFile = CFURLCreateCopyAppendingPathComponent(NULL, dir, CFSTR("cf#XXXXX"), false); @@ -311,7 +325,9 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes } else { fd = open(cpath, O_WRONLY|O_CREAT|O_TRUNC, mode); } + if (fd < 0) return false; + if (length && (write(fd, bytes, length) != length || fsync(fd) < 0)) { int saveerr = thread_errno(); close(fd); @@ -320,7 +336,9 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes thread_set_errno(saveerr); return false; } + close(fd); + if (atomic) { // preserve the mode as passed in originally chmod(auxPath, mode); @@ -329,6 +347,11 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes unlink(auxPath); return false; } + + // If the file was renamed successfully and we wrote it as root we need to reset the owner & group as they were. + if (writingFileAsRoot) { + chown(cpath, owner, group); + } } return true; } diff --git a/RunLoop.subproj/CFMachPort.c b/RunLoop.subproj/CFMachPort.c index 9cf96d8..50d1c35 100644 --- a/RunLoop.subproj/CFMachPort.c +++ b/RunLoop.subproj/CFMachPort.c @@ -143,6 +143,7 @@ #include #include #include +#include #include #include #include @@ -266,38 +267,44 @@ void _CFMachPortInstallNotifyPort(CFRunLoopRef rl, CFStringRef mode) { static void __CFNotifyDeadMachPort(CFMachPortRef port, void *msg, CFIndex size, void *info) { mach_msg_header_t *header = (mach_msg_header_t *)msg; if (header && header->msgh_id == MACH_NOTIFY_DEAD_NAME) { - mach_port_t dead_port = ((mach_dead_name_notification_t *)msg)->not_port; - CFMachPortRef existing; - /* If the CFMachPort has already been invalidated, it won't be found here. */ - __CFSpinLock(&__CFAllMachPortsLock); - if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) { - CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port); - CFRetain(existing); - __CFSpinUnlock(&__CFAllMachPortsLock); - CFMachPortInvalidate(existing); - CFRelease(existing); - } else { - __CFSpinUnlock(&__CFAllMachPortsLock); - } - /* Delete port reference we got for this notification */ - mach_port_deallocate(mach_task_self(), dead_port); + mach_port_t dead_port = ((mach_dead_name_notification_t *)msg)->not_port; + if (((mach_dead_name_notification_t *)msg)->NDR.int_rep != NDR_record.int_rep) { + dead_port = CFSwapInt32(dead_port); + } + CFMachPortRef existing; + /* If the CFMachPort has already been invalidated, it won't be found here. */ + __CFSpinLock(&__CFAllMachPortsLock); + if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) { + CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port); + CFRetain(existing); + __CFSpinUnlock(&__CFAllMachPortsLock); + CFMachPortInvalidate(existing); + CFRelease(existing); + } else { + __CFSpinUnlock(&__CFAllMachPortsLock); + } + /* Delete port reference we got for this notification */ + mach_port_deallocate(mach_task_self(), dead_port); } else if (header && header->msgh_id == MACH_NOTIFY_PORT_DELETED) { - mach_port_t dead_port = ((mach_port_deleted_notification_t *)msg)->not_port; - CFMachPortRef existing; - /* If the CFMachPort has already been invalidated, it won't be found here. */ - __CFSpinLock(&__CFAllMachPortsLock); - if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) { - CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port); - CFRetain(existing); - __CFSpinUnlock(&__CFAllMachPortsLock); - CFMachPortInvalidate(existing); - CFRelease(existing); - } else { - __CFSpinUnlock(&__CFAllMachPortsLock); - } - /* Delete port reference we got for this notification */ -// Don't do this, since this always fails, and could cause trouble -// mach_port_deallocate(mach_task_self(), dead_port); + mach_port_t dead_port = ((mach_port_deleted_notification_t *)msg)->not_port; + if (((mach_dead_name_notification_t *)msg)->NDR.int_rep != NDR_record.int_rep) { + dead_port = CFSwapInt32(dead_port); + } + CFMachPortRef existing; + /* If the CFMachPort has already been invalidated, it won't be found here. */ + __CFSpinLock(&__CFAllMachPortsLock); + if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) { + CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port); + CFRetain(existing); + __CFSpinUnlock(&__CFAllMachPortsLock); + CFMachPortInvalidate(existing); + CFRelease(existing); + } else { + __CFSpinUnlock(&__CFAllMachPortsLock); + } + /* Delete port reference we got for this notification */ + // Don't do this, since this always fails, and could cause trouble + // mach_port_deallocate(mach_task_self(), dead_port); } } diff --git a/String.subproj/CFString.c b/String.subproj/CFString.c index 881f27a..685075b 100644 --- a/String.subproj/CFString.c +++ b/String.subproj/CFString.c @@ -2620,7 +2620,7 @@ Boolean CFStringFindWithOptions(CFStringRef string, CFStringRef stringToFind, CF // this is assuming viramas are only in BMP ??? if ((str1Char == COMBINING_GRAPHEME_JOINER) || (otherChar == COMBINING_GRAPHEME_JOINER) || (otherChar == ZERO_WIDTH_JOINER) || ((otherChar >= HANGUL_CHOSEONG_START) && (otherChar <= HANGUL_JONGSEONG_END)) || (CFUniCharGetCombiningPropertyForCharacter(otherChar, combClassBMP) == 9)) { - CFRange clusterRange = CFStringGetRangeOfCharacterClusterAtIndex(string, str1Index, kCFStringGramphemeCluster); + CFRange clusterRange = CFStringGetRangeOfCharacterClusterAtIndex(string, str1Index - 1, kCFStringGramphemeCluster); if (str1Index < (clusterRange.location + clusterRange.length)) match = false; } -- 2.45.2