Changes between Version 2 and Version 3 of Ticket #68638, comment 26


Ignore:
Timestamp:
May 7, 2024, 3:02:08 AM (6 months ago)
Author:
bradleyCPA (B. Holder)
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #68638, comment 26

    v2 v3  
    11That looks pretty spot on to me. The larger problem is bash is now forking [and doing unsafe things -- https://www.man7.org/linux/man-pages/man2/fork.2.html -- in the forked process before exec()] while multithreaded which is a barmy idea and probably a completely unintended side-effect of relying on gnu gettext.
     2
     3To 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
     10int 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
     26to 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.