-
Notifications
You must be signed in to change notification settings - Fork 28
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
Replace offset with wrapping_offset #79
Comments
It is not clear to me given the docs for Except in cases where the caller passes an invalid pointer to You might have a different interpretation of what the docs mean when they say "in bounds or one byte past the end..." than I do. I see this as meaning that we ensure pointers refer to valid/mapped memory even if that memory is an internal allocator data-structure. Indeed, we are generally careful to allocate any memory before we store a pointer to it; I don't see why memory being allocated using My intuition for this stems from the fact that the C standard has a similar provision for pointer arithmetic, and yet Furthermore, the |
This was inspired by this Rust issue. @kennytm may have thoughts on this. |
To be clear, I think that in practice you're right that this will work, although I'm wary about relying on behavior that isn't guaranteed by the documentation. |
Currently we use
offset
in a number of crates. However, it is unsafe to useoffset
to implement an allocator because, according to the docs, "both the starting and resulting pointer must be either in bounds or one byte past the end of an allocated object."Thus, we should switch to using
wrapping_offset
, which does not have this requirement.According to the
wrapping_offset
docs,offset
allows the compiler to make more aggressive optimizations, so we should be careful that this change does not regress performance.The text was updated successfully, but these errors were encountered: