Skip to content

Commit 07d8b3f

Browse files
committed
Merge branch 'main' into update_libcxx_libcxxabi_19
2 parents 093c537 + 3dff04c commit 07d8b3f

File tree

107 files changed

+318
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+318
-206
lines changed

src/closure-externs/node-externs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ fs.Stats.prototype.mtimeMs;
119119
* @type {number}
120120
*/
121121
fs.Stats.prototype.ctimeMs;
122+
123+
/**
124+
* @param {string} p
125+
* @return {boolean}
126+
* @nosideeffects
127+
*/
128+
path.isAbsolute;
129+
130+
/**
131+
* @type {Object.<string,*>}
132+
*/
133+
path.posix;

src/library_fs.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ FS.staticInit();
193193
break;
194194
}
195195

196-
current = FS.lookupNode(current, parts[i]);
197196
current_path = PATH.join2(current_path, parts[i]);
197+
try {
198+
current = FS.lookupNode(current, parts[i]);
199+
} catch (e) {
200+
// if noent_okay is true, suppress a ENOENT in the last component
201+
// and return an object with an undefined node. This is needed for
202+
// resolving symlinks in the path when creating a file.
203+
if ((e?.errno === {{{ cDefs.ENOENT }}}) && islast && opts.noent_okay) {
204+
return { path: current_path };
205+
}
206+
throw e;
207+
}
198208

199209
// jump to the mount's root node if this is a mountpoint
200210
if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
@@ -1036,14 +1046,15 @@ FS.staticInit();
10361046
node = path;
10371047
} else {
10381048
path = PATH.normalize(path);
1039-
try {
1040-
var lookup = FS.lookupPath(path, {
1041-
follow: !(flags & {{{ cDefs.O_NOFOLLOW }}})
1042-
});
1043-
node = lookup.node;
1044-
} catch (e) {
1045-
// ignore
1046-
}
1049+
// noent_okay makes it so that if the final component of the path
1050+
// doesn't exist, lookupPath returns `node: undefined`. `path` will be
1051+
// updated to point to the target of all symlinks.
1052+
var lookup = FS.lookupPath(path, {
1053+
follow: !(flags & {{{ cDefs.O_NOFOLLOW }}}),
1054+
noent_okay: true
1055+
});
1056+
node = lookup.node;
1057+
path = lookup.path;
10471058
}
10481059
// perhaps we need to create the node
10491060
var created = false;

src/library_memfs.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ addToLibrary({
191191
return MEMFS.createNode(parent, name, mode, dev);
192192
},
193193
rename(old_node, new_dir, new_name) {
194-
// if we're overwriting a directory at new_name, make sure it's empty.
195-
if (FS.isDir(old_node.mode)) {
196-
var new_node;
197-
try {
198-
new_node = FS.lookupNode(new_dir, new_name);
199-
} catch (e) {
200-
}
201-
if (new_node) {
194+
var new_node;
195+
try {
196+
new_node = FS.lookupNode(new_dir, new_name);
197+
} catch (e) {}
198+
if (new_node) {
199+
if (FS.isDir(old_node.mode)) {
200+
// if we're overwriting a directory at new_name, make sure it's empty.
202201
for (var i in new_node.contents) {
203202
throw new FS.ErrnoError({{{ cDefs.ENOTEMPTY }}});
204203
}
205204
}
205+
FS.hashRemoveNode(new_node);
206206
}
207207
// do the internal rewiring
208208
delete old_node.parent.contents[old_node.name];
@@ -223,11 +223,7 @@ addToLibrary({
223223
parent.ctime = parent.mtime = Date.now();
224224
},
225225
readdir(node) {
226-
var entries = ['.', '..'];
227-
for (var key of Object.keys(node.contents)) {
228-
entries.push(key);
229-
}
230-
return entries;
226+
return ['.', '..', ...Object.keys(node.contents)];
231227
},
232228
symlink(parent, newname, oldpath) {
233229
var node = MEMFS.createNode(parent, newname, 0o777 | {{{ cDefs.S_IFLNK }}}, 0);

src/library_nodefs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ addToLibrary({
197197
rename(oldNode, newDir, newName) {
198198
var oldPath = NODEFS.realPath(oldNode);
199199
var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
200+
try {
201+
FS.unlink(newPath);
202+
} catch(e) {}
200203
NODEFS.tryFSOperation(() => fs.renameSync(oldPath, newPath));
201204
oldNode.name = newName;
202205
},

src/library_nodepath.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
// operations. Hence, using `nodePath` should be safe here.
1313

1414
addToLibrary({
15-
$PATH: {
16-
isAbs: (path) => nodePath['isAbsolute'](path),
17-
normalize: (path) => nodePath['normalize'](path),
18-
dirname: (path) => nodePath['dirname'](path),
19-
basename: (path) => nodePath['basename'](path),
20-
join: (...args) => nodePath['join'](...args),
21-
join2: (l, r) => nodePath['join'](l, r),
22-
},
15+
$PATH: `{
16+
isAbs: nodePath.isAbsolute,
17+
normalize: nodePath.normalize,
18+
dirname: nodePath.dirname,
19+
basename: nodePath.basename,
20+
join: nodePath.join,
21+
join2: nodePath.join,
22+
}`,
2323
// The FS-using parts are split out into a separate object, so simple path
2424
// usage does not require the FS.
2525
$PATH_FS__deps: ['$FS'],
2626
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
2727
$PATH_FS: {
2828
resolve: (...paths) => {
2929
paths.unshift(FS.cwd());
30-
return nodePath['posix']['resolve'](...paths);
30+
return nodePath.posix.resolve(...paths);
3131
},
32-
relative: (from, to) => nodePath['posix']['relative'](from || FS.cwd(), to || FS.cwd()),
32+
relative: (from, to) => nodePath.posix.relative(from || FS.cwd(), to || FS.cwd()),
3333
}
3434
});

src/library_noderawfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ addToLibrary({
4040
},
4141
lookupPath(path, opts = {}) {
4242
if (opts.parent) {
43-
path = nodePath.dirname(path);
43+
path = PATH.dirname(path);
4444
}
4545
var st = fs.lstatSync(path);
4646
var mode = NODEFS.getMode(path);

src/node_shell_read.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
*/
66

77
readBinary = (filename) => {
8-
// We need to re-wrap `file://` strings to URLs. Normalizing isn't
9-
// necessary in that case, the path should already be absolute.
10-
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
8+
// We need to re-wrap `file://` strings to URLs.
9+
filename = isFileURI(filename) ? new URL(filename) : filename;
1110
var ret = fs.readFileSync(filename);
1211
#if ASSERTIONS
1312
assert(ret.buffer);
@@ -17,7 +16,7 @@ readBinary = (filename) => {
1716

1817
readAsync = (filename, binary = true) => {
1918
// See the comment in the `readBinary` function.
20-
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
19+
filename = isFileURI(filename) ? new URL(filename) : filename;
2120
return new Promise((resolve, reject) => {
2221
fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
2322
if (err) reject(err);

test/benchmark/benchmark_utf16.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ unsigned short *randomString(int len) {
5454
}
5555

5656
int main() {
57-
srand(time(NULL));
5857
double t = 0;
5958
double t2 = emscripten_get_now();
6059
for(int i = 0; i < 10; ++i) {

test/benchmark/benchmark_utf8.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ char *randomString(int len) {
5454
}
5555

5656
int main() {
57-
time_t seed = time(NULL);
58-
printf("Random seed: %lld\n", seed);
59-
srand(seed);
6057
double t = 0;
6158
double t2 = emscripten_get_now();
6259
for (int i = 0; i < 100000; ++i) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12686,
3-
"a.html.gz": 6930,
4-
"total": 12686,
5-
"total_gz": 6930
2+
"a.html": 12597,
3+
"a.html.gz": 6882,
4+
"total": 12597,
5+
"total_gz": 6882
66
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 17266,
3-
"a.html.gz": 7515,
4-
"total": 17266,
5-
"total_gz": 7515
2+
"a.html": 17195,
3+
"a.html.gz": 7478,
4+
"total": 17195,
5+
"total_gz": 7478
66
}

test/core/test_emmalloc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ void randoms() {
178178
for (int i = 0; i < BINS; i++) {
179179
bins[i] = NULL;
180180
}
181-
srandom(1337101);
182181
for (int i = 0; i < RANDOM_ITERS; i++) {
183182
unsigned int r = random();
184183
int alloc = r & 1;

test/core/test_rand.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <stdlib.h>
2+
#include <stdbool.h>
3+
#include <stdio.h>
4+
#include <assert.h>
5+
6+
int main() {
7+
// We need RAND_MAX to be a bitmask (power of 2 minus 1). This assertion will
8+
// error if RAND_MAX ever changes, so we don't miss that.
9+
assert(RAND_MAX == 0x7fffffff);
10+
11+
srand(0xdeadbeef);
12+
for (int i = 0; i < 10; ++i) {
13+
printf("%d\n", rand());
14+
}
15+
16+
unsigned int seed = 0xdeadbeef;
17+
for (int i = 0; i < 10; ++i) {
18+
printf("%d\n", rand_r(&seed));
19+
}
20+
21+
bool haveEvenAndOdd = true;
22+
for (int i = 1; i <= 30; ++i) {
23+
int mask = 1 << i;
24+
if (mask > RAND_MAX) break;
25+
bool haveEven = false;
26+
bool haveOdd = false;
27+
for (int j = 0; j < 1000 && (!haveEven || !haveOdd); ++j) {
28+
if ((rand() & mask) == 0) {
29+
haveEven = true;
30+
} else {
31+
haveOdd = true;
32+
}
33+
}
34+
haveEvenAndOdd = haveEvenAndOdd && haveEven && haveOdd;
35+
}
36+
37+
if (haveEvenAndOdd) {
38+
printf("Have even and odd!\n");
39+
}
40+
41+
return 0;
42+
}

test/core/test_rand.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
490242850
2+
2074599277
3+
1480056542
4+
1912638067
5+
931112055
6+
2110392489
7+
2053422194
8+
1614832492
9+
216117595
10+
174823244
11+
760368382
12+
602359081
13+
1121118963
14+
1291018924
15+
1608306807
16+
352705809
17+
958258461
18+
1182561381
19+
114276303
20+
1481323674
21+
Have even and odd!

test/fetch/test_fetch_idb_store.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ int main()
3838
{
3939
// Create data
4040
uint8_t *data = (uint8_t*)malloc(10240);
41-
srand(time(NULL));
4241
for(int i = 0; i < 10240; ++i) data[i] = (uint8_t)rand();
4342

4443
persistFileToIndexedDB("outputfile.dat", data, 10240);

test/fetch/test_fetch_idb_store.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ int main()
2121
strcpy(attr.requestMethod, "EM_IDB_STORE");
2222
attr.attributes = EMSCRIPTEN_FETCH_REPLACE | EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_PERSIST_FILE;
2323
uint8_t *data = (uint8_t*)malloc(TEST_SIZE);
24-
srand(time(NULL));
2524
for(int i = 0; i < TEST_SIZE; ++i)
2625
data[i] = (uint8_t)rand() | 0x40;
2726
attr.requestData = (char *)data;

test/fs/test_fs_rename_on_existing.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <assert.h>
4+
#include <fcntl.h>
5+
#include <string.h>
6+
#include <sys/stat.h>
7+
#include <assert.h>
8+
#include <errno.h>
9+
#include <string.h>
10+
11+
12+
#if defined(__EMSCRIPTEN__)
13+
#include <emscripten.h>
14+
#endif
15+
16+
void makedir(const char *dir) {
17+
int rtn = mkdir(dir, 0777);
18+
assert(rtn == 0);
19+
}
20+
21+
void changedir(const char *dir) {
22+
int rtn = chdir(dir);
23+
assert(rtn == 0);
24+
}
25+
26+
static void create_file(const char *path, const char *buffer) {
27+
printf("creating: %s\n", path);
28+
int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666);
29+
printf("error: %s\n", strerror(errno));
30+
assert(fd >= 0);
31+
32+
int err = write(fd, buffer, sizeof(char) * strlen(buffer));
33+
assert(err == (sizeof(char) * strlen(buffer)));
34+
35+
close(fd);
36+
}
37+
38+
39+
void setup() {
40+
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
41+
makedir("working");
42+
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
43+
changedir("working");
44+
#endif
45+
}
46+
47+
int main() {
48+
setup();
49+
create_file("a", "abc");
50+
create_file("b", "xyz");
51+
assert(rename("a", "b") == 0);
52+
assert(unlink("b") == 0);
53+
create_file("b", "xyz");
54+
printf("success\n");
55+
}

test/hello_random_printf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <emscripten.h>
55

66
int main() {
7-
srand(time(NULL));
7+
srand(0);
88

99
printf("hello: a random string: %s, an integer: %d, a float: %f. Time now: %f\n",
1010
emscripten_random() > 0.5 ? "test" : "test2",

test/malloc_bench.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const bool USE_MEMORY = true;
2929
const bool USE_SHIFTS = false;
3030

3131
void randoms() {
32-
srandom(1);
3332
size_t before = (size_t)sbrk(0);
3433
double sum_sbrk = 0;
3534
size_t max_sbrk = before;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8534
1+
8577
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20856
1+
20952
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8518
1+
8561
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20824
1+
20920
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9563
1+
9610
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24699
1+
24795
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8500
1+
8551
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20750
1+
20845

0 commit comments

Comments
 (0)