this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fixing CoreServices/MacLocales and the mach_semaphore test

+45 -11
+41 -7
src/CoreServices/MacLocales.cpp
··· 9 9 #include <iconv.h> 10 10 #include <errno.h> 11 11 #include <cassert> 12 + #include <string> 13 + #include <map> 14 + #include "../util/mutex.h" 12 15 13 16 static iconv_t g_icUtf32ToUtf16 = nullptr; 14 17 18 + static std::map<std::string,int> g_mapLocaleString; 19 + static std::map<int,std::string> g_mapLocaleStringRev; 20 + static Darling::Mutex g_mapLocaleStringMutex; 21 + 15 22 __attribute__((constructor)) void initConversions() 16 23 { 17 24 g_icUtf32ToUtf16 = iconv_open("UTF-16", "UTF-32"); ··· 23 30 iconv_close(g_icUtf32ToUtf16); 24 31 } 25 32 33 + static int getLocaleUID(const std::string& str) 34 + { 35 + auto it = g_mapLocaleString.find(str); 36 + if (it != g_mapLocaleString.end()) 37 + return it->second; 38 + else 39 + { 40 + g_mapLocaleStringMutex.lock(); 41 + size_t id = g_mapLocaleString.size()+1; 42 + 43 + g_mapLocaleString[str] = id; 44 + g_mapLocaleStringRev[id] = str; 45 + g_mapLocaleStringMutex.unlock(); 46 + 47 + return id; 48 + } 49 + } 50 + 51 + static const char* getLocaleString(int uid) 52 + { 53 + auto it = g_mapLocaleStringRev.find(uid); 54 + if (it != g_mapLocaleStringRev.end()) 55 + return it->second.c_str(); 56 + else 57 + return "INVALID"; 58 + } 59 + 26 60 OSStatus LocaleRefFromLangOrRegionCode(LangCode langCode, RegionCode regionCode, LocaleRef* refOut) 27 61 { 28 62 if (langCode == kTextLanguageDontCare || regionCode == kTextRegionDontCare) 29 63 { 30 - *refOut = Locale::getDefault().getName(); 64 + *refOut = getLocaleUID(Locale::getDefault().getName()); 31 65 return 0; 32 66 } 33 67 ··· 47 81 } 48 82 else 49 83 { 50 - *refOut = loc.getName(); 84 + *refOut = getLocaleUID(loc.getName()); 51 85 return 0; 52 86 } 53 87 } ··· 62 96 } 63 97 else 64 98 { 65 - *refOut = loc.getName(); 99 + *refOut = getLocaleUID(loc.getBaseName()); 66 100 return 0; 67 101 } 68 102 } 69 103 70 104 OSStatus LocaleRefGetPartString(LocaleRef ref, uint32_t partMask, unsigned long maxStringLen, char* stringOut) 71 105 { 72 - Locale loc(ref); 106 + Locale loc(getLocaleString(ref)); 73 107 char buffer[50] = ""; 74 108 75 109 if (loc.isBogus()) ··· 139 173 140 174 for (int i = 0; i < cc && i < max; i++) 141 175 { 142 - out[i].ref = locales[i].getName(); 176 + out[i].ref = getLocaleUID(locales[i].getName()); 143 177 out[i].variant = 0; 144 178 } 145 179 *countOut = std::min<int32_t>(cc, max); ··· 150 184 OSStatus LocaleGetName(LocaleRef ref, LocaleOperationVariant variant, uint32_t nameMask, 151 185 LocaleRef refDisplay, unsigned long maxLen, unsigned long* lenOut, Utf16Char* displayName) 152 186 { 153 - Locale loc(ref); 154 - Locale locDisplay(refDisplay); 187 + Locale loc(getLocaleString(ref)); 188 + Locale locDisplay(getLocaleString(refDisplay)); 155 189 156 190 // variant and nameMask currently ignored 157 191
+1 -1
src/CoreServices/MacLocales.h
··· 7 7 typedef int16_t LangCode; 8 8 typedef int16_t Utf16Char; 9 9 10 - typedef const char* LocaleRef; 10 + typedef int LocaleRef; 11 11 typedef uint32_t LocaleOperationClass; 12 12 typedef uint32_t LocaleOperationVariant; 13 13
+3 -3
tests/src/mach_semaphore.c
··· 20 20 start_routine(void *id) 21 21 { 22 22 semaphore_signal(g_sem[1]); 23 - printf("thread: %lx about to decrement semaphore count\n", id); 23 + fprintf(stderr, "thread: %lx about to decrement semaphore count\n", id); 24 24 semaphore_wait(g_sem[0]); 25 - printf("thread: %lx succeeded in decrementing semaphore count\n", id); 25 + fprintf(stderr, "thread: %lx succeeded in decrementing semaphore count\n", id); 26 26 semaphore_signal(g_sem[1]); 27 - return (void *)0; 27 + return NULL; 28 28 } 29 29 30 30 int