RSInline RSDictionaryRef __RSProcessInfoGetEnvironment(RSProcessInfoRef processInfo) {
    RSDictionaryRef dict = __RSProcessInfoObjectForKey(processInfo, __RSProcessInfoEnvironment);
    if (dict) return dict;
    RSMutableDictionaryRef environment = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryRSTypeContext);
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_IPHONEOS
    __RSDictionaryAddEnvWithCString(environment, "Apple_PubSub_Socket_Render");
    __RSDictionaryAddEnvWithCString(environment, "DYLD_FRAMEWORK_PATH");
    __RSDictionaryAddEnvWithCString(environment, "DYLD_LIBRARY_PATH");
#endif
    __RSDictionaryAddEnvWithCString(environment, "HOME");
    __RSDictionaryAddEnvWithCString(environment, "LOGNAME");
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_IPHONEOS
    __RSDictionaryAddEnvWithCString(environment, "NSUnbufferedIO");
#endif
    __RSDictionaryAddEnvWithCString(environment, "PATH");
    __RSDictionaryAddEnvWithCString(environment, "PWD");
    __RSDictionaryAddEnvWithCString(environment, "SHELL");
    __RSDictionaryAddEnvWithCString(environment, "SSH_AUTH_SOCK");
    __RSDictionaryAddEnvWithCString(environment, "TMPDIR");
    __RSDictionaryAddEnvWithCString(environment, "USER");
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_IPHONEOS
    __RSDictionaryAddEnvWithCString(environment, "__CF_USER_TEXT_ENCODING");
    __RSDictionaryAddEnvWithCString(environment, "__XCODE_BUILT_PRODUCTS_DIR_PATHS");
    __RSDictionaryAddEnvWithCString(environment, "__XPC_DYLD_FRAMEWORK_PATH");
    __RSDictionaryAddEnvWithCString(environment, "__XPC_DYLD_LIBRARY_PATH");
#endif
    __RSProcessInfoSetObjectForKey(processInfo, __RSProcessInfoEnvironment, environment);
    RSRelease(environment);
    __RSRuntimeSetInstanceSpecial(environment, YES);    // now environment retain count = 1
    return environment;
}
static RSProcessInfoRef __RSProcessInfoCreateInstance(RSAllocatorRef allocator, RSDictionaryRef content) {
    RSProcessInfoRef instance = (RSProcessInfoRef)__RSRuntimeCreateInstance(allocator, _RSProcessInfoTypeID, sizeof(struct __RSProcessInfo) - sizeof(RSRuntimeBase));
    
    if (content) {
        instance->_info = RSMutableCopy(allocator, content);
    } else {
        instance->_info = RSDictionaryCreateMutable(RSAllocatorDefault, 0, RSDictionaryRSTypeContext);
    }
    __RSRuntimeSetInstanceSpecial(instance->_info, YES);
    
    return instance;
}
static BOOL __RSProcessInfoUpdateKeys(RSProcessInfoRef processInfo, RSArrayRef lookupKeys, RSArrayRef description, RSStringRef key) {
    if (key == nil || lookupKeys == nil) return NO;
    if (description == nil) description = lookupKeys;
    const RSUInteger keyCount = RSArrayGetCount(lookupKeys);
    if (keyCount > RSArrayGetCount(description)) return NO;
    RSUInteger successCount = 0;
    RSMutableDictionaryRef dict = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryRSTypeContext);
    if (dict)
    {
        for (RSUInteger idx = 0; idx < keyCount; idx++)
        {
            successCount += __RSProcessInfoUpdate(dict, RSArrayObjectAtIndex(lookupKeys, idx), RSArrayObjectAtIndex(description, idx));
        }
        __RSProcessInfoSetObjectForKey(processInfo, key, dict);
        RSRelease(dict);
    }
    return successCount == keyCount;
}
Beispiel #4
0
static void __RSErrorInitUserInfoKeyCallBackTable()
{
    RSMutableDictionaryRef table = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryNilValueContext);
    RSSpinLockLock(&__RSErrorCallBackTableSpinlock);
    if (!__RSErrorCallBackTable) {
        __RSErrorCallBackTable = table;
    }
    else
    {
        RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock);
        return;
    }
    RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock);
    RSErrorSetCallBackForDomain(RSErrorDomainPOSIX, __RSErrorPOSIXCallBack);
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
    RSErrorSetCallBackForDomain(RSErrorDomainMach, __RSErrorMachCallBack);
#endif
    RSErrorSetCallBackForDomain(RSErrorDomainRSCoreFoundation, __RSErrorRSCoreFoundationCallBack);
}
RSExport void RSDictionarySetValueForKeys(RSMutableDictionaryRef dictionary, RSArrayRef keys, RSTypeRef value) {
    if (nil == dictionary || nil == keys || !RSArrayGetCount(keys)) return;
    RSClassRef dictClass = RSClassGetWithUTF8String("RSDictionary");
    RSUInteger cnt = RSArrayGetCount(keys);
    if (cnt < 2) {
        return RSDictionarySetValue(dictionary, RSArrayObjectAtIndex(keys, 0), value);
    }
    cnt --;
    RSMutableDictionaryRef tmp = dictionary, tmp1 = tmp;
    for (RSUInteger idx = 0; idx < cnt; idx++) {
        if (RSInstanceIsMemberOfClass(tmp, dictClass)) {
            tmp1 = (RSMutableDictionaryRef)RSDictionaryGetValue(tmp, RSArrayObjectAtIndex(keys, idx));
            if (!tmp1) {
                tmp1 = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryRSTypeContext);
                RSDictionarySetValue(tmp, RSArrayObjectAtIndex(keys, idx), tmp1);
                RSRelease(tmp1);
            }
            tmp = tmp1;
        } else {
            return ;
        }
    }
    return RSDictionarySetValue(tmp, RSArrayLastObject(keys), value);
}