diff --git a/ChangeLog.md b/ChangeLog.md index fe0455caeb92a..331abb4a073ad 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works. Current Trunk ------------- +- Calls to `newlocale` (and `new std::locale` in C++) with arbirary names will + now succeed. This is the behaviour of musl libc which emscripten had + previously inadvertently disabled. - System libraries are now compiled with debug info (`-g`). This doesn't affect release builds (builds without `-g`) but allows DWARF debugging of types defined in system libraries such as C++ STL types (#13078). diff --git a/system/lib/libc/musl/src/locale/newlocale.c b/system/lib/libc/musl/src/locale/newlocale.c index bbc312084efbd..f50bbe9132df3 100644 --- a/system/lib/libc/musl/src/locale/newlocale.c +++ b/system/lib/libc/musl/src/locale/newlocale.c @@ -41,6 +41,8 @@ locale_t __newlocale(int mask, const char *name, locale_t loc) if (j==1 && tmp.cat[LC_CTYPE]==&__c_dot_utf8) return UTF8_LOCALE; + if ((loc = malloc(sizeof *loc))) *loc = tmp; + return loc; } diff --git a/tests/test_locale.c b/tests/core/test_localeconv.c similarity index 100% rename from tests/test_locale.c rename to tests/core/test_localeconv.c diff --git a/tests/test_locale.out b/tests/core/test_localeconv.out similarity index 100% rename from tests/test_locale.out rename to tests/core/test_localeconv.out diff --git a/tests/core/test_newlocale.c b/tests/core/test_newlocale.c new file mode 100644 index 0000000000000..26264aa3dd653 --- /dev/null +++ b/tests/core/test_newlocale.c @@ -0,0 +1,16 @@ +#include +#include + +void test(const char* name) { + locale_t loc = newlocale(LC_ALL_MASK, name, 0); + if (loc) + printf("newlocale '%s' succeeded\n", name); + else + printf("newlocale '%s' failed\n", name); +} + +int main(int argc, char* argv[]) { + test("C"); + test("waka"); + return 0; +} diff --git a/tests/core/test_newlocale.out b/tests/core/test_newlocale.out new file mode 100644 index 0000000000000..cde3005a114d9 --- /dev/null +++ b/tests/core/test_newlocale.out @@ -0,0 +1,2 @@ +newlocale 'C' succeeded +newlocale 'waka' succeeded diff --git a/tests/core/test_setlocale.c b/tests/core/test_setlocale.c new file mode 100644 index 0000000000000..1918d603e2a52 --- /dev/null +++ b/tests/core/test_setlocale.c @@ -0,0 +1,11 @@ +#include +#include + +int main(int argc, char* argv[]) { + char* rtn; + rtn = setlocale(LC_ALL, "C"); + printf("done setlocale 'C': '%s'\n", rtn); + rtn = setlocale(LC_ALL, "waka"); + printf("done setlocale 'waka': '%s'\n", rtn); + return 0; +} diff --git a/tests/core/test_setlocale.out b/tests/core/test_setlocale.out new file mode 100644 index 0000000000000..e01346ffaa09b --- /dev/null +++ b/tests/core/test_setlocale.out @@ -0,0 +1,2 @@ +done setlocale 'C': 'C;C;C;C;C;C' +done setlocale 'waka': 'waka;waka;waka;waka;waka;waka' diff --git a/tests/test_core.py b/tests/test_core.py index 0a828db43ecb9..6ceda4ed79997 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -7295,8 +7295,14 @@ def test_noexitruntime(self): def test_minmax(self): self.do_runf(path_from_root('tests', 'test_minmax.c'), 'NAN != NAN\nSuccess!') - def test_locale(self): - self.do_run_in_out_file_test('tests', 'test_locale.c') + def test_localeconv(self): + self.do_run_in_out_file_test('tests', 'core', 'test_localeconv.c') + + def test_newlocale(self): + self.do_run_in_out_file_test('tests', 'core', 'test_newlocale.c') + + def test_setlocale(self): + self.do_run_in_out_file_test('tests', 'core', 'test_setlocale.c') def test_vswprintf_utf8(self): self.do_run_in_out_file_test('tests', 'vswprintf_utf8.c') diff --git a/tests/test_other.py b/tests/test_other.py index 790f8d9894fb6..1edf45d408355 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -4679,8 +4679,16 @@ def test_locale_wrong(self): } ''') self.run_process([EMCC, 'src.cpp', '-s', 'EXIT_RUNTIME', '-s', 'DISABLE_EXCEPTION_CATCHING=0']) - self.assertContained('Constructed locale "C"\nThis locale is the global locale.\nThis locale is the C locale.', self.run_js('a.out.js', args=['C'])) - self.assertContained('''Can't construct locale "waka": collate_byname::collate_byname failed to construct for waka''', self.run_js('a.out.js', args=['waka'], assert_returncode=1)) + self.assertContained('''\ +Constructed locale "C" +This locale is the global locale. +This locale is the C locale. +''', self.run_js('a.out.js', args=['C'])) + self.assertContained('''\ +Constructed locale "waka" +This locale is not the global locale. +This locale is not the C locale. +''', self.run_js('a.out.js', args=['waka'])) def test_cleanup_os(self): # issue 2644