Skip to content

Use musl's strptime in standalone mode #22340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ addToLibrary({
stringToUTF8(summerName, std_name, {{{ cDefs.TZNAME_MAX + 1 }}});
}
},
#endif

$MONTH_DAYS_REGULAR: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
$MONTH_DAYS_LEAP: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
Expand Down Expand Up @@ -1004,6 +1003,7 @@ addToLibrary({
strptime_l: (buf, format, tm, locale) => {
return _strptime(buf, format, tm); // no locale support yet
},
#endif

// ==========================================================================
// setjmp.h
Expand Down
2 changes: 1 addition & 1 deletion test/core/test_strptime_reentrant.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string.h>
#include <stdlib.h>

#if __GLIBC__ || __EMSCRIPTEN__
#if defined(__GLIBC__) || (defined(__EMSCRIPTEN__) && !defined(STANDALONE))
// Not all implementations support this (for example, upstream musl)
#define HAVE_WDAY
#endif
Expand Down
5 changes: 1 addition & 4 deletions test/core/test_strptime_tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdio.h>
#include <string.h>

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

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

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

Expand Down
3 changes: 0 additions & 3 deletions test/core/test_strptime_tm.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ december: 11
2345,3,31,12,34,56
2003,1,2,12,34,56
2003,1,2,12,34,56
tm_gmtoff: 3600
tm_gmtoff: 0
tm_gmtoff: -9000
12,34,56
12,34,56
12,34,56
6 changes: 6 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,13 +2681,19 @@ def test_time_c(self):
def test_gmtime(self):
self.do_core_test('test_gmtime.c')

@also_with_standalone_wasm()
def test_strptime_tm(self):
if self.get_setting('STANDALONE_WASM'):
self.emcc_args += ['-DSTANDALONE']
self.do_core_test('test_strptime_tm.c')

def test_strptime_days(self):
self.do_core_test('test_strptime_days.c')

@also_with_standalone_wasm()
def test_strptime_reentrant(self):
if self.get_setting('STANDALONE_WASM'):
self.emcc_args += ['-DSTANDALONE']
self.do_core_test('test_strptime_reentrant.c')

@crossplatform
Expand Down
1 change: 1 addition & 0 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,7 @@ def get_files(self):
'localtime_r.c',
'gmtime_r.c',
'mktime.c',
'strptime.c',
'timegm.c',
'time.c'])
# It is more efficient to use JS for __assert_fail, as it avoids always
Expand Down
Loading