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: Stabilize the ffi module #22975

Merged
merged 1 commit into from
Mar 7, 2015
Merged

Conversation

alexcrichton
Copy link
Member

The two main sub-modules, c_str and os_str, have now had some time to bake
in the standard library. This commits performs a sweep over the modules adding
various stability tags.

The following APIs are now marked #[stable]

  • OsString
  • OsStr
  • OsString::from_string
  • OsString::from_str
  • OsString::new
  • OsString::into_string
  • OsString::push (renamed from push_os_str, added an AsOsStr bound)
  • various trait implementations for OsString
  • OsStr::from_str
  • OsStr::to_str
  • OsStr::to_string_lossy
  • OsStr::to_os_string
  • various trait implementations for OsStr
  • CString
  • CStr
  • NulError
  • CString::new - this API's implementation may change as a result of
    RFC: improve CString construction methods rfcs#912 but the usage of CString::new(thing) looks like it is
    unlikely to change. Additionally, the IntoBytes bound is also likely to
    change but the set of implementors for the trait will not change (despite the
    trait perhaps being renamed).
  • CString::from_vec_unchecked
  • CString::as_bytes
  • CString::as_bytes_with_nul
  • NulError::nul_position
  • NulError::into_vec
  • CStr::from_ptr
  • CStr::to_bytes
  • CStr::to_bytes_with_nul
  • various trait implementations for CStr

The following APIs remain #[unstable]

  • OsStr*Ext traits remain unstable as the organization of os::platform is
    uncertain still and the traits may change location.
  • AsOsStr remains unstable as generic conversion traits are likely to be
    rethought soon.

The following APIs were deprecated

  • OsString::push_os_str is now called push and takes T: AsOsStr instead (a
    superset of the previous functionality).

[breaking-change]

@rust-highfive
Copy link
Collaborator

r? @huonw

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

@aturon aturon mentioned this pull request Mar 2, 2015
91 tasks
@alexcrichton
Copy link
Member Author

r? @aturon

@rust-highfive rust-highfive assigned aturon and unassigned huonw Mar 2, 2015
@alexcrichton
Copy link
Member Author

cc @mzabaluev, rust-lang/rfcs#912

@mzabaluev
Copy link
Contributor

In rust-lang/rfcs#912 it was proposed to change (and perhaps rename) IntoBytes to convert directly to CString. Other than that, the stabilization looks OK.


pub use self::c_str::{CString, CStr, NulError, IntoBytes};
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

Choose a reason for hiding this comment

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

Stable reexport?

Copy link
Member Author

Choose a reason for hiding this comment

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

While not currently recognized by the compiler I've found it useful to see reexports tagged with stability attributes for rustdoc when it doesn't inline documentation and perhaps just helpful when reading code. It doesn't currently serve any semantic purpose though.

@bors
Copy link
Contributor

bors commented Mar 3, 2015

☔ The latest upstream changes (presumably #22995) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member Author

@mzabaluev thanks for taking a look! Due to the unstable-ness of IntoBytes we should be fine renaming it backwards compatibly. I was considering doing so in this PR but I opted not to wait for the resolution of your RFC.

@alexcrichton
Copy link
Member Author

Ah and I just realized that I forgot to decide on CStr::as_ptr (cc #16035). I forget the outcome of our discussions around this @aturon, but would you be ok stabilizing for now?

inner: [libc::c_char]
}

/// An error returned from `CString::new` to indicate that a nul byte was found
/// in the vector provided.
#[derive(Clone, PartialEq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct NulError(usize, Vec<u8>);
Copy link
Member

Choose a reason for hiding this comment

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

We're moving away from public tuple structs in std; this should probably be a normal struct with accessors.

Copy link
Member

Choose a reason for hiding this comment

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

Oops nevermind.

Copy link
Member

Choose a reason for hiding this comment

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

(I always forget that, unlike enum variants, the pub doesn't automatically extend to tuple components...)

@aturon
Copy link
Member

aturon commented Mar 5, 2015

@alexcrichton as_ptr remains a real footgun, but we decided that it's not feasible to land the infrastructure needed to do better for 1.0. You were planning to work on the design and eventually submit an RFC.

Meanwhile, it seemed ok to stabilize as_ptr as-is, with an eventual planned deprecation.

I wonder if type ascription would change the tradeoff at all? In particular, we were worried about cases involving null to-from Option conversion and triggering coercions. Ascription could help with ergonomics tehre.

In any case, I think it's fine to stabilize this for now, because any reference-based replacement would likely want a different name and lead to deprecation of this method. If that happens before 1.0, all the better.

Otherwise, r=me.

@alexcrichton
Copy link
Member Author

@bors: r=aturon 6ab4938

The two main sub-modules, `c_str` and `os_str`, have now had some time to bake
in the standard library. This commits performs a sweep over the modules adding
various stability tags.

The following APIs are now marked `#[stable]`

* `OsString`
* `OsStr`
* `OsString::from_string`
* `OsString::from_str`
* `OsString::new`
* `OsString::into_string`
* `OsString::push` (renamed from `push_os_str`, added an `AsOsStr` bound)
* various trait implementations for `OsString`
* `OsStr::from_str`
* `OsStr::to_str`
* `OsStr::to_string_lossy`
* `OsStr::to_os_string`
* various trait implementations for `OsStr`
* `CString`
* `CStr`
* `NulError`
* `CString::new` - this API's implementation may change as a result of
  rust-lang/rfcs#912 but the usage of `CString::new(thing)` looks like it is
  unlikely to change. Additionally, the `IntoBytes` bound is also likely to
  change but the set of implementors for the trait will not change (despite the
  trait perhaps being renamed).
* `CString::from_vec_unchecked`
* `CString::as_bytes`
* `CString::as_bytes_with_nul`
* `NulError::nul_position`
* `NulError::into_vec`
* `CStr::from_ptr`
* `CStr::as_ptr`
* `CStr::to_bytes`
* `CStr::to_bytes_with_nul`
* various trait implementations for `CStr`

The following APIs remain `#[unstable]`

* `OsStr*Ext` traits remain unstable as the organization of `os::platform` is
  uncertain still and the traits may change location.
* `AsOsStr` remains unstable as generic conversion traits are likely to be
  rethought soon.

The following APIs were deprecated

* `OsString::push_os_str` is now called `push` and takes `T: AsOsStr` instead (a
  superset of the previous functionality).
@alexcrichton
Copy link
Member Author

@bors: r=aturon 628f5d2

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 6, 2015
Conflicts:
	src/librustc_trans/back/link.rs
	src/librustc_trans/lib.rs
@bors bors merged commit 628f5d2 into rust-lang:master Mar 7, 2015
@alexcrichton alexcrichton deleted the stabilize-ffi branch March 7, 2015 06:13
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.

7 participants