-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
I may be missing something, but if everything coming from wasm is supposed to be utf-8 then could |
That's a good question. So |
@alexcrichton as usual your suggestion was spot-on, and I've now completely reworked how we handle WASI paths in |
👍 |
cc @sunfishcode |
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.
What would you think of simplifying it even further, and just using &str
and String
instead of WasiPath
and WasiPathBuf
? We'd have some standalone utility functions to convert to/from [u8]
, OsString
, and so on instead of try_from
. That would make it immediately clear that these paths are plain Rust strings.
@sunfishcode, sure, I guess that would work too. I’m a fan of actually having a wrapper type with trait implementations on it, whereas utility functions returning a All in all though, it’s true that using utility functions and then operating on pure |
Hmm, now that I've taken a closer look at it, since we're already re-using a lot of Rust's @alexcrichton I'd love to hear your opinion on this: 1) would you leave path handling as is with pub(crate) fn path_from_host<S: AsRef<OsStr>>(s: S) -> Result<String, host::__wasi_errno_t> {
// ...
} |
Also, another nice thing about current approach is that error mapping between String::from_utf8(vec).map_err(|_| host::__WASI_EILSEQ) I guess we'd either have to write a macro, or wrap it in a utility function creating ever so longer function names pub(crate) fn path_from_host_utf8_vec(vec: Vec<u8>) -> Result<String, host::__wasi_errno_t> {
String::from_utf8(vec).map_err(|_| host::__WASI_EILSEQ)
} |
Oh I don't have much of an opinion on API-design here other than the fundamentals should probably be str/String based at least because they're required to be utf-8 today. I'd defer to @sunfishcode's preference of using |
Coolios! @sunfishcode thoughts? I'm OK with both approaches with ever so slight preference towards wrapper types, but I'm not insisting on this approach, so I'll also defer to you :-) |
I can see it both ways. I think I like using |
Sounds reasonable to me! Let me make the adjustments then :-) |
@sunfishcode changes applied, ready for review :-) |
Looks good, thanks! |
This PR address @sunfishcode concerns about proper/improper conversion from/to UTF-8 across different hosts raise in #34. As such, it verifies that input path (from Wasm) is a valid UTF-8, then performs a translation into correct encoding for the host (UTF-8 on *nix, UTF-16 on Windows), and performs any relevant calls involving the path.