Skip to content
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
5 changes: 0 additions & 5 deletions src/lib/libmemfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ addToLibrary({
attr.atime = new Date(node.atime);
attr.mtime = new Date(node.mtime);
attr.ctime = new Date(node.ctime);
// A Date only holds whole milliseconds: also return the exact times
// (e.g. as set by utimensat), which SYSCALLS.writeStat prefers.
attr.atimeMs = node.atime;
attr.mtimeMs = node.mtime;
attr.ctimeMs = node.ctime;
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
// but this is not required by the standard.
attr.blksize = 4096;
Expand Down
3 changes: 0 additions & 3 deletions src/lib/libnodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ addToLibrary({
atime: stat.atime,
mtime: stat.mtime,
ctime: stat.ctime,
atimeMs: stat.atimeMs,
mtimeMs: stat.mtimeMs,
ctimeMs: stat.ctimeMs,
blksize: stat.blksize,
blocks: stat.blocks
};
Expand Down
20 changes: 7 additions & 13 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@ var SyscallsLibrary = {
{{{ makeSetValue('buf', C_STRUCTS.stat.st_size, 'stat.size', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blksize, '4096', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blocks, 'stat.blocks', 'i32') }}};
// Prefer `*Ms` properties if available (e.g. from MEMFS, or NODEFS / host
// `fs.Stats`) for sub-millisecond precision; fall back to Date#getTime for
// other filesystems.
var atime = stat.atimeMs ?? stat.atime.getTime();
var mtime = stat.mtimeMs ?? stat.mtime.getTime();
var ctime = stat.ctimeMs ?? stat.ctime.getTime();
var atime = stat.atime.getTime();
var mtime = stat.mtime.getTime();
var ctime = stat.ctime.getTime();
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_sec, 'Math.floor(atime / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_nsec, 'Math.floor((atime % 1000) * 1_000_000)', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_nsec, '(atime % 1000) * 1000 * 1000', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_sec, 'Math.floor(mtime / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, 'Math.floor((mtime % 1000) * 1_000_000)', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, '(mtime % 1000) * 1000 * 1000', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_sec, 'Math.floor(ctime / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, 'Math.floor((ctime % 1000) * 1_000_000)', SIZE_TYPE) }}};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the new 1_000_000 syntax?

Does removing Math.floor here have any semantic difference?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want 1_000? I don't see anywhere in the codebase that says that, the _ is only used in numbers at least 5 digits. But I can put it in.

I don't think Math.floor() makes a difference, no.

{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, '(ctime % 1000) * 1000 * 1000', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}};
return 0;
},
Expand Down Expand Up @@ -1092,10 +1089,7 @@ var SyscallsLibrary = {
return null;
}
var tv_sec = {{{ makeGetValue('ptr', C_STRUCTS.timespec.tv_sec, 'i53') }}};
// Round down tv_nsec to the nearest 10 microseconds (10,000 ns) to prevent
// floating-point rounding into the next whole second when converting to host/Windows timestamps.
tv_nsec = (tv_nsec / 10_000 | 0) * 10_000;
return (tv_sec + (tv_nsec / 1_000_000_000)) * 1000;
return (tv_sec*1000) + Math.floor(tv_nsec/(1000*1000));
}
atime = readTimespec(times);
mtime = readTimespec(times + {{{ C_STRUCTS.timespec.__size__ }}});
Expand Down
6 changes: 1 addition & 5 deletions system/lib/wasmfs/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#define _LARGEFILE64_SOURCE // For F_GETLK64 etc

#include <cmath>
#include <dirent.h>
#include <emscripten/emscripten.h>
#include <emscripten/heap.h>
Expand Down Expand Up @@ -1139,10 +1138,7 @@ static double timespec_to_ms(timespec ts) {
if (ts.tv_nsec == UTIME_NOW) {
return emscripten_date_now();
}
// Round down tv_nsec to the nearest 10 microseconds (10,000 ns) to prevent
// floating-point rounding into the next whole second when converting to host/Windows timestamps.
long tv_nsec_10us = (ts.tv_nsec / 10000) * 10000;
return (double(ts.tv_sec) + double(tv_nsec_10us) / 1e9) * 1000;
return double(ts.tv_sec) * 1000 + double(ts.tv_nsec / (1000 * 1000));
}

// TODO: Test this with non-AT_FDCWD values.
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19180,
"a.out.js.gz": 8091,
"a.out.js": 19126,
"a.out.js.gz": 8079,
"a.out.nodebug.wasm": 133999,
"a.out.nodebug.wasm.gz": 51252,
"total": 153179,
"total_gz": 59343,
"total": 153125,
"total_gz": 59331,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19157,
"a.out.js.gz": 8074,
"a.out.js": 19103,
"a.out.js.gz": 8063,
"a.out.nodebug.wasm": 133427,
"a.out.nodebug.wasm.gz": 50944,
"total": 152584,
"total_gz": 59018,
"total": 152530,
"total_gz": 59007,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22874,
"a.out.js.gz": 9053,
"a.out.js": 22820,
"a.out.js.gz": 9041,
"a.out.nodebug.wasm": 176407,
"a.out.nodebug.wasm.gz": 58760,
"total": 199281,
"total_gz": 67813,
"total": 199227,
"total_gz": 67801,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18979,
"a.out.js.gz": 8010,
"a.out.js": 18925,
"a.out.js.gz": 7999,
"a.out.nodebug.wasm": 149664,
"a.out.nodebug.wasm.gz": 56300,
"total": 168643,
"total_gz": 64310,
"total": 168589,
"total_gz": 64299,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19057,
"a.out.js.gz": 8033,
"a.out.js": 19003,
"a.out.js.gz": 8022,
"a.out.nodebug.wasm": 147446,
"a.out.nodebug.wasm.gz": 55963,
"total": 166503,
"total_gz": 63996,
"total": 166449,
"total_gz": 63985,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18520,
"a.out.js.gz": 7786,
"a.out.js": 18466,
"a.out.js.gz": 7775,
"a.out.nodebug.wasm": 101050,
"a.out.nodebug.wasm.gz": 38287,
"total": 119570,
"total_gz": 46073,
"total": 119516,
"total_gz": 46062,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22924,
"a.out.js.gz": 9073,
"a.out.js": 22870,
"a.out.js.gz": 9061,
"a.out.nodebug.wasm": 242687,
"a.out.nodebug.wasm.gz": 80983,
"total": 265611,
"total_gz": 90056,
"total": 265557,
"total_gz": 90044,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_noexcept.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19180,
"a.out.js.gz": 8091,
"a.out.js": 19126,
"a.out.js.gz": 8079,
"a.out.nodebug.wasm": 135906,
"a.out.nodebug.wasm.gz": 51862,
"total": 155086,
"total_gz": 59953,
"total": 155032,
"total_gz": 59941,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
20 changes: 6 additions & 14 deletions test/codesize/test_codesize_file_preload.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,6 @@ var MEMFS = {
attr.atime = new Date(node.atime);
attr.mtime = new Date(node.mtime);
attr.ctime = new Date(node.ctime);
// A Date only holds whole milliseconds: also return the exact times
// (e.g. as set by utimensat), which SYSCALLS.writeStat prefers.
attr.atimeMs = node.atime;
attr.mtimeMs = node.mtime;
attr.ctimeMs = node.ctime;
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
// but this is not required by the standard.
attr.blksize = 4096;
Expand Down Expand Up @@ -3029,18 +3024,15 @@ var SYSCALLS = {
HEAP64[(((buf) + (24)) >> 3)] = BigInt(stat.size);
HEAP32[(((buf) + (32)) >> 2)] = 4096;
HEAP32[(((buf) + (36)) >> 2)] = stat.blocks;
// Prefer `*Ms` properties if available (e.g. from MEMFS, or NODEFS / host
// `fs.Stats`) for sub-millisecond precision; fall back to Date#getTime for
// other filesystems.
var atime = stat.atimeMs ?? stat.atime.getTime();
var mtime = stat.mtimeMs ?? stat.mtime.getTime();
var ctime = stat.ctimeMs ?? stat.ctime.getTime();
var atime = stat.atime.getTime();
var mtime = stat.mtime.getTime();
var ctime = stat.ctime.getTime();
HEAP64[(((buf) + (40)) >> 3)] = BigInt(Math.floor(atime / 1e3));
HEAPU32[(((buf) + (48)) >> 2)] = Math.floor((atime % 1e3) * 1e6);
HEAPU32[(((buf) + (48)) >> 2)] = (atime % 1e3) * 1e3 * 1e3;
HEAP64[(((buf) + (56)) >> 3)] = BigInt(Math.floor(mtime / 1e3));
HEAPU32[(((buf) + (64)) >> 2)] = Math.floor((mtime % 1e3) * 1e6);
HEAPU32[(((buf) + (64)) >> 2)] = (mtime % 1e3) * 1e3 * 1e3;
HEAP64[(((buf) + (72)) >> 3)] = BigInt(Math.floor(ctime / 1e3));
HEAPU32[(((buf) + (80)) >> 2)] = Math.floor((ctime % 1e3) * 1e6);
HEAPU32[(((buf) + (80)) >> 2)] = (ctime % 1e3) * 1e3 * 1e3;
HEAP64[(((buf) + (88)) >> 3)] = BigInt(stat.ino);
return 0;
},
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_file_preload.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22232,
"a.out.js.gz": 9258,
"a.out.js": 22178,
"a.out.js.gz": 9246,
"a.out.nodebug.wasm": 1198,
"a.out.nodebug.wasm.gz": 730,
"total": 23430,
"total_gz": 9988,
"total": 23376,
"total_gz": 9976,
"sent": [
"a (fd_write)"
],
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_files_js_fs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 17831,
"a.out.js.gz": 7432,
"a.out.js": 17777,
"a.out.js.gz": 7410,
"a.out.nodebug.wasm": 381,
"a.out.nodebug.wasm.gz": 258,
"total": 18212,
"total_gz": 7690,
"total": 18158,
"total_gz": 7668,
"sent": [
"a (fd_write)",
"b (fd_read)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 26380,
"a.out.js.gz": 11230,
"a.out.js": 26268,
"a.out.js.gz": 11199,
"a.out.nodebug.wasm": 16986,
"a.out.nodebug.wasm.gz": 8672,
"total": 43366,
"total_gz": 19902,
"total": 43254,
"total_gz": 19871,
"sent": [
"__syscall_stat64",
"emscripten_resize_heap",
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 272661,
"a.out.js": 272550,
"a.out.nodebug.wasm": 587934,
"total": 860595,
"total": 860484,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_no_closure_code_size.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"strict.js.gz": 2296,
"strict.wasm": 1188,
"strict.wasm.gz": 733,
"files.js": 53945,
"files.js.gz": 15176,
"files.js": 53807,
"files.js.gz": 15143,
"files.wasm": 371,
"files.wasm.gz": 264,
"total": 77816,
"total_gz": 25071
"total": 77678,
"total_gz": 25038
}
47 changes: 0 additions & 47 deletions test/fs/test_fs_subms_times.c

This file was deleted.

6 changes: 0 additions & 6 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5977,12 +5977,6 @@ def test_fs_write(self):
self.set_setting("FORCE_FILESYSTEM")
self.do_runf_out_file('fs/test_fs_write.c')

@crossplatform
@with_all_fs
@no_deno('https://github.com/emscripten-core/emscripten/pull/27890')
def test_fs_subms_times(self):
self.do_runf('fs/test_fs_subms_times.c', 'done\n')

@with_all_fs
def test_fs_access_mode(self):
# Writing to an O_RDONLY fd and reading from an O_WRONLY fd must fail with
Expand Down
8 changes: 8 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5811,6 +5811,14 @@ def test_strftime_zZ(self):
def test_strptime_symmetry(self):
self.do_other_test('test_strptime_symmetry.c')

def test_utime_now(self):
self.do_runf('utime/test_utime_now.c', 'done\n')

@crossplatform
@also_with_nodefs_both
Comment thread
hoodmane marked this conversation as resolved.
def test_utime_roundtrip(self):
self.do_runf('utime/test_utime_roundtrip.c', 'done\n')

@also_with_wasmfs
def test_truncate_from_0(self):
self.do_other_test('test_truncate_from_0.cpp')
Expand Down
Loading
Loading