Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPtrExt::offset taking an isize argument is not ideal #22104
Comments
carllerche
changed the title
ptr::offset taking an isize argument is not ideal
PtrExt::offset taking an isize argument is not ideal
Feb 9, 2015
This comment has been minimized.
This comment has been minimized.
|
/cc @aturon |
steveklabnik
added
the
A-libs
label
Feb 9, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
With high probability we will add It's not like anyone ever does a check for "the uint is too large" when they cast, so this would just be an ergonomic improvement. I suppose we could add some friendly debug asserts in there. That said, this API taking a signed int is a soundness issue for us due to being able to allocate more than int::MAX contiguous bytes in some situations. There are a few options to address this, but all of them have drawbacks. |
This comment has been minimized.
This comment has been minimized.
|
Not sure we need those methods. I'll be the conservative side and say that hiding the problem doesn't help. Users of .offset need to be aware, and a cast to isize might help them with that. |
This comment has been minimized.
This comment has been minimized.
|
Why is the intrinsic different than casting the ptr to usize, modifying it, and casting back to a ptr? |
This comment has been minimized.
This comment has been minimized.
|
That's this question in the GEP FAQ. thestinger was the guy to make sure Rust used GEP so that llvm could optimize much better. |
This comment has been minimized.
This comment has been minimized.
|
The maximum object size in Rust is equal to |
This comment has been minimized.
This comment has been minimized.
|
@Thiez that specification was of course added in response to this problem, so it's a bit of a circular argument. |
This comment has been minimized.
This comment has been minimized.
|
You couldn't do this in C either, because the difference between two pointers has type |
This comment has been minimized.
This comment has been minimized.
|
Nominating for 1.0-beta P-backcompat-libs. We need to resolve this issue. |
aturon
added
the
I-nominated
label
Feb 16, 2015
This comment has been minimized.
This comment has been minimized.
|
assigning to self (to get answers to some questions I have) |
pnkfelix
self-assigned this
Feb 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Not 1.0 blocker based on current understanding of situation. P-high. |
pnkfelix
added
P-medium
and removed
I-nominated
labels
Feb 19, 2015
bluss
referenced this issue
Jul 11, 2015
Open
Abort on some large allocation requests, Panic on other #26951
huonw
added
I-nominated
T-libs
labels
Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this in triage yesterday and the conclusion was that this cannot be changed due to it being stable, and the situation is also intended due to the limitations imposed by LLVM. Pointer offsets need to be able to go backwards (e.g. move around in an array), but it's undefined behavior to overflow, so the only defined way to do this is to have a signed offset. |
alexcrichton
closed this
Jan 21, 2016
This comment has been minimized.
This comment has been minimized.
|
I also just reread the docs and I think that they adequately reflect this. |
carllerche commentedFeb 9, 2015
PtrExt::offsettaking an isize argument prevents being able to advance forward / back the full possible range of a pointer. A better option might be to have separate functions for forwards / backwards that take usize arguments.