__private_extern__ const wchar_t *_CFDLLPath(void) { static wchar_t cachedPath[MAX_PATH+1]; if (!bDllPathCached) { #ifdef _DEBUG // might be nice to get this from the project file at some point wchar_t *DLLFileName = L"CoreFoundation_debug.dll"; #else wchar_t *DLLFileName = L"CoreFoundation.dll"; #endif HMODULE ourModule = GetModuleHandleW(DLLFileName); CFAssert(ourModule, __kCFLogAssertion, "GetModuleHandle failed"); DWORD wResult = GetModuleFileNameW(ourModule, cachedPath, MAX_PATH+1); CFAssert1(wResult > 0, __kCFLogAssertion, "GetModuleFileName failed: %d", GetLastError()); CFAssert1(wResult < MAX_PATH+1, __kCFLogAssertion, "GetModuleFileName result truncated: %s", cachedPath); // strip off last component, the DLL name CFIndex idx; for (idx = wResult - 1; idx; idx--) { if ('\\' == cachedPath[idx]) { cachedPath[idx] = '\0'; break; } } bDllPathCached = true; } return cachedPath; }
CFPreferencesDomainRef _CFPreferencesDomainCreate(CFTypeRef context, const _CFPreferencesDomainCallBacks *callBacks) { CFAllocatorRef alloc = __CFPreferencesAllocator(); CFPreferencesDomainRef newDomain; CFAssert(callBacks != NULL && callBacks->createDomain != NULL && callBacks->freeDomain != NULL && callBacks->fetchValue != NULL && callBacks->writeValue != NULL, __kCFLogAssertion, "Cannot create a domain with NULL callbacks"); newDomain = (CFPreferencesDomainRef)_CFRuntimeCreateInstance(alloc, __kCFPreferencesDomainTypeID, sizeof(struct __CFPreferencesDomain) - sizeof(CFRuntimeBase), NULL); if (newDomain) { newDomain->_callBacks = callBacks; if (context) CFRetain(context); newDomain->_context = context; newDomain->_domain = callBacks->createDomain(alloc, context); } return newDomain; }
// we are expected to move mark & parserMark relative to any moved characters, set currentChar to the first new character fetched, update bufferLength, and advance currentByte as appropriate. Does not check for EOF; it is the caller's responsibility to verify this. static void fillCharacterBuffer(_CFXMLInputStream *stream) { if (!stream->charBuffer) { growCharacterBuffer(stream); } if (!stream->mark && !stream->parserMark) { // This is the easy case; we can freely overwrite the buffer; if either mark or parserMark is set, we must not remove any characters from those marks and the end of the buffer CFIndex fillLength = stream->bufferCapacity-5; // We leave a few characters at the end, b/c we don't want to reallocate (doubling the amount of memory used) just b/c we're matching a small string near the end of the filled buffer stream->bufferLength = loadCharacters(stream->charBuffer, fillLength, stream); CFAssert(stream->bufferLength != 0, __kCFLogAssertion, "CF internal error: XML parser input stream corruption"); stream->currentChar = stream->charBuffer; } else { // We do everything we can not to allocate; first we fill any remaining characters. If that doesn't work, we try shifting the characters starting at the earlier of mark or parserMark to the beginning of buffer, then filling the newly-freed characters. Boolean done; // First try just filling the remaining capacity done = (fillToCapacity(stream) != 0); if (!done) { const UniChar *leftMostMark; if (stream->mark && !stream->parserMark) { leftMostMark = stream->mark; } else if (stream->parserMark && !stream->mark) { leftMostMark = stream->parserMark; } else if (stream->parserMark < stream->mark) { leftMostMark = stream->parserMark; } else { leftMostMark = stream->mark; } if (leftMostMark > stream->charBuffer) { CFIndex delta = leftMostMark - stream->charBuffer; memmove(stream->charBuffer, leftMostMark, (stream->bufferLength - delta) * sizeof(UniChar)); stream->bufferLength -= delta; if (stream->mark) { stream->mark -= delta; } if (stream->parserMark) { stream->parserMark -= delta; } // Now try to fill the newly-opened space done = (fillToCapacity(stream) != 0); delta = loadCharacters(stream->charBuffer + stream->bufferLength, stream->bufferCapacity - stream->bufferLength, stream); } } if (!done) { // No help for it; now we must allocate growCharacterBuffer(stream); fillToCapacity(stream); // If this doesn't work, we give up. } } }
CF_PRIVATE void _inputStreamBackUpToMark(_CFXMLInputStream *stream) { CFAssert(stream->mark != NULL || stream->charBuffer == NULL, __kCFLogAssertion, "CF internal error: malformed XML input stream"); restoreToMark(stream, stream->mark); }
CF_PRIVATE void _inputStreamGetCharactersFromMark(_CFXMLInputStream *stream, CFMutableStringRef string) { UniChar *end = stream->currentChar ? stream->currentChar : stream->charBuffer + stream->bufferLength; CFIndex numChars = end - stream->mark; CFAssert(stream->mark, __kCFLogAssertion, "CF internal error: malformed XML input stream"); _fillStringWithCharacters(string, stream->mark, numChars); }
CF_PRIVATE void _inputStreamClearMark(_CFXMLInputStream *stream) { CFAssert(stream->mark != NULL, __kCFLogAssertion, "CF internal error: parser input stream malformed"); stream->mark = NULL; }
__private_extern__ void _inputStreamSetMark(_CFXMLInputStream *stream) { CFAssert(stream->mark == NULL, __kCFLogAssertion, "CF internal error: parser input stream malformed"); stream->mark = dropMark(stream); }
CF_INLINE void __CFArrayValidateRange(CFArrayRef array, CFRange range, const char *func) { CFAssert(0 <= range.location && range.location <= CFArrayGetCount(array), __kCFLogAssertion, "%s(): range.location index (%d) out of bounds (0, %d)", func, range.location, CFArrayGetCount(array)); CFAssert(0 <= range.length, __kCFLogAssertion, "%s(): range.length (%d) cannot be less than zero", func, range.length); CFAssert(range.location + range.length <= CFArrayGetCount(array), __kCFLogAssertion, "%s(): ending index (%d) out of bounds (0, %d)", func, range.location + range.length, CFArrayGetCount(array)); }
static void __CFNullDeallocate(CFTypeRef cf) { CFAssert(false, __kCFLogAssertion, "Deallocated CFNull!"); }
static void __CFBooleanDeallocate(CFTypeRef cf) { CFAssert(false, __kCFLogAssertion, "Deallocated CFBoolean!"); }
CF_INLINE void __CFDataValidateRange(CFDataRef data, CFRange range, const char *func) { CFAssert(0 <= range.location && range.location <= __CFDataLength(data), __kCFLogAssertion, "%s(): range.location index (%d) out of bounds", func, range.location); CFAssert(0 <= range.length, __kCFLogAssertion, "%s(): length (%d) cannot be less than zero", func, range.length); CFAssert(range.location + range.length <= __CFDataLength(data), __kCFLogAssertion, "%s(): ending index (%d) out of bounds", func, range.location + range.length); }