Exemplo n.º 1
0
void
CFStreamCreatePairWithSocket(CFAllocatorRef alloc, CFSocketNativeHandle sock,
		CFReadStreamRef *readStream,
		CFWriteStreamRef *writeStream)
{
	struct CFWriteStreamSocket* sfd;
	struct CFReadStreamSocket* rfd;

	*writeStream = (CFWriteStreamRef)
			_CFRuntimeCreateInstance(alloc, CFWriteStreamGetTypeID(),
			CFWRITESTREAMSOCKET_SIZE, 0);
	sfd = (struct CFWriteStreamSocket*) *writeStream;

	memcpy(&(*writeStream)->impl, &CFWriteStreamSocketImpl, sizeof (CFWriteStreamSocketImpl));
	sfd->fd = dup(sock);
	sfd->originalFd = sock;

	*readStream = (CFReadStreamRef)
			_CFRuntimeCreateInstance(alloc, CFReadStreamGetTypeID(),
			CFREADSTREAMSOCKET_SIZE, 0);
	rfd = (struct CFReadStreamSocket*) *readStream;

	memcpy(&(*readStream)->impl, &CFReadStreamSocketImpl, sizeof (CFReadStreamSocketImpl));
	rfd->fd = dup(sock);
	rfd->originalFd = sock;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
// IOMIGMachPortCreate
//------------------------------------------------------------------------------
IOMIGMachPortRef IOMIGMachPortCreate(CFAllocatorRef allocator, CFIndex maxMessageSize, mach_port_t port)
{
    IOMIGMachPortRef  migPort  = NULL;
    void *              offset  = NULL;
    uint32_t            size;
    
    require(maxMessageSize > 0, exit);
    
    /* allocate service */
    size    = sizeof(__IOMIGMachPort) - sizeof(CFRuntimeBase);
    migPort  = ( IOMIGMachPortRef)_CFRuntimeCreateInstance(allocator, IOMIGMachPortGetTypeID(), size, NULL);
    
    require(migPort, exit);

    offset = migPort;
    bzero(offset + sizeof(CFRuntimeBase), size);
        
    CFMachPortContext context = {0, migPort, NULL, NULL, NULL};
    migPort->port = (port != MACH_PORT_NULL) ? 
            CFMachPortCreateWithPort(kCFAllocatorDefault, port, __IOMIGMachPortPortCallback, &context, NULL) :
            CFMachPortCreate(kCFAllocatorDefault, __IOMIGMachPortPortCallback, &context, NULL);
    
    require(migPort->port, exit);
    
    migPort->maxMessageSize = maxMessageSize;
    
    return migPort;

exit:
    if ( migPort )
        CFRelease(migPort);
        
    return NULL;
}
Exemplo n.º 3
0
static CFDataRef
CFDataCreate_internal (CFAllocatorRef allocator, const UInt8 *bytes,
  CFIndex length, CFAllocatorRef bytesDealloc, Boolean copy)
{
  struct __CFData *newData;
  CFIndex size;
  
  size = CFDATA_SIZE + (copy == true ? length : 0);
  
  if (allocator == NULL)
    allocator = CFAllocatorGetDefault ();
  
  newData = (struct __CFData*)_CFRuntimeCreateInstance (allocator,
    _kCFDataTypeID, size, NULL);
  if (newData)
    {
      newData->_length = length;
      
      if (copy)
        {
          memcpy (&(newData[1]), bytes, length);
          bytes = (const UInt8*)&(newData[1]);
        }
      else
        {
          if (bytesDealloc == NULL)
            bytesDealloc = CFAllocatorGetDefault ();
          newData->_deallocator = CFRetain(bytesDealloc);
          CFDataSetFreeBytes (newData);
        }
      newData->_contents = bytes;
    }
  
  return (CFDataRef)newData;
}
static SCBondStatusRef
__SCBondStatusCreatePrivate(CFAllocatorRef	allocator,
			    SCBondInterfaceRef	bond,
			    CFDictionaryRef	status_bond,
			    CFDictionaryRef	status_interfaces)
{
	SCBondStatusPrivateRef	statusPrivate;
	uint32_t		size;

	/* initialize runtime */
	pthread_once(&bondStatus_init, __SCBondStatusInitialize);

	/* allocate bond */
	size          = sizeof(SCBondStatusPrivate) - sizeof(CFRuntimeBase);
	statusPrivate = (SCBondStatusPrivateRef)_CFRuntimeCreateInstance(allocator,
									 __kSCBondStatusTypeID,
									 size,
									 NULL);
	if (statusPrivate == NULL) {
		return NULL;
	}

	/* establish the bond status */

	statusPrivate->bond		 = CFRetain(bond);
	statusPrivate->status_bond       = CFDictionaryCreateCopy(NULL, status_bond);

	statusPrivate->interfaces        = NULL;
	statusPrivate->status_interfaces = CFDictionaryCreateCopy(NULL, status_interfaces);

	return (SCBondStatusRef)statusPrivate;
}
Exemplo n.º 5
0
/* Note that there are two entry points for creating CFErrors.
 * This one does it with individual keys and values which are used 
 *  to create the userInfo dictionary.
 */
CFErrorRef CFErrorCreateWithUserInfoKeysAndValues(CFAllocatorRef allocator,
                                                  CFStringRef domain, CFIndex code,
                                                  const void* const* userInfoKeys,
                                                  const void* const* userInfoValues,
                                                  CFIndex numUserInfoValues)
{
    CF_VALIDATE_OBJECT_ARG(CF, domain, CFStringGetTypeID());

    CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance(
        allocator,
        __kCFErrorTypeID,
        sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL);
    if (!err) {
        return NULL;
    }

    err->domain = CFStringCreateCopy(allocator, domain);
    err->code = code;
    err->userInfo = CFDictionaryCreate(
        allocator,
        (const void**)userInfoKeys, (const void**)userInfoValues, numUserInfoValues,
        &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    return err;
}
Exemplo n.º 6
0
CFMutableDataRef
CFDataCreateMutable (CFAllocatorRef allocator, CFIndex capacity)
{
  struct __CFMutableData *newData;
  
  if (allocator == NULL)
    allocator = CFAllocatorGetDefault ();
  
  newData = (struct __CFMutableData*)_CFRuntimeCreateInstance (allocator,
    _kCFDataTypeID, CFMUTABLEDATA_SIZE, NULL);
  
  if (newData)
    {
      if (capacity < DEFAULT_CAPACITY)
        capacity = DEFAULT_CAPACITY;
      newData->_capacity = capacity;
      newData->_allocator = CFRetain(allocator);
      newData->_contents = CFAllocatorAllocate (allocator, capacity, 0);
      
      CFDataSetMutable ((CFDataRef)newData);
      CFDataSetFreeBytes((CFDataRef)newData);
    }
  
  return (CFMutableDataRef)newData;
}
// Designated initializer; all node creation (except the wonky one created by the parser) should happen here.
CFXMLNodeRef CFXMLNodeCreate(CFAllocatorRef alloc, CFXMLNodeTypeCode xmlType, CFStringRef dataString, const void *additionalData, CFIndex version) {
    struct __CFXMLNode *node;
    UInt32 extraSize;
    // Add assertions checking xmlType against the presence/absence of additionalData & dataString
    switch (xmlType) {
        case kCFXMLNodeTypeDocument: extraSize = sizeof(CFXMLDocumentInfo); break;
        case kCFXMLNodeTypeElement: extraSize = sizeof(CFXMLElementInfo); break;
        case kCFXMLNodeTypeProcessingInstruction: extraSize = sizeof(CFXMLProcessingInstructionInfo); break;
        case kCFXMLNodeTypeEntity: extraSize = sizeof(CFXMLEntityInfo); break;
        case kCFXMLNodeTypeEntityReference: extraSize = sizeof(CFXMLEntityReferenceInfo); break;
        case kCFXMLNodeTypeDocumentType: extraSize = sizeof(CFXMLDocumentTypeInfo); break;
        case kCFXMLNodeTypeNotation: extraSize = sizeof(CFXMLNotationInfo); break;
        case kCFXMLNodeTypeElementTypeDeclaration: extraSize = sizeof(CFXMLElementTypeDeclarationInfo); break;
        case kCFXMLNodeTypeAttributeListDeclaration: extraSize = sizeof(CFXMLAttributeListDeclarationInfo); break;
        default: extraSize = 0;
    }

    node = (struct __CFXMLNode *)_CFRuntimeCreateInstance(alloc, CFXMLNodeGetTypeID(), sizeof(struct __CFXMLNode) + extraSize - sizeof(CFRuntimeBase), NULL);
    if (node) {
        alloc = CFGetAllocator(node);
        node->version = version;
        node->dataTypeID = xmlType;
        node->dataString = dataString ? (CFStringRef)CFStringCreateCopy(alloc, dataString) : NULL;
        if (extraSize != 0) {
            node->additionalData = (void *)((uint8_t *)node + sizeof(struct __CFXMLNode));
            _copyAddlDataForType(alloc, xmlType, additionalData, node->additionalData);
        } else {
            node->additionalData = NULL;
        }
    }
    return node;
}
Exemplo n.º 8
0
static SCNetworkSetPrivateRef
__SCNetworkSetCreatePrivate(CFAllocatorRef      allocator,
			    SCPreferencesRef	prefs,
			    CFStringRef		setID)
{
	SCNetworkSetPrivateRef  setPrivate;
	uint32_t		size;

	/* initialize runtime */
	pthread_once(&initialized, __SCNetworkSetInitialize);

	/* allocate target */
	size            = sizeof(SCNetworkSetPrivate) - sizeof(CFRuntimeBase);
	setPrivate = (SCNetworkSetPrivateRef)_CFRuntimeCreateInstance(allocator,
								      __kSCNetworkSetTypeID,
								      size,
								      NULL);
	if (setPrivate == NULL) {
		return NULL;
	}

	setPrivate->setID       = CFStringCreateCopy(NULL, setID);
	setPrivate->prefs       = CFRetain(prefs);
	setPrivate->name	= NULL;
	setPrivate->established	= FALSE;	// "new" (not yet established) set

	return setPrivate;
}
Exemplo n.º 9
0
CFCalendarRef CFCalendarCreateWithIdentifier(CFAllocatorRef allocator, CFStringRef identifier) {
    if (allocator == NULL) allocator = __CFGetDefaultAllocator();
    __CFGenericValidateType(allocator, CFAllocatorGetTypeID());
    __CFGenericValidateType(identifier, CFStringGetTypeID());
    // return NULL until Chinese calendar is available
    if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar) {
//    if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar && identifier != kCFChineseCalendar) {
	if (CFEqual(kCFGregorianCalendar, identifier)) identifier = kCFGregorianCalendar;
	else if (CFEqual(kCFBuddhistCalendar, identifier)) identifier = kCFBuddhistCalendar;
	else if (CFEqual(kCFJapaneseCalendar, identifier)) identifier = kCFJapaneseCalendar;
	else if (CFEqual(kCFIslamicCalendar, identifier)) identifier = kCFIslamicCalendar;
	else if (CFEqual(kCFIslamicCivilCalendar, identifier)) identifier = kCFIslamicCivilCalendar;
	else if (CFEqual(kCFHebrewCalendar, identifier)) identifier = kCFHebrewCalendar;
//	else if (CFEqual(kCFChineseCalendar, identifier)) identifier = kCFChineseCalendar;
	else return NULL;
    }
    struct __CFCalendar *calendar = NULL;
    uint32_t size = sizeof(struct __CFCalendar) - sizeof(CFRuntimeBase);
    calendar = (struct __CFCalendar *)_CFRuntimeCreateInstance(allocator, CFCalendarGetTypeID(), size, NULL);
    if (NULL == calendar) {
	return NULL;
    }
    calendar->_identifier = (CFStringRef)CFRetain(identifier);
    calendar->_locale = NULL;
    calendar->_localeID = CFLocaleGetIdentifier(CFLocaleGetSystem());
    calendar->_tz = CFTimeZoneCopyDefault();
    calendar->_cal = NULL;
    return (CFCalendarRef)calendar;
}
Exemplo n.º 10
0
CFUserNotificationRef CFUserNotificationCreate(CFAllocatorRef allocator, CFTimeInterval timeout, CFOptionFlags flags, SInt32 *error, CFDictionaryRef dictionary) {
    CHECK_FOR_FORK();
    CFUserNotificationRef userNotification = NULL;
    SInt32 retval = ERR_SUCCESS;
    static uint16_t tokenCounter = 0;
    SInt32 token = ((getpid() << 16) | (tokenCounter++));
    CFStringRef sessionID = (dictionary ? CFDictionaryGetValue(dictionary, kCFUserNotificationSessionIDKey) : NULL);
    mach_port_t replyPort = MACH_PORT_NULL;

    if (!allocator) allocator = __CFGetDefaultAllocator();
    retval = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &replyPort);
    if (ERR_SUCCESS == retval && MACH_PORT_NULL != replyPort) retval = _CFUserNotificationSendRequest(allocator, sessionID, replyPort, token, timeout, flags, dictionary);
    if (ERR_SUCCESS == retval) {
        userNotification = (CFUserNotificationRef)_CFRuntimeCreateInstance(allocator, CFUserNotificationGetTypeID(), sizeof(struct __CFUserNotification) - sizeof(CFRuntimeBase), NULL);
        if (userNotification) {
            userNotification->_replyPort = replyPort;
            userNotification->_token = token;
            userNotification->_timeout = timeout;
            userNotification->_requestFlags = flags;
            userNotification->_responseFlags = 0;
            userNotification->_sessionID = NULL;
            userNotification->_responseDictionary = NULL;
            userNotification->_machPort = NULL;
            userNotification->_callout = NULL;
            if (sessionID) userNotification->_sessionID = CFStringCreateCopy(allocator, sessionID);
        } else {
            retval = unix_err(ENOMEM);
        }
    } else {
        if (dictionary) CFUserNotificationLog(CFDictionaryGetValue(dictionary, kCFUserNotificationAlertHeaderKey), CFDictionaryGetValue(dictionary, kCFUserNotificationAlertMessageKey));
    }
    if (ERR_SUCCESS != retval && MACH_PORT_NULL != replyPort) mach_port_destroy(mach_task_self(), replyPort);
    if (error) *error = retval;
    return userNotification;
}
Exemplo n.º 11
0
/* Note that there are two entry points for creating CFErrors.
 * This one does it with a presupplied userInfo dictionary.
 */
CFErrorRef CFErrorCreate(CFAllocatorRef allocator,
                         CFStringRef domain, CFIndex code,
                         CFDictionaryRef userInfo)
{
    CF_VALIDATE_OBJECT_ARG(CF, domain, CFStringGetTypeID());
    if (userInfo) {
        CF_VALIDATE_OBJECT_ARG(CF, userInfo, CFDictionaryGetTypeID());
    }

    CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance(
        allocator,
        __kCFErrorTypeID,
        sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL);
    if (!err) {
        return NULL;
    }

    err->domain = CFStringCreateCopy(allocator, domain);
    err->code = code;
    err->userInfo = userInfo ?
        CFDictionaryCreateCopy(allocator, userInfo) :
        _CFErrorCreateEmptyDictionary(allocator);

    return err;
}
Exemplo n.º 12
0
CGColorTransformRef CGColorTransformCreate(CGColorSpaceRef space, CFDictionaryRef theDict)
{
	CGColorTransformRef colorTransform;
	CGColorTransformRef colTransformTmp;
	size_t numComponents;
	CGColorSpaceType spaceType;
	CFIndex extraBytes;
	CGColorSpaceRef space2;
	unsigned char* md5;

	if (!space || !CGColorSpaceSupportsOutput(space))
		return NULL;

	numComponents = CGColorSpaceGetNumberOfComponents(space);
	extraBytes = (numComponents <= 4) ? 328 : 16; // 0x148 : 0x10
	
	colorTransform = (CGColorTransformRef)_CFRuntimeCreateInstance(NULL, CGColorTransformGetTypeID(), extraBytes, NULL);
	if (!colorTransform)
		return NULL;

	spaceType = CGColorSpaceGetType(space);
	switch(spaceType)
	{
	case kCGColorSpaceTypeDeviceGray:
		space2 = CGColorSpaceCreateDisplayGray();
		break;
	case kCGColorSpaceTypeDeviceRGB:
		space2 = CGColorSpaceCreateDisplayRGB();
		break;
	case kCGColorSpaceTypeDeviceCMYK:
		space2 = CGColorSpaceCreateSystemDefaultCMYK();
		break;
	}

	if (space2)
	{
		pthread_mutex_lock(&cacheMutex);
		if (baseCache)
		{
			md5 = CGColorSpaceGetMD5Digest(space2);
			for (int i=0; i < CFArrayGetCount(baseCache); i++)
			{
				/*colTransformTmp = (CGColorTransformRef) CFArrayGetValueAtIndex(baseCache, i);
				 if (!memcmp((unsigned char *)CFArrayGetValueAtIndex(baseCache, i), md5, 16))
				 {

				 }*/
			}
		}
	}
	else
	{
		CFRelease(colorTransform);
		colorTransform = NULL;
	}

	return colorTransform;
}
Exemplo n.º 13
0
SDMMD_AFCLockRef SDMMD_AFCLockCreate() {
    uint32_t extra = sizeof(AFCLockClassBody);
    SDMMD_AFCLockRef lock = calloc(0x1, sizeof(SDMMD_AFCLockClass));
    lock = (SDMMD_AFCLockRef)_CFRuntimeCreateInstance(kCFAllocatorDefault, _kSDMMD_AFCLockRefID, extra, NULL);
    if (lock) {
        sdmmd_mutex_init(lock->ivars.mutex_lock);
    }
    return lock;
}
Exemplo n.º 14
0
static struct __CFHTTPCookieStorage *_CFHTTPCookieStorageCreate(CFAllocatorRef allocator) {
    CFIndex size = sizeof(struct __CFHTTPCookieStorage) - sizeof(CFRuntimeBase);
    struct __CFHTTPCookieStorage *cookieStorage = (struct __CFHTTPCookieStorage *)_CFRuntimeCreateInstance(allocator, CFHTTPCookieStorageGetTypeID(), size, NULL);
    
    cookieStorage->_cookies = (CFMutableArrayRef)CFRetain(CFArrayCreateMutable(allocator, 0, &kCFTypeArrayCallBacks));
    
    
    return cookieStorage;
}
Exemplo n.º 15
0
static void *
_heim_create_cf_instance(CFTypeID typeID, CFIndex size, char *category)
{
    heim_assert(size >= sizeof(CFRuntimeBase), "cf runtime size too small");
    CFTypeRef type = _CFRuntimeCreateInstance(NULL, typeID, size - sizeof(struct heim_base), (unsigned char *)category);
    if (type)
	memset(((uint8_t *)type) + sizeof(struct heim_base), 0, size - sizeof(struct heim_base));
    return (void *)type;
}
Exemplo n.º 16
0
static SCPreferencesPrivateRef
__SCPreferencesCreatePrivate(CFAllocatorRef	allocator)
{
	SCPreferencesPrivateRef	prefsPrivate;
	uint32_t		size;

	/* initialize runtime */
	pthread_once(&initialized, __SCPreferencesInitialize);

	/* allocate prefs session */
	size  = sizeof(SCPreferencesPrivate) - sizeof(CFRuntimeBase);
	prefsPrivate = (SCPreferencesPrivateRef)_CFRuntimeCreateInstance(allocator,
									 __kSCPreferencesTypeID,
									 size,
									 NULL);
	if (prefsPrivate == NULL) {
		return NULL;
	}

	pthread_mutex_init(&prefsPrivate->lock, NULL);

	prefsPrivate->name				= NULL;
	prefsPrivate->prefsID				= NULL;
	prefsPrivate->options				= NULL;
	prefsPrivate->path				= NULL;
	prefsPrivate->newPath				= NULL;		// new prefs path
	prefsPrivate->locked				= FALSE;
	prefsPrivate->lockFD				= -1;
	prefsPrivate->lockPath				= NULL;
	prefsPrivate->signature				= NULL;
	prefsPrivate->session				= NULL;
	prefsPrivate->sessionKeyLock			= NULL;
	prefsPrivate->sessionKeyCommit			= NULL;
	prefsPrivate->sessionKeyApply			= NULL;
	prefsPrivate->scheduled				= FALSE;
	prefsPrivate->rls				= NULL;
	prefsPrivate->rlsFunction			= NULL;
	prefsPrivate->rlsContext.info			= NULL;
	prefsPrivate->rlsContext.retain			= NULL;
	prefsPrivate->rlsContext.release		= NULL;
	prefsPrivate->rlsContext.copyDescription	= NULL;
	prefsPrivate->rlList				= NULL;
	prefsPrivate->dispatchQueue			= NULL;
	prefsPrivate->prefs				= NULL;
	prefsPrivate->accessed				= FALSE;
	prefsPrivate->changed				= FALSE;
	prefsPrivate->isRoot				= (geteuid() == 0);
	prefsPrivate->limit_SCNetworkConfiguration	= FALSE;
	prefsPrivate->authorizationData			= NULL;
	prefsPrivate->authorizationRequired		= FALSE;
	prefsPrivate->helper_port			= MACH_PORT_NULL;

	return prefsPrivate;
}
Exemplo n.º 17
0
CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at) {
    CFDateRef memory;
    uint32_t size;
    size = sizeof(struct __CFDate) - sizeof(CFRuntimeBase);
    memory = (CFDateRef)_CFRuntimeCreateInstance(allocator, CFDateGetTypeID(), size, NULL);
    if (!memory) {
        return NULL;
    }
    ((struct __CFDate*)memory)->_time = at;
    return memory;
}
static CFArrayRef __CFArrayInit(CFAllocatorRef allocator, UInt32 flags, CFIndex capacity, const CFArrayCallBacks *callBacks) {
    struct __CFArray *memory;
    UInt32 size;
    __CFBitfieldSetValue(flags, 31, 2, 0);
    if (CF_IS_COLLECTABLE_ALLOCATOR(allocator)) {
	if (!callBacks || (callBacks->retain == NULL && callBacks->release == NULL)) {
	    __CFBitfieldSetValue(flags, 4, 4, 1); // setWeak
	}
    }
    if (__CFArrayCallBacksMatchNull(callBacks)) {
	__CFBitfieldSetValue(flags, 3, 2, __kCFArrayHasNullCallBacks);
    } else if (__CFArrayCallBacksMatchCFType(callBacks)) {
	__CFBitfieldSetValue(flags, 3, 2, __kCFArrayHasCFTypeCallBacks);
    } else {
	__CFBitfieldSetValue(flags, 3, 2, __kCFArrayHasCustomCallBacks);
    }
    size = __CFArrayGetSizeOfType(flags) - sizeof(CFRuntimeBase);
    switch (__CFBitfieldGetValue(flags, 1, 0)) {
    case __kCFArrayImmutable:
	size += capacity * sizeof(struct __CFArrayBucket);
	break;
    case __kCFArrayDeque:
	break;
    }
    memory = (struct __CFArray*)_CFRuntimeCreateInstance(allocator, __kCFArrayTypeID, size, NULL);
    if (NULL == memory) {
	return NULL;
    }
    __CFBitfieldSetValue(memory->_base._cfinfo[CF_INFO_BITS], 6, 0, flags);
    __CFArraySetCount((CFArrayRef)memory, 0);
    switch (__CFBitfieldGetValue(flags, 1, 0)) {
    case __kCFArrayImmutable:
        if (isWeakMemory(memory)) {  // if weak, don't scan
            auto_zone_set_unscanned(objc_collectableZone(), memory);
        }
	if (__CFOASafe) __CFSetLastAllocationEventName(memory, "CFArray (immutable)");
	break;
    case __kCFArrayDeque:
	if (__CFOASafe) __CFSetLastAllocationEventName(memory, "CFArray (mutable-variable)");
	((struct __CFArray *)memory)->_mutations = 1;
	((struct __CFArray *)memory)->_mutInProgress = 0;
	((struct __CFArray*)memory)->_store = NULL;
	break;
    }
    if (__kCFArrayHasCustomCallBacks == __CFBitfieldGetValue(flags, 3, 2)) {
	CFArrayCallBacks *cb = (CFArrayCallBacks *)__CFArrayGetCallBacks((CFArrayRef)memory);
	*cb = *callBacks;
	FAULT_CALLBACK((void **)&(cb->retain));
	FAULT_CALLBACK((void **)&(cb->release));
	FAULT_CALLBACK((void **)&(cb->copyDescription));
	FAULT_CALLBACK((void **)&(cb->equal));
    }
    return (CFArrayRef)memory;
}
Exemplo n.º 19
0
EXRangeRef EXRangeCreate(CFAllocatorRef allocator, uint32_t location, uint32_t length) {
    struct __EXRange *newrange;
    uint32_t extra = sizeof(struct __EXRange) - sizeof(CFRuntimeBase);
    newrange = (struct __EXRange *)_CFRuntimeCreateInstance(allocator, _kEXRangeID, extra, NULL);
    if (NULL == newrange) {
        return NULL;
    }
    newrange->_location = location;
    newrange->_length = length;
    return (EXRangeRef)newrange;
}
Exemplo n.º 20
0
static ACSharedArtImageSourceRef __ACSharedArtImageSourceInit(CFAllocatorRef allocator, ACSharedArtRef owner, CFIndex headerIndex)
{	
	struct __ACSharedArtImageSource * isrc;
	UInt32 size = sizeof(struct __ACSharedArtImageSource) - sizeof(CFRuntimeBase);
	isrc = (struct __ACSharedArtImageSource *) _CFRuntimeCreateInstance(allocator, __kACSharedArtImageSourceTypeID,size,NULL);
	CFRetain(owner);
	isrc->owner = owner;
	isrc->headerIndex = headerIndex;
	void * headerBytes = ACSharedArtGetBytePtr(isrc->owner) + ACSharedArtGetImageHeaderOffsetForIndex(isrc->owner,headerIndex);
	isrc->header = (struct __ACSharedArtImageHeader *) (headerBytes);

	return (ACSharedArtImageSourceRef) isrc;
}
Exemplo n.º 21
0
/* Note that there are two entry points for creating CFErrors. This one does it with a presupplied userInfo dictionary.
*/
CFErrorRef CFErrorCreate(CFAllocatorRef allocator, CFStringRef domain, CFIndex code, CFDictionaryRef userInfo) {
    __CFGenericValidateType(domain, CFStringGetTypeID());
    if (userInfo) __CFGenericValidateType(userInfo, CFDictionaryGetTypeID());

    CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance(allocator, __kCFErrorTypeID, sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL);
    if (NULL == err) return NULL;

    err->domain = CFStringCreateCopy(allocator, domain);
    err->code = code;
    err->userInfo = userInfo ? CFDictionaryCreateCopy(allocator, userInfo) : _CFErrorCreateEmptyDictionary(allocator);

    return err;
}
Exemplo n.º 22
0
CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo)
{
	CGLayerRef layer = (CGLayerRef)_CFRuntimeCreateInstance (nullptr, _kCGLayerTypeID,
		sizeof(struct __CGLayer) - sizeof(CFRuntimeBase), nullptr);
	
	layer->picture = new QPicture;
	layer->picture->setBoundingRect(QRect(0, 0, size.width, size.height));
	layer->context = CGContextForPaintDevice(layer->picture);
	
	// TODO: copy over settings from "context"
	
	return layer;
}
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;
}
Exemplo n.º 24
0
STATIC EAPOLClientItemIDRef
__EAPOLClientItemIDAllocate(CFAllocatorRef allocator)
{
    EAPOLClientItemIDRef	itemID;

    __EAPOLClientItemIDRegisterClass();

    itemID = (EAPOLClientItemIDRef)
	_CFRuntimeCreateInstance(allocator,
				 __kEAPOLClientItemIDTypeID,
				 sizeof(*itemID) - sizeof(CFRuntimeBase),
				 NULL);
    return (itemID);
}
Exemplo n.º 25
0
CFLocaleRef CFLocaleCreate(CFAllocatorRef allocator, CFStringRef identifier) {
    if (allocator == NULL) allocator = __CFGetDefaultAllocator();
    __CFGenericValidateType(allocator, CFAllocatorGetTypeID());
    __CFGenericValidateType(identifier, CFStringGetTypeID());
    CFStringRef localeIdentifier = NULL;
    if (identifier) {
         localeIdentifier = CFLocaleCreateCanonicalLocaleIdentifierFromString(allocator, identifier);
    }
    if (NULL == localeIdentifier) return NULL;
    CFStringRef old = localeIdentifier;
    localeIdentifier = (CFStringRef)CFStringCreateCopy(allocator, localeIdentifier);
    CFRelease(old);
    __CFLocaleLockGlobal();
    // Look for cases where we can return a cached instance.
    // We only use cached objects if the allocator is the system
    // default allocator.
    if (!allocator) allocator = __CFGetDefaultAllocator();
    Boolean canCache = (kCFAllocatorSystemDefault == allocator);
    if (canCache && __CFLocaleCache) {
        CFLocaleRef locale = (CFLocaleRef)CFDictionaryGetValue(__CFLocaleCache, localeIdentifier);
        if (locale) {
             CFRetain(locale);
             __CFLocaleUnlockGlobal();
             CFRelease(localeIdentifier);
             return locale;
         }
     }
    struct __CFLocale *locale = NULL;
    uint32_t size = sizeof(struct __CFLocale) - sizeof(CFRuntimeBase);
    locale = (struct __CFLocale *)_CFRuntimeCreateInstance(allocator, CFLocaleGetTypeID(), size, NULL);
    if (NULL == locale) {
         return NULL;
    }
    __CFLocaleSetType(locale, __kCFLocaleOrdinary);
    locale->_identifier = localeIdentifier;
    locale->_cache = CFDictionaryCreateMutable(allocator, 0, NULL, &kCFTypeDictionaryValueCallBacks);
    locale->_overrides = NULL;
    locale->_prefs = NULL;

    CF_SPINLOCK_INIT_FOR_STRUCTS(locale->_lock);

    if (canCache) {
        if (NULL == __CFLocaleCache) {
            __CFLocaleCache = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        }
        CFDictionarySetValue(__CFLocaleCache, localeIdentifier, locale);
    }
    __CFLocaleUnlockGlobal();
    return (CFLocaleRef)locale;
}
Exemplo n.º 26
0
static struct __CFNotificationCenter *_CFNotificationCenterCreate(CFAllocatorRef allocator) {
    CFIndex size = sizeof(struct __CFNotificationCenter) - sizeof(CFRuntimeBase);
    struct __CFNotificationCenter *center = (struct __CFNotificationCenter *)_CFRuntimeCreateInstance(allocator, CFNotificationCenterGetTypeID(), size, NULL);
    center->lock = OS_SPINLOCK_INIT;
    CFArrayCallBacks callbacks = {
        .version = 0,
        .retain = (CFArrayRetainCallBack)&CFNotificationObserverRetain,
        .release = (CFArrayReleaseCallBack)&CFNotificationObserverRelease,
        .copyDescription = NULL,
        .equal = (CFArrayEqualCallBack)&CFNotificationObserverEqual
    };
    center->observers = CFArrayCreateMutable(allocator, 0, &callbacks);
    return center;
}
Exemplo n.º 27
0
CF_EXPORT CFPlugInInstanceRef CFPlugInInstanceCreateWithInstanceDataSize(CFAllocatorRef allocator, CFIndex instanceDataSize, CFPlugInInstanceDeallocateInstanceDataFunction deallocateInstanceFunction, CFStringRef factoryName, CFPlugInInstanceGetInterfaceFunction getInterfaceFunction) {
    CFPlugInInstanceRef instance;
    UInt32 size;
    size = sizeof(struct __CFPlugInInstance) + instanceDataSize - sizeof(CFRuntimeBase);
    instance = (CFPlugInInstanceRef)_CFRuntimeCreateInstance(allocator, __kCFPlugInInstanceTypeID, size, NULL);
    if (!instance) return NULL;

    instance->factory = _CFPFactoryFind((CFUUIDRef)factoryName, true);
    if (instance->factory) _CFPFactoryAddInstance(instance->factory);
    instance->getInterfaceFunction = getInterfaceFunction;
    instance->deallocateInstanceDataFunction = deallocateInstanceFunction;

    return instance;
}
Exemplo n.º 28
0
static DAFileSystemRef __DAFileSystemCreate( CFAllocatorRef allocator, CFURLRef id, CFDictionaryRef properties )
{
    __DAFileSystem * filesystem;

    filesystem = ( void * ) _CFRuntimeCreateInstance( allocator, __kDAFileSystemTypeID, sizeof( __DAFileSystem ) - sizeof( CFRuntimeBase ), NULL );

    if ( filesystem )
    {
        filesystem->_id         = CFRetain( id );
        filesystem->_properties = CFRetain( properties );
    }

    return filesystem;
}
Exemplo n.º 29
0
static CFBinaryHeapRef __CFBinaryHeapInit(CFAllocatorRef allocator, UInt32 flags, CFIndex capacity, const void **values, CFIndex numValues, const CFBinaryHeapCallBacks *callBacks, const CFBinaryHeapCompareContext *compareContext) {
    CFBinaryHeapRef memory;
    CFIndex idx;
    CFIndex size;

    CFAssert2(0 <= capacity, __kCFLogAssertion, "%s(): capacity (%d) cannot be less than zero", __PRETTY_FUNCTION__, capacity);
    CFAssert2(0 <= numValues, __kCFLogAssertion, "%s(): numValues (%d) cannot be less than zero", __PRETTY_FUNCTION__, numValues);
    size = sizeof(struct __CFBinaryHeap) - sizeof(CFRuntimeBase);
    if (CF_IS_COLLECTABLE_ALLOCATOR(allocator)) {
	if (!callBacks || (callBacks->retain == NULL && callBacks->release == NULL)) {
	    __CFBitfieldSetValue(flags, 4, 4, 1); // setWeak
	}
    }

    memory = (CFBinaryHeapRef)_CFRuntimeCreateInstance(allocator, __kCFBinaryHeapTypeID, size, NULL);
    if (NULL == memory) {
	return NULL;
    }
	__CFBinaryHeapSetCapacity(memory, __CFBinaryHeapRoundUpCapacity(1));
	__CFBinaryHeapSetNumBuckets(memory, __CFBinaryHeapNumBucketsForCapacity(__CFBinaryHeapRoundUpCapacity(1)));
	void *buckets = _CFAllocatorAllocateGC(allocator, __CFBinaryHeapNumBuckets(memory) * sizeof(struct __CFBinaryHeapBucket), isStrongMemory_Heap(memory) ? __kCFAllocatorGCScannedMemory : 0);
	__CFAssignWithWriteBarrier((void **)&memory->_buckets, buckets);
	if (__CFOASafe) __CFSetLastAllocationEventName(memory->_buckets, "CFBinaryHeap (store)");
	if (NULL == memory->_buckets) {
	    CFRelease(memory);
	    return NULL;
	}
    __CFBinaryHeapSetNumBucketsUsed(memory, 0);
    __CFBinaryHeapSetCount(memory, 0);
    if (NULL != callBacks) {
	memory->_callbacks.retain = callBacks->retain;
	memory->_callbacks.release = callBacks->release;
	memory->_callbacks.copyDescription = callBacks->copyDescription;
	memory->_callbacks.compare = callBacks->compare;
    } else {
	memory->_callbacks.retain = 0;
	memory->_callbacks.release = 0;
	memory->_callbacks.copyDescription = 0;
	memory->_callbacks.compare = 0;
    }
    if (compareContext) memcpy(&memory->_context, compareContext, sizeof(CFBinaryHeapCompareContext));
// CF: retain info for proper operation
    __CFBinaryHeapSetMutableVariety(memory, kCFBinaryHeapMutable);
    for (idx = 0; idx < numValues; idx++) {
	CFBinaryHeapAddValue(memory, values[idx]);
    }
    __CFBinaryHeapSetMutableVariety(memory, __CFBinaryHeapMutableVarietyFromFlags(flags));
    return memory;
}
Exemplo n.º 30
0
CFWindowsMessageQueueRef CFWindowsMessageQueueCreate(CFAllocatorRef allocator, DWORD mask) {
    CFWindowsMessageQueueRef memory;
    UInt32 size = sizeof(struct __CFWindowsMessageQueue) - sizeof(CFRuntimeBase);
    memory = (CFWindowsMessageQueueRef)_CFRuntimeCreateInstance(allocator, __kCFWindowsMessageQueueTypeID, size, NULL);
    if (NULL == memory) {
        return NULL;
    }
    __CFWindowsMessageQueueSetValid(memory);

    CF_SPINLOCK_INIT_FOR_STRUCTS(memory->_lock);
    memory->_mask = mask;   
    memory->_source = NULL;
    memory->_runLoops = CFArrayCreateMutable(allocator, 0, NULL);
    return memory;
}