本文整理匯總了C++中CFAllocatorDeallocate函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFAllocatorDeallocate函數的具體用法?C++ CFAllocatorDeallocate怎麽用?C++ CFAllocatorDeallocate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFAllocatorDeallocate函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: SQLite3InsertWithTableNameAndDictionary
// Insert values into the table from a CFDictionary.
//
// If the number of key-values pairs in the dictionary is zero, insert is ignored.
//
// Example:
//
// NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: @"Mirek", @"name",
// @"Rusin", @"surname"];
//
// SQLite3InsertWithDictionary(connection, CFSTR("users"), (CFDictionaryRef)attributes);
//
// TODO:
// - sanitize table name and keys
// - return values for binding
inline SQLite3Status SQLite3InsertWithTableNameAndDictionary(SQLite3ConnectionRef connection, CFStringRef table, CFDictionaryRef dictionary) {
SQLite3Status status = kSQLite3StatusError;
CFIndex n = CFDictionaryGetCount(dictionary);
const void **keys = CFAllocatorAllocate(connection->allocator, sizeof(void *) * n, 0);
const void **values = CFAllocatorAllocate(connection->allocator, sizeof(void *) * n, 0);
CFDictionaryGetKeysAndValues(dictionary, keys, values);
CFArrayRef keysArray = CFArrayCreate(connection->allocator, keys, n, &kCFTypeArrayCallBacks);
CFArrayRef valuesArray = CFArrayCreate(connection->allocator, values, n, &kCFTypeArrayCallBacks);
CFStringRef keysString = CFStringCreateByCombiningStrings(connection->allocator, keysArray, CFSTR(", "));
const char *valuesCString = _SQLite3CreateValuesPlaceholderCString(connection->allocator, n);
CFStringRef sql = CFStringCreateWithFormat(connection->allocator, NULL, CFSTR("INSERT INTO %@(%@) VALUES(%s)"), table, keysString, valuesCString);
SQLite3StatementRef statement = SQLite3StatementCreate(connection, sql);
if (statement) {
SQLite3StatementBindArray(statement, valuesArray);
status = SQLite3StatementStep(statement);
SQLite3StatementReset(statement);
SQLite3StatementClearBindings(statement);
SQLite3StatementFinalize(statement);
SQLite3StatementRelease(statement);
}
CFRelease(sql);
CFAllocatorDeallocate(connection->allocator, (void *)valuesCString);
CFRelease(keysString);
CFRelease(valuesArray);
CFRelease(keysArray);
CFAllocatorDeallocate(connection->allocator, keys);
CFAllocatorDeallocate(connection->allocator, values);
return status;
}
示例2: __JSONParserAppendMapEnd
inline int __JSONParserAppendMapEnd(void *context) {
int success = 0;
__JSONRef json = (__JSONRef)context;
__JSONStackEntryRef entry = __JSONStackPop(json->stack);
if (entry) {
if (entry->keysIndex == entry->valuesIndex) {
CFTypeRef *keys = __JSONStackEntryCreateKeys(entry, json->elements);
if (keys) {
CFTypeRef *values = __JSONStackEntryCreateValues(entry, json->elements);
if (values) {
json->elements[entry->index] = CFDictionaryCreate(json->allocator, keys, values, entry->keysIndex, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFAllocatorDeallocate(entry->allocator, values);
success = 1;
}
CFAllocatorDeallocate(entry->allocator, keys);
}
} else {
// TODO: The number of keys and values does not match
}
__JSONStackEntryRelease(entry);
} else {
// TODO: Container on the stack can't be NULL (too deep?)
}
return success;
}
示例3: CFStringCompareWithOptionsAndLocale
CFComparisonResult
CFStringCompareWithOptionsAndLocale (CFStringRef str1,
CFStringRef str2, CFRange rangeToCompare,
CFStringCompareFlags compareOptions, CFLocaleRef locale)
{
CFComparisonResult ret;
UniChar *string1;
UniChar *string2;
CFIndex length1;
CFIndex length2;
CFAllocatorRef alloc;
UCollator *ucol;
alloc = CFAllocatorGetDefault ();
length1 = rangeToCompare.length;
string1 = CFAllocatorAllocate (alloc, (length1) * sizeof(UniChar), 0);
CFStringGetCharacters (str1, rangeToCompare, string1);
length2 = CFStringGetLength (str2);
string2 = CFAllocatorAllocate (alloc, (length2) * sizeof(UniChar), 0);
CFStringGetCharacters (str2, CFRangeMake(0, length2), string2);
ucol = CFStringICUCollatorOpen (compareOptions, locale);
ret = ucol_strcoll (ucol, string2, length2, string1, length1);
CFStringICUCollatorClose (ucol);
CFAllocatorDeallocate (alloc, string1);
CFAllocatorDeallocate (alloc, string2);
return ret;
}
示例4: SCNetworkSetCopyAll
CFArrayRef /* of SCNetworkSetRef's */
SCNetworkSetCopyAll(SCPreferencesRef prefs)
{
CFMutableArrayRef array;
CFIndex n;
CFStringRef path;
CFDictionaryRef sets;
path = SCPreferencesPathKeyCreateSets(NULL);
sets = SCPreferencesPathGetValue(prefs, path);
CFRelease(path);
if ((sets != NULL) && !isA_CFDictionary(sets)) {
return NULL;
}
array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
n = (sets != NULL) ? CFDictionaryGetCount(sets) : 0;
if (n > 0) {
CFIndex i;
const void * keys_q[N_QUICK];
const void ** keys = keys_q;
const void * vals_q[N_QUICK];
const void ** vals = vals_q;
if (n > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) {
keys = CFAllocatorAllocate(NULL, n * sizeof(CFTypeRef), 0);
vals = CFAllocatorAllocate(NULL, n * sizeof(CFPropertyListRef), 0);
}
CFDictionaryGetKeysAndValues(sets, keys, vals);
for (i = 0; i < n; i++) {
SCNetworkSetPrivateRef setPrivate;
if (!isA_CFDictionary(vals[i])) {
SC_log(LOG_INFO, "error w/set \"%@\"", keys[i]);
continue;
}
setPrivate = __SCNetworkSetCreatePrivate(NULL, prefs, keys[i]);
assert(setPrivate != NULL);
// mark set as "old" (already established)
setPrivate->established = TRUE;
CFArrayAppendValue(array, (SCNetworkSetRef)setPrivate);
CFRelease(setPrivate);
}
if (keys != keys_q) {
CFAllocatorDeallocate(NULL, keys);
CFAllocatorDeallocate(NULL, vals);
}
}
return array;
}
示例5: writeDataFinalize
static void writeDataFinalize(struct _CFStream *stream, void *info) {
_CFWriteDataStreamContext *ctxt = (_CFWriteDataStreamContext *)info;
if (ctxt->bufferAllocator != kCFAllocatorNull) {
_CFStreamByteBuffer *buf = ctxt->firstBuf->next, *next;
while (buf != NULL) {
next = buf->next;
CFAllocatorDeallocate(ctxt->bufferAllocator, buf);
buf = next;
}
CFRelease(ctxt->bufferAllocator);
}
CFAllocatorDeallocate(CFGetAllocator(stream), ctxt);
}
示例6: HttpContextRelease
/* extern */ void
HttpContextRelease(HttpContextRef context) {
if (context != NULL) {
// Decrease the retain count.
context->_retainCount--;
// Don't dispose until the count goes to zero.
if (context->_retainCount > 0)
return;
// The streams and timers retain the context. If any of these are still set, it means
// that somehow we hit a retain count of zero, but are still held by them! This would
// happen if the context was over-released.
assert(!context->_inStream && !context->_outStream && !context->_timer);
// Hold locally so deallocation can happen and then safely release.
CFAllocatorRef alloc = context->_alloc;
// Release request
if (context->_request != NULL) {
// Release uri
if (context->_request->_uri != NULL )
CFAllocatorDeallocate(alloc, context->_request->_uri);
// Free memory allocated for headers
if (context->_request->_headers != NULL)
CFAllocatorDeallocate(alloc, context->_request->_headers);
// Free memory in use by the request
CFAllocatorDeallocate(alloc, context->_request);
}
// Release the recieve buffer if there is one.
if (context->_rcvdBytes != NULL)
CFRelease(context->_rcvdBytes);
// Release the send buffer if there is one.
if (context->_sendBytes != NULL)
CFRelease(context->_sendBytes);
// Free the memory in use by the context.
CFAllocatorDeallocate(alloc, context);
// Release the allocator.
if (alloc)
CFRelease(alloc);
}
}
示例7: PPPSetOption
__private_extern__
int
PPPSetOption(int ref, u_int8_t *serviceid, u_int32_t option, void *data, u_int32_t dataLen)
{
void *buf;
u_long bufLen;
int status;
bufLen = sizeof(struct ppp_opt_hdr) + dataLen;
buf = CFAllocatorAllocate(NULL, bufLen, 0);
bzero((struct ppp_opt_hdr *)buf, sizeof(struct ppp_opt_hdr));
((struct ppp_opt_hdr *)buf)->o_type = option;
bcopy(data, ((struct ppp_opt *)buf)->o_data, dataLen);
status = PPPExec(ref,
serviceid,
PPP_SETOPTION,
buf,
bufLen,
NULL,
NULL);
if (status != 0) {
fprintf(stderr, "PPPExec(PPP_SETOPTION) failed: status = %d\n", status);
}
CFAllocatorDeallocate(NULL, buf);
return status;
}
示例8: PPPGetOption
__private_extern__
int
PPPGetOption(int ref, u_int8_t *serviceid, u_int32_t option, void **data, u_int32_t *dataLen)
{
struct ppp_opt_hdr opt;
void *replyBuf = NULL;
u_int32_t replyBufLen = 0;
int status;
bzero(&opt, sizeof(opt));
opt.o_type = option;
status = PPPExec(ref,
serviceid,
PPP_GETOPTION,
(void *)&opt,
sizeof(opt),
&replyBuf,
&replyBufLen);
if (status != 0) {
fprintf(stderr, "PPPExec(PPP_GETOPTION) failed: status = %d\n", status);
*data = NULL;
*dataLen = 0;
return status;
}
if (replyBuf && (replyBufLen > sizeof(struct ppp_opt_hdr))) {
*dataLen = replyBufLen - sizeof(struct ppp_opt_hdr);
*data = CFAllocatorAllocate(NULL, *dataLen, 0);
bcopy(((struct ppp_opt *)replyBuf)->o_data, *data, *dataLen);
}
if (replyBuf) CFAllocatorDeallocate(NULL, replyBuf);
return status;
}
示例9: _CFReadBytesFromPathAndGetFD
static Boolean _CFReadBytesFromPathAndGetFD(CFAllocatorRef alloc, const char *path, void **bytes, CFIndex *length, CFIndex maxLength, int extraOpenFlags, int *fd) { // maxLength is the number of bytes desired, or 0 if the whole file is desired regardless of length.
struct statinfo statBuf;
*bytes = NULL;
int no_hang_fd = openAutoFSNoWait();
*fd = open(path, O_RDONLY|extraOpenFlags|CF_OPENFLGS, 0666);
if (*fd < 0) {
closeAutoFSNoWait(no_hang_fd);
return false;
}
if (fstat(*fd, &statBuf) < 0) {
int saveerr = thread_errno();
close(*fd);
*fd = -1;
closeAutoFSNoWait(no_hang_fd);
thread_set_errno(saveerr);
return false;
}
if ((statBuf.st_mode & S_IFMT) != S_IFREG) {
close(*fd);
*fd = -1;
closeAutoFSNoWait(no_hang_fd);
thread_set_errno(EACCES);
return false;
}
if (statBuf.st_size == 0) {
*bytes = CFAllocatorAllocate(alloc, 4, 0); // don't return constant string -- it's freed!
if (__CFOASafe) __CFSetLastAllocationEventName(*bytes, "CFUtilities (file-bytes)");
*length = 0;
} else {
CFIndex desiredLength;
if ((maxLength >= statBuf.st_size) || (maxLength == 0)) {
desiredLength = statBuf.st_size;
} else {
desiredLength = maxLength;
}
*bytes = CFAllocatorAllocate(alloc, desiredLength, 0);
if (!bytes) {
close(*fd);
*fd = -1;
closeAutoFSNoWait(no_hang_fd);
return false;
}
if (__CFOASafe) __CFSetLastAllocationEventName(*bytes, "CFUtilities (file-bytes)");
// fcntl(fd, F_NOCACHE, 1);
if (read(*fd, *bytes, desiredLength) < 0) {
CFAllocatorDeallocate(alloc, *bytes);
close(*fd);
*fd = -1;
closeAutoFSNoWait(no_hang_fd);
return false;
}
*length = desiredLength;
}
closeAutoFSNoWait(no_hang_fd);
return true;
}
示例10: CFSetCreateMutableCopy
CFMutableSetRef
CFSetCreateMutableCopy (CFAllocatorRef allocator, CFIndex capacity,
CFSetRef set)
{
if (CF_IS_OBJC (_kCFSetTypeID, set))
{
CFMutableSetRef result;
const CFIndex count = CFSetGetCount (set);
void **values =
(void **) CFAllocatorAllocate (allocator, sizeof (void *) * count, 0);
CFIndex i;
CFSetGetValues (set, (const void **) values);
result = CFSetCreateMutable (allocator, count, &kCFTypeSetCallBacks);
for (i = 0; i < count; i++)
GSHashTableAddValue ((GSHashTableRef) result, values[i], values[i]);
CFAllocatorDeallocate (allocator, (void *) values);
return result;
}
return (CFMutableSetRef) GSHashTableCreateMutableCopy (allocator,
(GSHashTableRef) set,
capacity);
}
示例11: CFTreeSortChildren
void CFTreeSortChildren(CFTreeRef tree, CFComparatorFunction comparator, void *context) {
CFIndex children;
__CFGenericValidateType(tree, __kCFTreeTypeID);
CFAssert1(NULL != comparator, __kCFLogAssertion, "%s(): pointer to comparator function may not be NULL", __PRETTY_FUNCTION__);
children = CFTreeGetChildCount(tree);
if (1 < children) {
CFIndex idx;
CFTreeRef nextChild;
struct _tcompareContext ctx;
CFTreeRef *list, buffer[128];
list = (children < 128) ? buffer : (CFTreeRef *)CFAllocatorAllocate(kCFAllocatorSystemDefault, children * sizeof(CFTreeRef), 0); // XXX_PCB GC OK
if (__CFOASafe && list != buffer) __CFSetLastAllocationEventName(tree->_callbacks, "CFTree (temp)");
nextChild = tree->_child;
for (idx = 0; NULL != nextChild; idx++) {
list[idx] = nextChild;
nextChild = nextChild->_sibling;
}
ctx.func = comparator;
ctx.context = context;
CFQSortArray(list, children, sizeof(CFTreeRef), (CFComparatorFunction)__CFTreeCompareValues, &ctx);
__CFAssignWithWriteBarrier((void **)&tree->_child, list[0]);
for (idx = 1; idx < children; idx++) {
__CFAssignWithWriteBarrier((void **)&list[idx - 1]->_sibling, list[idx]);
}
list[idx - 1]->_sibling = NULL;
tree->_rightmostChild = list[children - 1];
if (list != buffer) CFAllocatorDeallocate(kCFAllocatorSystemDefault, list); // XXX_PCB GC OK
}
}
示例12: SCPreferencesCopyKeyList
CFArrayRef
SCPreferencesCopyKeyList(SCPreferencesRef prefs)
{
CFAllocatorRef allocator;
CFArrayRef keys;
SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
CFIndex prefsCnt;
const void ** prefsKeys;
if (prefs == NULL) {
/* sorry, you must provide a session */
_SCErrorSet(kSCStatusNoPrefsSession);
return NULL;
}
__SCPreferencesAccess(prefs);
allocator = CFGetAllocator(prefs);
prefsCnt = CFDictionaryGetCount(prefsPrivate->prefs);
if (prefsCnt > 0) {
prefsKeys = CFAllocatorAllocate(allocator, prefsCnt * sizeof(CFStringRef), 0);
CFDictionaryGetKeysAndValues(prefsPrivate->prefs, prefsKeys, NULL);
keys = CFArrayCreate(allocator, prefsKeys, prefsCnt, &kCFTypeArrayCallBacks);
CFAllocatorDeallocate(allocator, prefsKeys);
} else {
keys = CFArrayCreate(allocator, NULL, 0, &kCFTypeArrayCallBacks);
}
return keys;
}
示例13: SCBondStatusGetMemberInterfaces
CFArrayRef /* of SCNetworkInterfaceRef's */
SCBondStatusGetMemberInterfaces(SCBondStatusRef bondStatus)
{
SCBondStatusPrivateRef statusPrivate = (SCBondStatusPrivateRef)bondStatus;
if (!isA_SCBondStatus(bondStatus)) {
return NULL;
}
if (statusPrivate->interfaces == NULL) {
const void * keys_q[N_QUICK];
const void ** keys = keys_q;
CFIndex n;
n = CFDictionaryGetCount(statusPrivate->status_interfaces);
if (n > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) {
keys = CFAllocatorAllocate(NULL, n * sizeof(CFTypeRef), 0);
}
CFDictionaryGetKeysAndValues(statusPrivate->status_interfaces, keys, NULL);
statusPrivate->interfaces = CFArrayCreate(NULL, keys, n, &kCFTypeArrayCallBacks);
if (keys != keys_q) {
CFAllocatorDeallocate(NULL, keys);
}
}
return statusPrivate->interfaces;
}
示例14: __JSONStackEntryRelease
inline CFIndex __JSONStackEntryRelease(__JSONStackEntryRef entry) {
CFIndex retainCount = 0;
if (entry) {
if ((retainCount = --entry->retainCount) == 0) {
CFAllocatorRef allocator = entry->allocator;
if (entry->values)
CFAllocatorDeallocate(allocator, entry->values);
if (entry->keys)
CFAllocatorDeallocate(allocator, entry->keys);
CFAllocatorDeallocate(allocator, entry);
if (allocator)
CFRelease(allocator);
}
}
return retainCount;
}
示例15: PPPStatus
__private_extern__
int
PPPStatus(int ref, u_int8_t *serviceid, struct ppp_status **stat)
{
void *replyBuf = NULL;
u_int32_t replyBufLen = 0;
int status;
status = PPPExec(ref,
serviceid,
PPP_STATUS,
NULL,
0,
&replyBuf,
&replyBufLen);
if (status != 0) {
fprintf(stderr, "PPPExec(PPP_STATUS) failed: status = %d\n", status);
return status;
}
if (replyBuf && (replyBufLen == sizeof(struct ppp_status))) {
*stat = (struct ppp_status *)replyBuf;
} else {
if (replyBuf) CFAllocatorDeallocate(NULL, replyBuf);
*stat = NULL;
status = -1;
}
return status;
}