-
Notifications
You must be signed in to change notification settings - Fork 3.5k
HandleAllocator: Always reserve handle zero. NFC #19065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| std::shared_ptr<Directory> createDirectory(mode_t mode) override { | ||
| proxy([](auto ctx) { _wasmfs_opfs_init_root_directory(ctx.ctx); }); | ||
| return std::make_shared<OPFSDirectory>(mode, this, 0, proxy); | ||
| return std::make_shared<OPFSDirectory>(mode, this, 1, proxy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have _wasmfs_opfs_init_root_directory return the id here? Would that be easy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be easy.
|
Oh nice. FWIW having this.allocate = function(handle) {
let id = this.freelist.pop() || this.allocated.length;
this.allocated[id] = handle;
return id;
}; |
Oh nice! |
Also, set entries to `undefined` rather than using the `delete` operator on the handle array. Apparently using `delete` can lead to holes in the array which can damage perf. Reserving 0 also allows us to simplify the allocate function a little. This actually revealed a hidden bug in test/other/test_dlopen_promise.c. Split out from #19054
4c5ba63 to
e5470d3
Compare
tlively
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % comments
| $HandleAllocator__docs: '/** @constructor */', | ||
| $HandleAllocator: function() { | ||
| this.allocated = []; | ||
| // Reserve slot 0 so that 0 is always and invalid handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and" => "an"
| if (wasmfsOPFSDirectoryHandles.allocated.length == 0) { | ||
| // allocated.length start of as 1 since 0 is a reserved handle | ||
| if (wasmfsOPFSDirectoryHandles.allocated.length == 1) { | ||
| // Directory 0 is reserved as the root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs to be updated to say "Directory 1"
| std::shared_ptr<Directory> createDirectory(mode_t mode) override { | ||
| proxy([](auto ctx) { _wasmfs_opfs_init_root_directory(ctx.ctx); }); | ||
| return std::make_shared<OPFSDirectory>(mode, this, 0, proxy); | ||
| return std::make_shared<OPFSDirectory>(mode, this, 1, proxy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be easy.
|
Oops, we make a followup with feedback |
Also, set entries to
undefinedrather than using thedeleteoperator on thehandle array. Apparently using
deletecan lead to holes in the array whichcan damage perf.
This actually revealed a hidden bug in test/other/test_dlopen_promise.c.
Split out from #19054