Commit Graph

4297 Commits

Author SHA1 Message Date
bors 0a3b557d52 Auto merge of #95317 - Jules-Bertholet:round_ties_to_even, r=pnkfelix,m-ou-se,scottmcm
Add `round_ties_even` to `f32` and `f64`

Tracking issue: #96710

Redux of #82273. See also #55107

Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this.

Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`).  Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight.

Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
2023-03-07 09:43:12 +00:00
bors 0fbfc3e769 Auto merge of #89518 - a1phyr:unix_file_vectored_at, r=workingjubilee
Add vectored positioned I/O on Unix

Add methods for vectored I/O with an offset on `File` for `unix` under `#![feature(unix_file_vectored_at)]`.

The new methods are wrappers around `preadv` and `pwritev`.

Tracking issue: #89517
2023-03-04 05:26:35 +00:00
Benoît du Garreau 92f35b32b2 Use weak linkage for `preadv` and `pwritev` on MacOS and iOS 2023-03-03 10:40:10 +01:00
est31 999405059c Match unmatched backticks in library/ 2023-03-03 03:03:29 +01:00
Benoît du Garreau 23cd4cee05 Add basic tests 2023-03-02 11:51:20 +01:00
Benoît du Garreau 1e63f08c85 Take shared references as parameter 2023-03-02 11:50:27 +01:00
Benoît du Garreau 2fc23c2dfe Use weak linkage on Android 2023-03-02 11:12:24 +01:00
bors 864b6258fc Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee
Add support for QNX Neutrino to standard library

This change:

- adds standard library support for QNX Neutrino (7.1).
- upgrades `libc` to version `0.2.139` which supports QNX Neutrino

`@gh-tr`

⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️

Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-03-02 02:41:42 +00:00
Florian Bartels a510715749
Update library/std/src/os/nto/mod.rs
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2023-03-01 06:42:40 +01:00
Matthias Krüger 24551850a9
Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomcc
rustdoc: Show that repeated expression arrays can be made with constant values

The [rust reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) currently says that repeated values for arrays can be constant or `Copy`
> repeat operand is [Copy](https://doc.rust-lang.org/reference/special-types-and-traits.html#copy) or that it must be a [path](https://doc.rust-lang.org/reference/expressions/path-expr.html) to a constant item

This updates the rust documentation on primitive arrays to reflect what the rust reference says (and also compiler suggestions if you do not use a `const` item)
2023-03-01 01:20:23 +01:00
Florian Bartels cef9d4cbc1
Retry to spawn/fork up to 3 times when it failed because of an interruption 2023-02-28 15:59:53 +01:00
Florian Bartels 3ce2cd059f
Add QNX Neutrino support to libstd
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-28 15:59:47 +01:00
Matthias Krüger 3fe4023370
Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDenton
[stdio][windows] Use MBTWC and WCTMB

`MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff).

Fixes #107092
2023-02-27 18:48:48 +01:00
Coca162 22b65fc275
Clarify that Copy is a trait in array docs 2023-02-27 15:16:39 +00:00
Coca162 dc9732620d
Update docs to show [expr; N] can repeat const expr 2023-02-27 13:51:10 +00:00
Benoît du Garreau 351c154cb4 Add vectored positioned I/O on Unix 2023-02-27 10:10:13 +01:00
Linus Färnstrand 6cb34492a6 Move IpAddr and SocketAddr to core 2023-02-26 13:50:08 +01:00
bors 34e6673a04 Auto merge of #107405 - hermitcore:bsd, r=bjorn3
add support of RustyHermit's BSD socket layer

RustyHermit is a tier 3 platform and publishes a new kernel interface. The new version supports a common BSD socket layer. By supporting this interface, the implementation of `std` can be harmonized to other operating systems. In `sys_common/mod.rs` we remove only a special case for RustyHermit. All changes are done in the RustyHermit specific directories.

To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-25 19:43:00 +00:00
Nicole Mazzuca 7f25580512 [stdio][windows] Use MBTWC and WCTMB 2023-02-25 11:15:23 -08:00
bors 26c98689f2 Auto merge of #108233 - ChrisDenton:move-std-tests, r=thomcc
Move some std tests from `tests/ui-fulldeps` into `library/std`

This allows them to be tested normally along with other `./x test std` tests. Moving `rename_directory` is simple enough but `create_dir_all_bare` needed to be an std integration test.

Additionally, some tests that I couldn't move atm have instead been placed in an `std` subdirectory. These tests include ones that do fun things with processes or that intentionally abort the test process.

r? libs
2023-02-25 10:26:57 +00:00
Stefan Lankes af8ee641a8 avoid the usage of libc during the creation of documentation 2023-02-24 15:30:14 +01:00
Stefan Lankes 90162a78a9 remove code duplications 2023-02-24 15:30:14 +01:00
Stefan Lankes b5fb4f3d9b move IO traits to std/src/os/hermit
By moving the IO traits, the RustyHermit support is harmonized to
of other operating systems.
2023-02-24 15:30:14 +01:00
Stefan Lankes 7143379a52 add support of RustyHermit's BSD socket layer
RustHermit publishs a new kernel interface and supports
a common BSD socket layer. By supporting this interface,
the implementation can be harmonized to other operating systems.

To realize this socket layer, the handling of file descriptors
is also harmonized to other operating systems.
2023-02-24 15:30:14 +01:00
Dylan DPC 353827a044
Rollup merge of #108391 - sunfishcode:sunfishcode/is-terminal-file-length, r=ChrisDenton
Fix `is_terminal`'s handling of long paths on Windows.

As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case.

This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-24 12:02:45 +05:30
Dylan DPC f94c3c9da1
Rollup merge of #108370 - fbq:time-doc-fix, r=thomcc
std: time: Avoid to use "was created" in elapsed() description

".. since this instant was created" is inaccurate and misleading, consider the following case:
```rust
	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3
```
Per the current description, `elapsed()` at T3 should return T3 - T2?

To avoid the inaccuracy, removes the "was created" in the description of {Instant,SystemTime}::elapsed().
And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
2023-02-24 12:02:42 +05:30
Dan Gohman c0c1925774 Fix `is_terminal`'s handling of long paths on Windows.
As reported in sunfishcode/is-terminal#18, there are situations where
`GetFileInformationByHandleEx` can write a file name length that is
longer than the provided buffer. To avoid deferencing memory past the
end of the buffer, use a bounds-checked function to form a slice to
the buffer and handle the out-of-bounds case.

This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal`
implementation.
2023-02-23 06:29:11 -08:00
Matthias Krüger c4a4bce695
Rollup merge of #108218 - ChrisDenton:cmd-escape, r=cuviper
Windows: Quote more batch file arguments

Make sure to always quote batch file arguments that contain command prompt special characters.

Additionally add `/d` command line parameter to disable any autorun scripts that may change the way variable expansion works. This makes it more consistent across systems and may help avoid surprises.

## Background Info

[`CreateProcess`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with the `lpApplicationName` set can only be used to run `.exe` files and not script files such as `.bat`. However, for historical reasons, we do have special handling so that `.bat` files will be correctly run with `cmd.exe` as the application.

In Windows, command line arguments are passed as a single string (not an array). Applications can parse this string however they like but most follow the standard MSVC C/C++ convention. But `cmd.exe` uses different argument parsing rules to other Windows programs (because it emulates old DOS).  This PR aims to help smooth over some of the differences.

r? libs
2023-02-23 06:18:06 +01:00
Boqun Feng b54a5fdca0 std: time: Avoid to use "was created" in elapsed() description
".. since this instant was created" is inaccurate and misleading,
consider the following case:

	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3

Per the current description, `elapsed()` at T3 should return T3 - T2?

Therefore removes the "was created" in the description of
{Instant,SystemTime}::elapsed(). And since these types represent times,
it's OK to use prepostions with them, e.g. "since this instant".
2023-02-22 14:40:43 -08:00
Matthias Krüger 0982eab839
Rollup merge of #107736 - tgross35:atomic-as-ptr, r=m-ou-se
Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893)

Originally discussed in https://github.com/rust-lang/rust/issues/66893#issuecomment-1419198623

~~This uses #107706 as a base to avoid a merge conflict once that gets rolled up (so disregard const changes in the diff until it does)~~ all merged & rebased

`@rustbot` label +T-libs-api
r? m-ou-se
2023-02-22 20:05:57 +01:00
Chris Denton 0b7c867ec5
Quote more batch file arguments
Make sure to quote batch file arguments that contain command prompt special characters.

Additionally add `/d` command line parameter to disable any commands that may change the way variable expansion works.
2023-02-22 04:27:35 +00:00
Chris Denton 0f221cc034
Exclude SGX from create_dir_all_bare test
And emscripten too.
2023-02-21 18:33:20 +00:00
Chris Denton 9b18b4440a
Make `create_dir_all_bare` an std integration test
Moving `create_dir_all` out of `ui-fulldeps` is complicated by the fact it sets the current directory. This means it can't be a unit test. Instead, move it to its own integration test.
2023-02-21 18:33:19 +00:00
Chris Denton f7a132f428
Move `rename_directory` from ui-fulldeps to std
std has had a `TempDir` implementation for a long time now.
2023-02-21 18:33:19 +00:00
Tomasz Miąsko 7867aa8aee Remove unused FileDesc::get_cloexec 2023-02-21 18:52:25 +01:00
Dylan DPC 7dcf7fe737
Rollup merge of #108272 - MrNossiom:master, r=thomcc
docs: wrong naming convention in struct keyword doc

Noticed that the naming convention mentioned is not the right one.

As far as I know, PacalCase is the naming convention used for structs names. PacalCase is not the same as camelCase
2023-02-21 14:20:00 +05:30
Dylan DPC e781a6ff3b
Rollup merge of #108105 - majaha:patch-1, r=cuviper
Explain the default panic hook better

This changes the documentation of `std::panic::set_hook` and `take_hook` to explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.

I also reworded a few things for clarity.
2023-02-21 14:19:59 +05:30
Matt Harding ec9a4ce19e Explain the default panic hook better
This changes the documentation of `std::panic::set_hook` and `take_hook` to better explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.
2023-02-20 23:37:19 +00:00
Milo Moisson 18f5f0c473
use UpperCamelCase 2023-02-20 23:44:21 +01:00
Milo Moisson 76ac2705a5
docs: wrong naming convention in struct keyword doc 2023-02-20 16:40:46 +01:00
Tomasz Miąsko b118569268 Use custom implementation of read_buf in Read for &'a FileDesc
This allows to skip an unnecessary buffer initialization.
2023-02-19 13:06:38 +01:00
Dylan DPC 47ec320ce6
Rollup merge of #104659 - tshepang:reflow, r=workingjubilee
reflow the stack size story
2023-02-19 13:03:39 +05:30
bors 3701bdc633 Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-se
Optimize `LazyLock` size

The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently.

`@rustbot` label +T-libs +A-atomic
2023-02-18 09:29:21 +00:00
Dylan DPC 0c5bbca12d
Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-se
Use id-based thread parking on SOLID

By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX.

ping ``@kawadakk``
r? ``@m-ou-se``
``@rustbot`` label +T-libs
2023-02-16 11:40:19 +05:30
Kornel 4c2d48ee80 Suggest simpler fs helper methods in File::{open,create} 2023-02-15 18:58:38 +00:00
Kornel 15adc7b5e4 Demonstrate I/O in File examples 2023-02-15 18:47:50 +00:00
Florian Bartels 8f41570e91
Use libc which supports QNX Neutrino
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-15 13:57:57 +01:00
Dylan DPC ef6de70c77
Rollup merge of #108060 - ChrisDenton:rtlgenrandom, r=thomcc
Revert to using `RtlGenRandom` as a fallback

This is required due to `BCryptGenRandom` failing to load a dll it depends on.

Fixes #108059
2023-02-15 12:24:56 +05:30
Chris Denton dfd0afb991
Revert to using `RtlGenRandom`
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems.
2023-02-14 19:37:05 +00:00
Matthias Krüger a1ba861190
Rollup merge of #107573 - cuviper:drop-llvm-13, r=nagisa
Update the minimum external LLVM to 14

With this change, we'll have stable support for LLVM 14 through 16 (pending release).
For reference, the previous increase to LLVM 13 was #100460.
2023-02-14 18:24:40 +01:00