Skip to content

Handle file descriptors as usize #3

@saza-ku

Description

@saza-ku

File descriptors are handled as i32 in WASI functions arguments, like this.

pub export fn fd_close(fd: i32) callconv(.C) WasiError

We pass them around as i32. But indices must be usize in Zig, so we must cast them every time we index the file descriptor table.

    pub fn get(self: *Self, fd: i32) ?*Stream {
        const streams = self.streams.acquire();
        defer self.streams.release();
        const s = &streams.*[@as(usize, @intCast(fd))];
        if (s.* == null) {
            return null;
        }

        return @as(*Stream, @ptrCast(s));
    }

To avoid it, we want to cast fd to usize in WASI functions, and handle it as usize in stream module.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions