コード例 #1
0
ファイル: unixinterface.cpp プロジェクト: Afshintm/coreclr
// Convert 8 bit string to unicode
static LPCWSTR StringToUnicode(LPCSTR str)
{
    int length = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
    ASSERTE_ALL_BUILDS(length != 0);

    LPWSTR result = new (nothrow) WCHAR[length];
    ASSERTE_ALL_BUILDS(result != NULL);
    
    length = MultiByteToWideChar(CP_ACP, 0, str, length, result, length);
    ASSERTE_ALL_BUILDS(length != 0);

    return result;
}
コード例 #2
0
ファイル: unixinterface.cpp プロジェクト: Afshintm/coreclr
// Convert 8 bit string array to unicode string array
static LPCWSTR* StringArrayToUnicode(int argc, LPCSTR* argv)
{
    LPCWSTR* argvW = nullptr;
    
    if (argc > 0)
    {
        argvW = new (nothrow) LPCWSTR[argc];
        ASSERTE_ALL_BUILDS(argvW != 0);
        
        for (int i = 0; i < argc; i++)
        {
            argvW[i] = StringToUnicode(argv[i]);
        }
    }

    return argvW;
}
コード例 #3
0
ファイル: unixinterface.cpp プロジェクト: QtRoS/coreclr
static void ExtractStartupFlagsAndConvertToUnicode(
    const char** propertyKeys,
    const char** propertyValues,
    int* propertyCountRef,
    STARTUP_FLAGS* startupFlagsRef,
    LPCWSTR** propertyKeysWRef,
    LPCWSTR** propertyValuesWRef)
{
    int propertyCount = *propertyCountRef;

    LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
    ASSERTE_ALL_BUILDS(propertyKeysW != nullptr);

    LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[propertyCount];
    ASSERTE_ALL_BUILDS(propertyValuesW != nullptr);

    // Extract the startup flags from the properties, and convert the remaining properties into unicode
    STARTUP_FLAGS startupFlags =
        static_cast<STARTUP_FLAGS>(
            STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
            STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN);
    int propertyCountW = 0;
    for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
    {
        auto SetFlagValue = [&](STARTUP_FLAGS flag)
        {
            if (strcmp(propertyValues[propertyIndex], "0") == 0)
            {
                startupFlags = static_cast<STARTUP_FLAGS>(startupFlags & ~flag);
            }
            else if (strcmp(propertyValues[propertyIndex], "1") == 0)
            {
                startupFlags = static_cast<STARTUP_FLAGS>(startupFlags | flag);
            }
        };

        if (strcmp(propertyKeys[propertyIndex], "CONCURRENT_GC") == 0)
        {
            SetFlagValue(STARTUP_CONCURRENT_GC);
        }
        else if (strcmp(propertyKeys[propertyIndex], "SERVER_GC") == 0)
        {
            SetFlagValue(STARTUP_SERVER_GC);
        }
        else if (strcmp(propertyKeys[propertyIndex], "HOARD_GC_VM") == 0)
        {
            SetFlagValue(STARTUP_HOARD_GC_VM);
        }
        else if (strcmp(propertyKeys[propertyIndex], "TRIM_GC_COMMIT") == 0)
        {
            SetFlagValue(STARTUP_TRIM_GC_COMMIT);
        }
        else
        {
            // This is not a CoreCLR startup flag, convert it to unicode and preserve it for returning
            propertyKeysW[propertyCountW] = StringToUnicode(propertyKeys[propertyIndex]);
            propertyValuesW[propertyCountW] = StringToUnicode(propertyValues[propertyIndex]);
            ++propertyCountW;
        }
    }

    for (int propertyIndex = propertyCountW; propertyIndex < propertyCount; ++propertyIndex)
    {
        propertyKeysW[propertyIndex] = nullptr;
        propertyValuesW[propertyIndex] = nullptr;
    }

    *propertyCountRef = propertyCountW;
    *startupFlagsRef = startupFlags;
    *propertyKeysWRef = propertyKeysW;
    *propertyValuesWRef = propertyValuesW;
}