Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cache lookup failures too
  • Loading branch information
tmm1 committed Feb 11, 2015
commit 25e98f767546b8aef78f751f6973c684f9899eaf
22 changes: 16 additions & 6 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ rb_require_safe(VALUE fname, int safe)
PUSH_TAG();
saved.safe = rb_safe_level();
if ((state = EXEC_TAG()) == 0) {
VALUE ipath, path;
VALUE ipath, path = 0;
long handle;
int found;
st_data_t key, val;
Expand All @@ -982,19 +982,29 @@ rb_require_safe(VALUE fname, int safe)
key = (st_data_t)RSTRING_PTR(ipath);
if (st_delete(vm->require_cache.tbl, &key, &val)) {
vals = (char *)val;
if ((found = vals[0])) {
//fprintf(stderr, "FOUND '%s' => '%s'\n", (char *)key, vals);
found = vals[0];
if (found) {
/*fprintf(stderr, "FOUND '%s' => '%s'\n", (char *)key, vals);*/
path = rb_str_new_cstr(vals+1);
}
xfree(vals);
} else {
found = search_required(ipath, &path, safe);
/*if (found && path)
fprintf(stderr, "MISSING '%s' => '%s'\n", RSTRING_PTR(ipath), RSTRING_PTR(path));*/
}
} else {
found = search_required(ipath, &path, safe);
/*if (found && RSTRING_PTR(ipath)[0] != '/')
fprintf(stderr, "SEARCHING '%s'\n", RSTRING_PTR(ipath));*/
}
if (vm->require_cache.write && RSTRING_PTR(ipath)[0] != '/' && path) {
fprintf(vm->require_cache.out, "%s\n%c%s\n", RSTRING_PTR(ipath), found ? found : '\0', found ? RSTRING_PTR(path) : "");
if (vm->require_cache.write && RSTRING_PTR(ipath)[0] != '/' && (!found || (found && path))) {
/*fprintf(stderr, "WRITING '%s' => '%s'\n", RSTRING_PTR(ipath), found ? RSTRING_PTR(path) : "");*/
fprintf(vm->require_cache.out, "%s\n", RSTRING_PTR(ipath));
Copy link
Author

Choose a reason for hiding this comment

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

These fprintfs happen back to back, so I can't figure out why one writes sane data (to stderr) and the other ends up corrupting the cache file.

Copy link

Choose a reason for hiding this comment

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

@tmm1: RSTRING_PTR is not assured to be NULL-terminated. Try StringValueCStr() instead?

Copy link
Author

Choose a reason for hiding this comment

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

I thought that might be why, so I tried fprintf("%.*s", RSTRING_LEN(ipath), RSTRING_PTR(ipath)) but that didn't help either.

Copy link
Author

Choose a reason for hiding this comment

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

Just tried StringValueCStr and no difference. It's super weird that the corruption always happens after loading thread.bundle, so I wonder if that's affecting the open file handle somehow.

Copy link
Author

Choose a reason for hiding this comment

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

Might be related to this, which calls back into load.c:

ext/thread/thread.c:    rb_provide("thread.rb");

Copy link

Choose a reason for hiding this comment

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

Hah. Sounds like a fun one. I'm definitely digging this tomorrow if you haven't figured it out by then. :))

if (found)
fprintf(vm->require_cache.out, "%c%s\n", found, RSTRING_PTR(path));
else
fprintf(vm->require_cache.out, "%s\n", "");
fsync(fileno(vm->require_cache.out));
}

Expand Down Expand Up @@ -1193,7 +1203,7 @@ require_cache_setup()
if (!fgets(line2, PATH_MAX+2, file)) break;
line1[strlen(line1)-1] = 0;
line2[strlen(line2)-1] = 0;
//fprintf(stderr, "INSERTING '%s' => '%s'\n", line1, line2);
/*fprintf(stderr, "INSERTING '%s' => '%s'\n", line1, line2);*/
st_insert(vm->require_cache.tbl, (st_data_t)ruby_strdup(line1), (st_data_t)ruby_strdup(line2));
}
fclose(file);
Expand Down