Project idea: strongly typed file descriptor integers and deduplication of various checks around them #3772
Labels
A-files
Area: related to files, paths, sockets, file descriptors, or handles
C-cleanup
Category: cleaning up our code
E-good-second-issue
A good issue to pick up if you've already seen some parts of Miri, mentoring is available
This is less of a fundamental/large-in-behavior change and more a very bitrotty change with possibly not-really-deduplicating-that-much changes that hopefully still make the code more manageable.
Problem statement
Currently we represent file descriptors just as
i32
within miri. We mix them with various negative integer values for signalling errors, just like libc does. We also duplicate a lot of error handling logic likeand
Solution parts
Scalar
instead ofi32
as the return type of foreign function handlers (groundwork for the following, as we inconsistently usei32
andScalar
. Even usingScalar
wheni32
would definitely suffice, not just when it could be a pointer).i32
known-to-be-file-descriptors in a newtype struct together with some convenience functions for reading them and getting the integer back out (into a scalar)io::Result<FileDescriptionRef>
(or the reference versions) from the various getters, instead ofOption<FileDescriptionRef>
. Forward that where useful, avoiding explicit-1
returns paired withset_last_error
, instead handling it withtry_unwrap_io_result
get_mut
,get
, anddup
methods toFdTable
that returnio::Result
instead ofOption
, even though the only io error they ever return isNotFound
, allowing us to?
away their resultThe text was updated successfully, but these errors were encountered: