Age | Commit message (Collapse) | Author |
|
1583: Remove unsafe in with_nix_path() for [u8] r=asomers a=rtzoeller
Remove use of `unsafe` in the implementation of `with_nix_path()` for `[u8]`. This also comes with a nice determinism win across input sizes, and is fairly performance neutral (slightly slower for small strings, much faster for large strings).
I suspect the performance degradation in the existing implementation is related to the following note in the `CStr::from_ptr()` documentation:
> Note: This operation is intended to be a 0-cost cast but it is currently implemented with an up-front calculation of the length of the string. This is not guaranteed to always be the case.
---
Tested with `cargo 1.57.0-nightly (7fbbf4e8f 2021-10-19)`, with variations of the following benchmarking code:
```rs
#[bench]
fn bench_with_nix_path_1024(b: &mut test::Bencher) {
let bytes = std::hint::black_box([70u8; 1024]);
b.iter(|| {
bytes.with_nix_path(|cstr| {
std::hint::black_box(&cstr);
}).unwrap();
})
}
```
| Length | Before Change | After Change |
|--------|-----------------------|-----------------------|
| 16 | 37 ns/iter (+/- 0) | 44 ns/iter (+/- 0) |
| 64 | 39 ns/iter (+/- 0) | 44 ns/iter (+/- 0) |
| 256 | 84 ns/iter (+/- 0) | 48 ns/iter (+/- 0) |
| 1024 | 232 ns/iter (+/- 1) | 50 ns/iter (+/- 1) |
| 4095 | 796 ns/iter (+/- 8) | 62 ns/iter (+/- 2) |
Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
|
|
Using features reduces build time and size for consumer crates. By
default all features are enabled.
|
|
|
|
And this time, start running Clippy in CI
|
|
Also, test rustdoc in CI, and demote missing_docs from a deny to a
warning (but still deny it in CI).
|
|
1507: Forbid dead code again r=asomers a=asomers
The old problems with bitflags no longer apply
1508: More rust docs r=asomers a=asomers
Switch from allow(missing_docs) to deny(missing_docs), which should
gradually help us moving forward. Also, add a few missing docs, such as
for sched and aio.
Co-authored-by: Alan Somers <asomers@gmail.com>
|
|
Switch from allow(missing_docs) to deny(missing_docs), which should
gradually help us moving forward. Also, add a few missing docs, such as
for sched and aio.
|
|
The old problems with bitflags no longer apply
|
|
Now that Nix's weird error types are eliminated, there's no reason not
to simply use Errno as the Error type.
|
|
For many of Nix's consumers it be convenient to easily convert a Nix
error into a std::io::Error. That's currently not possible because of
the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have
no equivalent in std::io::Error.
However, very few of Nix's public APIs actually return those unusual
errors. So a more useful API would be for Nix's standard error type to
implement Into<std::io::Error>.
This commit makes Error a simple NewType around Errno. For most
functions it's a drop-in replacement. There are only three exceptions:
* clearenv now returns a bespoke error type. It was the only Nix
function whose error couldn't be cleanly mapped onto an Errno.
* sys::signal::signal now returns Error(Errno::ENOTSUP) instead of
Error::UnsupportedOperation when the user passes an incompatible
argument to `handler`.
* When a NixPath exceeds PATH_MAX, it will now return
Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath.
In the latter two cases there is now some abiguity about whether the
error code was generated by Nix or by the OS. But I think the ambiguity
is worth it for the sake of being able to implement Into<io::Error>.
This commit also introduces Error::Sys() as a migration aid. Previously
that as an enum variant. Now it's a function, but it will work in many
of the same contexts as the original.
Fixes #1155
|
|
|
|
Co-authored-by: Dominik Hassler <hadfl@omnios.org>
Co-authored-by: Joshua M. Clulow <josh@sysmgr.org>
|
|
Allow nix to compile on Fuchsia by conditionally avoiding libc
functionality that does not exist for Fuchsia.
|
|
|
|
|
|
|
|
|
|
Some things are not implemented yet in redox, so a lot of annotations
were added to remove functions when compiling for redox. Those functions
will hopefully be added in time, but for now it's better to have partial
support than none.
Blocked by https://github.com/rust-lang/libc/pull/1438
|
|
std::convert::Infallible has been available since Rust 1.34 and nix
currently targets Rust 1.36 or later so this should not cause
problems.
Fixes #1238
|
|
Most Nix functions that accept `NixPath` arguments can't do anything
useful with `None`. The exceptions (`mount` and `quotactl_sync`)
already take explicitly optional arguments.
Also, this changes the behavior of `mount` with `None` arguments.
Previously, it would call mount(2) with empty strings for those
arguments. Now, it will use null pointers.
|
|
|
|
|
|
Replace it with mem::zeroed. It isn't perfect, but it's better than it
was.
Issue #1115
|
|
|
|
This fixes the tests on Rust 1.38.0. We'll fix them for real after
release 0.15.0.
Issue #1096
|
|
|
|
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all
traits are supported by all types, which is why many are missing
some.
|
|
Support under bionic/android is the same as under Linux for what is exposed
by this code.
Signed-off-by: Paul Osborne <osbpau@gmail.com>
|
|
This method is useful when it can be statically determined that a
nix::Error be an errno, which I find to be very common.
|
|
- init_module and finit_module to load kernel modules
- delete_module to unload kernel modules
Signed-off-by: Pascal Bach <pascal.bach@nextrem.ch>
|
|
This is a lower-level interface than `std::fs::ReadDir`. Notable differences:
* can be opened from a file descriptor (as returned by `openat`, perhaps
before knowing if the path represents a file or directory). Uses
`fdopendir` for this, available on all Unix platforms as of
rust-lang/libc#1018.
* implements `AsRawFd`, so it can be passed to `fstat`, `openat`, etc.
* can be iterated through multiple times without closing and reopening the
file descriptor. Each iteration rewinds when finished.
* returns entries for `.` (current directory) and `..` (parent directory).
* returns entries' names as a `CStr` (no allocation or conversion beyond
whatever libc does).
|
|
Supporting the bytes crate was unnecessarily specific. This change
replaces from_bytes and from_bytes_mut with from_boxed_slice and
from_boxed_mut_slice, which can work with anything that implements
Borrow<[u8]> and BorrowMut<[u8]>, respectively.
|
|
Mistakingly removed in d1be45d8405
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
820: Change AioCb to primarily use Bytes instead of Rc<[u8]> r=Susurrus a=asomers
`Rc<[u8]>` isn't a very good buffer type to use for aio. For one thing, it lacks interior mutability. For another, a single `Rc<[u8]>` can't be carved up into smaller buffers of the same type. `Bytes` and `BytesMut` fix both problems. This PR removes the ability to construct an `AioCb` from `Rc<[u8]>` and adds the ability to construct one from `Bytes`, `BytesMut`, or raw pointers (for consumers who need even more flexibility). At this stage, the PR has the following warts:
1. A hack is necessary to force small `Bytes` buffers to allocate on the heap. I plan to fix this with an enhancement to the bytes crate.
2. The `AioCb::buffer` method is necessary due to a deficiency in the tokio-core crate. Once I fix that, then only `AioCb::into_buffer`will need to be public.
|
|
It's not actually safe to read into an `Rc<[u8]>`. It only worked
because of a coincidental `unsafe` block. Replace that type with
`BytesMut` from the bytes crate. For consistency's sake, use `Bytes`
for writing too, and completely remove methods relating to `Rc<[u8]>`.
Note that the `AioCb` will actually own the `BytesMut` object. The
caller must call `into_buffer` to get it back once the I/O is complete.
Fixes #788
|
|
|
|
|
|
This was doing testing for errno constants and a few other
types that is no longer necessary now that these types are
all tested within the libc project itself.
|
|
696: Stop reexporting `Errno` variants r=Susurrus a=jonas-schievink
Closes #664 (unsure if this is everything needed)
|