Skip to content

Instantly share code, notes, and snippets.

@cjepeway
Created April 25, 2015 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjepeway/2142e6d9e7aa7171c34d to your computer and use it in GitHub Desktop.
Save cjepeway/2142e6d9e7aa7171c34d to your computer and use it in GitHub Desktop.
perl6 open...oddities.
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
@cjepeway
Copy link
Author

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.

@cjepeway
Copy link
Author

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