Skip to content

Commit c6a5bc3

Browse files
authored
Use musl's strptime in standalone mode (#22340)
This is a less impactful version of #22158
1 parent 984ebeb commit c6a5bc3

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ addToLibrary({
687687
stringToUTF8(summerName, std_name, {{{ cDefs.TZNAME_MAX + 1 }}});
688688
}
689689
},
690-
#endif
691690

692691
$MONTH_DAYS_REGULAR: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
693692
$MONTH_DAYS_LEAP: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
@@ -1004,6 +1003,7 @@ addToLibrary({
10041003
strptime_l: (buf, format, tm, locale) => {
10051004
return _strptime(buf, format, tm); // no locale support yet
10061005
},
1006+
#endif
10071007

10081008
// ==========================================================================
10091009
// setjmp.h

test/core/test_strptime_reentrant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <string.h>
1414
#include <stdlib.h>
1515

16-
#if __GLIBC__ || __EMSCRIPTEN__
16+
#if defined(__GLIBC__) || (defined(__EMSCRIPTEN__) && !defined(STANDALONE))
1717
// Not all implementations support this (for example, upstream musl)
1818
#define HAVE_WDAY
1919
#endif

test/core/test_strptime_tm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <stdio.h>
1616
#include <string.h>
1717

18-
#if __GLIBC__ || __EMSCRIPTEN__
18+
#if defined(__GLIBC__) || (defined(__EMSCRIPTEN__) && !defined(STANDALONE))
1919
// Not all implementations support these (for example, upstream musl)
2020
#define HAVE_WDAY
2121
#define HAVE_TIMEZONE
@@ -88,15 +88,12 @@ int main() {
8888
#ifdef HAVE_TIMEZONE
8989
// check timezone offsets
9090
STRPTIME("2020-05-01T00:00+0100","%Y-%m-%dT%H:%M%z",&tm);
91-
printf("tm_gmtoff: %ld\n",tm.tm_gmtoff);
9291
assert(tm.tm_gmtoff == 3600);
9392

9493
STRPTIME("2020-05-01T00:00Z","%Y-%m-%dT%H:%M%z",&tm);
95-
printf("tm_gmtoff: %ld\n",tm.tm_gmtoff);
9694
assert(tm.tm_gmtoff == 0);
9795

9896
STRPTIME("2020-05-01T00:00-02:30","%Y-%m-%dT%H:%M%z",&tm);
99-
printf("tm_gmtoff: %ld\n",tm.tm_gmtoff);
10097
assert(tm.tm_gmtoff == -9000);
10198
#endif
10299

test/core/test_strptime_tm.out

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ december: 11
2121
2345,3,31,12,34,56
2222
2003,1,2,12,34,56
2323
2003,1,2,12,34,56
24-
tm_gmtoff: 3600
25-
tm_gmtoff: 0
26-
tm_gmtoff: -9000
2724
12,34,56
2825
12,34,56
2926
12,34,56

test/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,13 +2681,19 @@ def test_time_c(self):
26812681
def test_gmtime(self):
26822682
self.do_core_test('test_gmtime.c')
26832683

2684+
@also_with_standalone_wasm()
26842685
def test_strptime_tm(self):
2686+
if self.get_setting('STANDALONE_WASM'):
2687+
self.emcc_args += ['-DSTANDALONE']
26852688
self.do_core_test('test_strptime_tm.c')
26862689

26872690
def test_strptime_days(self):
26882691
self.do_core_test('test_strptime_days.c')
26892692

2693+
@also_with_standalone_wasm()
26902694
def test_strptime_reentrant(self):
2695+
if self.get_setting('STANDALONE_WASM'):
2696+
self.emcc_args += ['-DSTANDALONE']
26912697
self.do_core_test('test_strptime_reentrant.c')
26922698

26932699
@crossplatform

tools/system_libs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,7 @@ def get_files(self):
22042204
'localtime_r.c',
22052205
'gmtime_r.c',
22062206
'mktime.c',
2207+
'strptime.c',
22072208
'timegm.c',
22082209
'time.c'])
22092210
# It is more efficient to use JS for __assert_fail, as it avoids always

0 commit comments

Comments
 (0)