| 2 | |
| 3 | To come back to this, I'd just add that I've never actually seen the bad behavior referenced here occur myself but maybe you could do something like: |
| 4 | |
| 5 | {{{ |
| 6 | #include <unistd.h> |
| 7 | #include <CoreFoundation/CFPreferences.h> |
| 8 | #include <objc/objc-runtime.h> |
| 9 | |
| 10 | int main() { |
| 11 | |
| 12 | Class __SwiftNativeNSStringBase = objc_getClass("__SwiftNativeNSStringBase"); |
| 13 | id funAlloc = ((id (*)(Class, SEL))objc_msgSend) (__SwiftNativeNSStringBase, sel_registerName("alloc")); |
| 14 | |
| 15 | // via bash`reset_locale_vars > libintl.8.dylib`libintl_setlocale > .`_libintl_locale_name_default |
| 16 | CFTypeRef preferences = CFPreferencesCopyAppValue(CFSTR("AppleLocale"), kCFPreferencesCurrentApplication); |
| 17 | if (fork()== 0) { |
| 18 | // via bash`execute_disk_command > libintl.8.dylib`libintl_gettext > .`libintl_dcgettext > .`libintl_dcigettext > .`guess_category_value > .`_libintl_language_preferences_default |
| 19 | CFArrayRef prefArray = CFLocaleCopyPreferredLanguages(); |
| 20 | } |
| 21 | } |
| 22 | // compile like clang -g -framework Foundation -o main main.c |
| 23 | // run like OBJC_PRINT_INITIALIZE_METHODS=YES ./main 2>&1 | grep "__SwiftNativeNSStringBase" |
| 24 | }}} |
| 25 | |
| 26 | to force the `__SwiftNativeNSStringBase` class initializer to run before the fork(). I'd guess that the workaround in https://trac.macports.org/ticket/68638?cnum_edit=26#comment:11 does something like that but not sure and YMMV. |