Skip to content

Commit 7ca8c82

Browse files
authored
Remove __tm_timezone static allocation in JS (#12042)
Helps WebAssembly/binaryen#3043
1 parent 334c79c commit 7ca8c82

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/library.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,6 @@ LibraryManager.library = {
10601060
return time1 - time0;
10611061
},
10621062

1063-
// Statically allocated copy of the string "GMT" for gmtime() to point to
1064-
__tm_timezone: '{{{ makeStaticString("GMT") }}}',
10651063
mktime__deps: ['tzset'],
10661064
mktime__sig: 'ii',
10671065
mktime: function(tmPtr) {
@@ -1101,7 +1099,9 @@ LibraryManager.library = {
11011099
},
11021100
timelocal: 'mktime',
11031101

1104-
gmtime_r__deps: ['__tm_timezone'],
1102+
#if MINIMAL_RUNTIME
1103+
gmtime_r__deps: ['allocateUTF8'],
1104+
#endif
11051105
gmtime_r__sig: 'iii',
11061106
gmtime_r: function(time, tmPtr) {
11071107
var date = new Date({{{ makeGetValue('time', 0, 'i32') }}}*1000);
@@ -1117,8 +1117,9 @@ LibraryManager.library = {
11171117
var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0);
11181118
var yday = ((date.getTime() - start) / (1000 * 60 * 60 * 24))|0;
11191119
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_yday, 'yday', 'i32') }}};
1120-
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_zone, '___tm_timezone', 'i32') }}};
1121-
1120+
// Allocate a string "GMT" for us to point to.
1121+
if (!_gmtime_r.GMTString) _gmtime_r.GMTString = allocateUTF8("GMT");
1122+
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_zone, '_gmtime_r.GMTString', 'i32') }}};
11221123
return tmPtr;
11231124
},
11241125
__gmtime_r: 'gmtime_r',
@@ -1143,7 +1144,7 @@ LibraryManager.library = {
11431144
return (date.getTime() / 1000)|0;
11441145
},
11451146

1146-
localtime_r__deps: ['__tm_timezone', 'tzset'],
1147+
localtime_r__deps: ['tzset'],
11471148
localtime_r__sig: 'iii',
11481149
localtime_r: function(time, tmPtr) {
11491150
_tzset();

0 commit comments

Comments
 (0)