Skip to content
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

std: Second pass stabilization for ptr #20042

Merged
merged 1 commit into from
Dec 30, 2014

Conversation

alexcrichton
Copy link
Member

This commit performs a second pass for stabilization over the std::ptr module.
The specific actions taken were:

  • The RawPtr trait was renamed to PtrExt
  • The RawMutPtr trait was renamed to PtrMutExt
  • The module name ptr is now stable.
  • These functions were all marked #[stable] with no modification:
    • null
    • null_mut
    • swap
    • replace
    • read
    • write
    • PtrExt::is_null
    • PtrExt::is_not_null
    • PtrExt::offset
  • These functions remain unstable:
    • as_ref, as_mut - the return value of an Option is not fully expressive
      as null isn't the only bad value, and it's unclear
      whether we want to commit to these functions at this
      time. The reference/lifetime semantics as written are
      also problematic in how they encourage arbitrary
      lifetimes.
    • zero_memory - This function is currently not used at all in the
      distribution, and in general it plays a broader role in the
      "working with unsafe pointers" story. This story is not yet
      fully developed, so at this time the function remains
      unstable for now.
    • read_and_zero - This function remains unstable for largely the same
      reasons as zero_memory.
  • These functions are now all deprecated:
    • PtrExt::null - call ptr::null or ptr::null_mut instead.
    • PtrExt::to_uint - use an as expression instead.

@rust-highfive
Copy link
Collaborator

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @aturon

}

#[inline]
#[unstable = "return value does not necessarily convey all possible \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to say: Option is not clearly the right return type, and we may want to tie the return lifetime to a borrow of the raw pointer.

@aturon
Copy link
Member

aturon commented Dec 19, 2014

r=me modulo tiny nit

@alexcrichton
Copy link
Member Author

deleting r+ for now, I'd like to take some more time to analyze https://github.com/Gankro/raw-rs/blob/master/src/rawptr.rs

@Gankra
Copy link
Contributor

Gankra commented Dec 20, 2014

CC me

@alexcrichton
Copy link
Member Author

Ok, after thinking about this and talking it over with @gankro, I'm thinking the following:

  • Adding the free-functions as methods on the PtrExt or PtrMutExt trait would be nice, but does lead to duplication. There's also a desire, however, to keep the duplication due to the free-functions allowing for coercion.
  • Some functions may wish to be renamed, such as copy_memory => copy, set_memory => write_bytes, etc.
  • Other convenience methods like add and sub for the offset function taking a uint instead of an int.

For now the functionality stabilized here I believe is a subset of the possible future functionality, and I think we can let feedback during the first alpha cycle to drive the rest of what we stabilize in this module.

Does that sound ok @gankro?

re-r? @aturon

fn is_not_null(&self) -> bool { !self.is_null() }
/// Returns true if the pointer is not equal to the null pointer.
#[stable]
fn is_not_null(self) -> bool { !self.is_null() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be dropped in favor of !p.is_null()?

@aturon
Copy link
Member

aturon commented Dec 29, 2014

r=me modulo nits.

@Gankra
Copy link
Contributor

Gankra commented Dec 29, 2014

Sounds okay, but the renames are a back-compat issue, no?

@aturon
Copy link
Member

aturon commented Dec 29, 2014

@gankro

Sounds okay, but the renames are a back-compat issue, no?

Neither are being stabilized here, FWIW.

@Gankra
Copy link
Contributor

Gankra commented Dec 29, 2014

Not sure if it matters, but they are compiler intrinsics.

This commit performs a second pass for stabilization over the `std::ptr` module.
The specific actions taken were:

* The `RawPtr` trait was renamed to `PtrExt`
* The `RawMutPtr` trait was renamed to `MutPtrExt`
* The module name `ptr` is now stable.
* These functions were all marked `#[stable]` with no modification:
  * `null`
  * `null_mut`
  * `swap`
  * `replace`
  * `read`
  * `write`
  * `PtrExt::is_null`
  * `PtrExt::offset`
* These functions remain unstable:
  * `as_ref`, `as_mut` - the return value of an `Option` is not fully expressive
                         as null isn't the only bad value, and it's unclear
                         whether we want to commit to these functions at this
                         time. The reference/lifetime semantics as written are
                         also problematic in how they encourage arbitrary
                         lifetimes.
  * `zero_memory` - This function is currently not used at all in the
                    distribution, and in general it plays a broader role in the
                    "working with unsafe pointers" story. This story is not yet
                    fully developed, so at this time the function remains
                    unstable for now.
  * `read_and_zero` - This function remains unstable for largely the same
                      reasons as `zero_memory`.
* These functions are now all deprecated:
  * `PtrExt::null` - call `ptr::null` or `ptr::null_mut` instead.
  * `PtrExt::to_uint` - use an `as` expression instead.
  * `PtrExt::is_not_null` - use `!p.is_null()` instead.
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 30, 2014
This commit performs a second pass for stabilization over the `std::ptr` module.
The specific actions taken were:

* The `RawPtr` trait was renamed to `PtrExt`
* The `RawMutPtr` trait was renamed to `PtrMutExt`
* The module name `ptr` is now stable.
* These functions were all marked `#[stable]` with no modification:
  * `null`
  * `null_mut`
  * `swap`
  * `replace`
  * `read`
  * `write`
  * `PtrExt::is_null`
  * `PtrExt::is_not_null`
  * `PtrExt::offset`
* These functions remain unstable:
  * `as_ref`, `as_mut` - the return value of an `Option` is not fully expressive
                         as null isn't the only bad value, and it's unclear
                         whether we want to commit to these functions at this
                         time. The reference/lifetime semantics as written are
                         also problematic in how they encourage arbitrary
                         lifetimes.
  * `zero_memory` - This function is currently not used at all in the
                    distribution, and in general it plays a broader role in the
                    "working with unsafe pointers" story. This story is not yet
                    fully developed, so at this time the function remains
                    unstable for now.
  * `read_and_zero` - This function remains unstable for largely the same
                      reasons as `zero_memory`.
* These functions are now all deprecated:
  * `PtrExt::null` - call `ptr::null` or `ptr::null_mut` instead.
  * `PtrExt::to_uint` - use an `as` expression instead.
@bors bors merged commit 54452cd into rust-lang:master Dec 30, 2014
@alexcrichton alexcrichton deleted the second-pass-ptr branch January 7, 2015 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants