-
-
Save cjepeway/2142e6d9e7aa7171c34d to your computer and use it in GitHub Desktop.
perl6 open...oddities.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jepeway@go-go-go:~/src/tz/p6$ perl6 -e 'open("/usr/include/stdiox.h")' | |
Failed to open file PAK: no such file or directory | |
in method open at src/gen/m-CORE.setting:18151 | |
in sub open at src/gen/m-CORE.setting:19300 | |
in block <unit> at -e:1 | |
jepeway@go-go-go:~/src/tz/p6$ perl6 -e 'open("/usr/include/stdio.h")' | |
jepeway@go-go-go:~/src/tz/p6$ perl6 -e 'open("/usr/include/nope.h")' | |
Failed to open file @: no such file or directory | |
in method open at src/gen/m-CORE.setting:18151 | |
in sub open at src/gen/m-CORE.setting:19300 | |
in block <unit> at -e:1 | |
jepeway@go-go-go:~/src/tz/p6$ perl6 -e 'open("nope.h")' | |
Malformed UTF-8 at line 1 col 21 | |
in method open at src/gen/m-CORE.setting:18151 | |
in sub open at src/gen/m-CORE.setting:19300 | |
in block <unit> at -e:1 | |
Uh...no.
if ((fd = uv_fs_open(tc->loop, &req, (const char *)fname, flag, DEFAULT_MODE, NULL)) < 0) {
char path[MAXPATHLEN];
strncpy(path, fname, sizeof path);
path[sizeof(path) - 1] = '\0';
MVM_free(fname);
MVM_exception_throw_adhoc(tc, "Failed to open file %s: %s", path, uv_strerror(req.result));
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From src/io/syncfile.c:412 in MVM_file_open_fh()
if ((fd = uv_fs_open(tc->loop, &req, (const char *)fname, flag, DEFAULT_MODE, NULL)) < 0) {
MVM_free(fname);
MVM_exception_throw_adhoc(tc, "Failed to open file %s: %s", fname, uv_strerror(req.result));
}
fname can’t be used once it’s been free()d. Something like (the obvious)
if ((fd = uv_fs_open(tc->loop, &req, (const char *)fname, flag, DEFAULT_MODE, NULL)) < 0) {
char path[MAXPATHLEN];
strncpy(path, fname, sizeof(path)-1);
MVM_free(fname);
MVM_exception_throw_adhoc(tc, "Failed to open file %s: %s", path, uv_strerror(req.result));
}
though I’m betting libuv has its own notions of MAXPATHLEN that should perhaps be used instead.