authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-05 17:23:49+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-05 17:23:49+02:00
log81d824bf80b71fceeb01238824c272d899a364fc
treec8a5709c7df696a0790c6f2dd277aaea93a9eda6
parent07a968b3444c1db036d605ed8a25bc128110b646

Clear PreopenList on every populate call


1 files changed, 14 insertions(+), 0 deletions(-)

lib/std/fs/wasi.zig+14
......@@ -71,7 +71,16 @@ pub const PreopenList = struct {
7171
7272 /// Populate the list with the preopens by issuing `std.os.wasi.fd_prestat_get`
7373 /// and `std.os.wasi.fd_prestat_dir_name` syscalls to the runtime.
74 ///
75 /// If called more than once, it will clear its contents every time before
76 /// issuing the syscalls.
7477 pub fn populate(self: *Self) Error!void {
78 // Clear contents if we're being called again
79 for (self.toOwnedSlice()) |preopen| {
80 switch (preopen.@"type") {
81 PreopenType.Dir => |path| self.buffer.allocator.free(path),
82 }
83 }
7584 errdefer self.deinit();
7685 var fd: fd_t = 3; // start fd has to be beyond stdio fds
7786
......@@ -123,6 +132,11 @@ pub const PreopenList = struct {
123132 pub fn asSlice(self: *const Self) []const Preopen {
124133 return self.buffer.items;
125134 }
135
136 /// The caller owns the returned memory. ArrayList becomes empty.
137 pub fn toOwnedSlice(self: *Self) []Preopen {
138 return self.buffer.toOwnedSlice();
139 }
126140};
127141
128142/// Convenience wrapper for `std.os.wasi.path_open` syscall.