-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions for building raw slices to libcore #60667
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
412b3b1
to
f5236b7
Compare
Hmm, I wonder if there's code that would have issues with zero-sized-types and slice lens > isize::MAX? I know I've had that idea as a way to hack in custom DST's; wouldn't surprise me if others did too.
Maybe we do need to say that while it's safe to create such a pointer, it's unsafe to dereference one?
…On May 10, 2019 4:24:48 AM EDT, Oliver Scherer ***@***.***> wrote:
oli-obk commented on this pull request.
> +/// Performs the same functionality as [`from_raw_parts`], except
that a
+/// mutable slice is returned.
+///
+/// # Panics
+///
+/// The total size of the slice should be no
+/// larger than `isize::MAX` **bytes** in memory.
+///
+/// See the documentation of [`from_raw_parts`] for more details.
+///
+/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
+#[inline]
+#[unstable(feature = "slice_from_raw_parts", reason = "recently
added", issue = "36925")]
+pub fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut
[T] {
+ debug_assert!(mem::size_of::<T>().saturating_mul(len) <=
isize::max_value() as usize,
+ "attempt to create slice covering half the address
space");
It's not a safety issue. I mostly thought of it as "you're going into
weird places"-territory. There's basically no reason to ever create
such raw slices. I should remove the `Panics` note though. This is just
a debug assertion that we'd only get on the builders with debug
assertions, so it's mostly a sanity test for our own test suite.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#60667 (comment)
|
7979709
to
adaa377
Compare
☔ The latest upstream changes (presumably #61274) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @sfackler |
LGTM other than the one nit. |
adaa377
to
5b73c70
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
5b73c70
to
8b21b07
Compare
@bors r=sfackler |
📌 Commit 8b21b07 has been approved by |
Add functions for building raw slices to libcore implement rust-lang#36925
Add functions for building raw slices to libcore implement rust-lang#36925
When landing a PR that adds a |
Stabilize ptr::slice_from_raw_parts[_mut] Closes #36925, the tracking issue. Initial impl: #60667 r? @rust-lang/libs In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
implement #36925