Commit Graph

47 Commits

Author SHA1 Message Date
Daniel Paoliello 2b22d0f0d2 Make __rust_alloc_error_handler_should_panic a function 2025-07-03 10:52:21 -07:00
Christopher Durham 4d93f60568 use generic Atomic type where possible
in core/alloc/std only for now, and ignoring test files

Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-27 02:18:08 +03:00
Boxy c93005ee65 update cfgs 2025-04-09 12:29:59 +01:00
bjorn3 42de015549 Mark imports of #[rustc_std_internal_symbol] items with this attribute
This ensures that they will be correctly mangled in a future commit.
2025-03-17 14:06:56 +00:00
Eric Huss 4f4ea35a69 std: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Michael Goulet a4e7f8f9bf Mark extern blocks as unsafe 2025-02-09 17:11:13 +00:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Tobias Bucher bb8eb44511 Unify guarantees about the default allocator
`std::alloc` said that the default allocator is unspecified for all
crrate types except `cdylib` and `staticlib`. Adjust
`std::alloc::System` documentation to say the same.

Fixes #125870.
2024-06-11 17:13:26 +02:00
Ralf Jung 3f6703bbd8 default_alloc_error_hook: explain difference to default __rdl_oom in alloc 2024-05-03 19:12:33 +02:00
Mara Bos 904fef0e24 SeqCst->{Release,Acquire} for alloc error hook.
SeqCst is unnecessary.
2024-03-19 15:27:11 +01:00
joboet fa9a911a57 libs: use assert_unchecked instead of intrinsic 2024-01-13 20:10:00 +01:00
Kevin Reid 3dde25edc4 Correct and expand documentation of handle_alloc_error and set_alloc_error_hook.
Add the following facts:

* `handle_alloc_error` may panic instead of aborting.
* What happens if a hook returns rather than diverging.
* A hook may panic. (This was already demonstrated in an example,
  but not stated in prose.)
* A hook must be sound to call — it cannot assume that it is only
  called by the runtime, since its function pointer can be retrieved by
  safe code.
2023-08-19 13:27:03 -07:00
James Dietz db4a153440 remove additional [allow(unused_unsafe)] 2023-07-24 17:56:38 -04:00
Mikail Bagishov 7b9f64475e Change memory ordering in System wrapper example
Currently, the `SeqCst` ordering is used, which seems unnecessary:
+ Even `Relaxed` ordering guarantees that all updates are atomic and are executed in total order
+ User code only reads atomic for monitoring purposes, no "happens-before" relationships with actual allocations and deallocations are needed for this

If argumentation above is correct, I propose changing ordering to `Relaxed` to clarify that no synchronization is required here, and improve performance (if somebody copy-pastes this example into their code).
2023-01-08 22:53:51 +03:00
Ralf Jung 5974f6f0a5 default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to match std handler 2023-01-02 16:35:14 +01:00
Christopher Durham 69721defc2 Forbid mixing System with sytem allocator calls 2022-09-03 16:47:12 -05:00
Lukas Wirth 756118e2b9 Update std::alloc::System docs 2022-06-26 16:31:29 +02:00
Ralf Jung b05d71f880 make std not use &A: Allocator instance 2022-06-18 07:38:28 -07:00
Lucas Dumont 5adef6c795 Add std::alloc::set_alloc_error_hook example 2022-06-07 15:06:18 +02:00
kraktus 519aa6e4d7 update jemallocator example to use 2018 edition import syntax 2022-05-04 13:43:33 +02:00
Pietro Albini 181d28bb61 trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
bors d6f3a4ecb4 Auto merge of #88098 - Amanieu:oom_panic, r=nagisa
Implement -Z oom=panic

This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue #43596).

Perf and binary size tests show negligible impact.
2022-03-18 03:01:46 +00:00
T-O-R-U-S 72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
Amanieu d'Antras aa36237e16 Add -Z oom={panic,abort} command-line option 2022-03-03 12:58:38 +00:00
Christiaan Dirkx 4ff5ab5296 Rename rterr to rtprintpanic 2021-05-19 15:52:09 +02:00
Christiaan Dirkx 6145051eee Replace sys_common::util::dumb_print with rterr! 2021-05-19 15:05:35 +02:00
LingMan 769fb8a8b7 Fix safety comment
The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
2021-01-07 09:13:21 +01:00
pierwill 9cb43bd994 Add missing punctuation to std::alloc docs
Add a period to first line of module docs to match other modules in std.
2020-12-17 21:49:32 -08:00
Tim Diekmann 9274b37d99 Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
hyd-dev 70e175b551 Add missing newline to error message of the default OOM hook 2020-11-10 00:15:07 +08:00
Jacob Hughes 5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
blitzerr 2b19b14cec a few more &mut self -> self changes 2020-09-22 21:04:31 -07:00
blitzerr 3ffd403c6b removing &mut self for other methods of AllocRef 2020-09-22 06:22:02 -07:00
blitzerr d9d02fa168 Changing the alloc() to accept &self instead of &mut self 2020-09-21 16:43:36 -07:00
Flying-Toast c66789d572 Capitalize safety comments 2020-09-08 22:26:44 -04:00
Tim Diekmann 438c40efa1 Allow reallocation to different alignment 2020-08-19 06:46:47 +02:00
Tim Diekmann 63d241a7b7 Make grow_impl unsafe 2020-08-18 15:22:10 +02:00
Tim Diekmann 66a651244e Add comment, which was removed by accident (again) 2020-08-18 10:00:31 +02:00
Tim Diekmann a9fe0ca47a Clean up AllocRef implementation and documentation 2020-08-18 09:53:22 +02:00
bors 515c9fa505 Auto merge of #75621 - TimDiekmann:no-fast-realloc, r=Amanieu
Remove fast path in reallocation for same layout sizes

r? @Amanieu

Before merging a perf-run should be done.

Closes https://github.com/rust-lang/wg-allocators/issues/70
2020-08-18 05:42:05 +00:00
Ellen a2dfc3ec78 Switch to intra-doc links for std/src/alloc.rs 2020-08-17 14:42:40 +01:00
Tim Diekmann c48f784418 Fix typo in comment 2020-08-17 15:05:19 +02:00
Tim Diekmann c619b36975 Remove fast path in reallocation for same layout sizes 2020-08-17 13:23:38 +02:00
Tim Diekmann ab9362ad9a Replace Memoryblock with NonNull<[u8]> 2020-08-04 18:03:34 +02:00
Tim Diekmann b01fbc437e Simplify implementations of AllocRef for Global and System 2020-07-29 11:41:36 +02:00
Tim Diekmann 076ef66ba2 Remove in-place allocation and revert to separate methods for zeroed allocations
Fix docs
2020-07-28 12:41:18 +02:00
mark 2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00