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

Prefer raw::c_char or libc::c_char and fix arm #29775

Merged
merged 2 commits into from
Nov 11, 2015
Merged

Conversation

arcnmx
Copy link
Contributor

@arcnmx arcnmx commented Nov 11, 2015

It's a bit strange to expect users of libstd to require the use of an external crates.io crate to work with standard types. This commit encourages the use os::raw::c_char instead, although users are certainly free to use libc::c_char if they wish; the test still exists to ensure the two types are identical (though the reported bug only exists on platforms that are not officially tested).

Fixes #29774

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

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

#[cfg(not(any(target_arch = "aarch64", target_os = "android")))]
#[cfg(any(target_os = "ios", target_os = "macos",
not(any(target_arch = "aarch64", target_arch = "arm",
target_os = "android"))))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope all this is correct... ugh.

Copy link
Member

Choose a reason for hiding this comment

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

At least going by the current definition of liblibc, the type is unsigned for linux arm, linux aarch64, and android everywhere. Perhaps the ios/macos clause could be turned into a linux-specific clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, k, so if I have the logic right... everything is signed, exceptions are: linux aarch64 and arm, and android? The main thing I wasn't sure about were ARM BSDs.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm not entirely sure about BSDs, but they can always be fixed once we gain support!

@alexcrichton
Copy link
Member

Looks good to me, thanks @arcnmx!

I wouldn't necessarily go so far as to say we should all stop using libc::c_char just yet, but it's certainly true that the standard library shouldn't be reexporting APIs exposing the underlying unstable libc library!

@alexcrichton
Copy link
Member

@bors: r+ f9f7347

@arcnmx
Copy link
Contributor Author

arcnmx commented Nov 11, 2015

There that should be better I think? When can we just start using cfg-if in libstd :(

@alexcrichton
Copy link
Member

I wouldn't have a problem just vendoring the macro like libc does, it'd probably definitely pull its weight by this point!

Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 11, 2015
It's a bit strange to expect users of `libstd` to require the use of an external crates.io crate to work with standard types. This commit encourages the use `os::raw::c_char` instead, although users are certainly free to use `libc::c_char` if they wish; the test still exists to ensure the two types are identical (though the reported bug only exists on platforms that are not officially tested).

Fixes rust-lang#29774
bors added a commit that referenced this pull request Nov 11, 2015
@bors bors merged commit f9f7347 into rust-lang:master Nov 11, 2015
@liigo
Copy link
Contributor

liigo commented Nov 12, 2015

Maybe need a breaking-change mark?

@SimonSapin
Copy link
Contributor

I’m pretty sure this is a breaking change to stable APIs. Code that used to work cross-platform now fails to build with errors like expected *const i8, found *const u8`` on ARM targets (but not Intel targets): servo/servo#8446 (comment)

This seems like a violation of the stability promise with no apparent justification.

@larsbergstrom
Copy link
Contributor

cc: @alexcrichton @brson

@arcnmx
Copy link
Contributor Author

arcnmx commented Nov 16, 2015

@SimonSapin

True, it's a breaking change specifically on ARM Linux targets. I wasn't aware the stability promise applied to third tier platforms. The reasoning was that #29546 was a breaking change on that platform for the same reason, and also broke tests (the assertion that os::raw::c_char == libc::c_char).

This was to bring std back in line - the other alternative is to revert libc's change. Considering that the original API was wrong, ARM Linux isn't officially supported, and liblibc 0.2 was already deployed to crates.io, it seemed like we'd may as well just fix the issue and deal with the breakage.

@SimonSapin
Copy link
Contributor

For what it’s worth we’re seeing breakage on ARM Android. I don’t know if that’s more supported than ARM Linux.

@arcnmx
Copy link
Contributor Author

arcnmx commented Nov 16, 2015

@SimonSapin hm, that'd be a bug then. Also note that the errors you linked to were broken by #29546 and not this commit (see #29774).

EDIT: wait could be wrong. ugh let's check that cfg logic again...

@SimonSapin
Copy link
Contributor

Ah, sorry if I got the wrong culprit. I guessed at what changes seemed relevant in https://github.com/rust-lang/rust/commits/master/src/libstd/os/raw.rs

@arcnmx
Copy link
Contributor Author

arcnmx commented Nov 16, 2015

@SimonSapin yup the old libc was wrong on android too. From what I can tell x86 Android would've broke too? Android is also tier 3 so same argument applies :/

Solution for the most part is to update your dependencies that use libc to 0.2

@SimonSapin
Copy link
Contributor

(I don’t think we have CI for Servo on x86 Android.)

@arcnmx
Copy link
Contributor Author

arcnmx commented Nov 16, 2015

@SimonSapin though it was breaking regardless, the crux of the issue really is that we've all been depending on a crates.io dependency as part of the type signature of a std method, and when one changes without the other, things go boom~!

I still suggest everyone move away from libc::c_char, but I guess std::os::raw is 8 whole characters longer :(

@SimonSapin
Copy link
Contributor

I think it’s less about the number characters than the amount of existing code (that may have been written before std::os::raw existed) where we tend to apply the easiest fix whenever things break.

@SimonSapin
Copy link
Contributor

It looks like updating libc from 0.1 fixes at least some of the build errors. I’ll report back when we’ve updated everything. (Looks like we have 67 Cargo.toml files to update in a number of git repositories.)

@alexcrichton
Copy link
Member

I've opened #29867 to help track this.

SSheldon added a commit to SSheldon/rust-objc that referenced this pull request Dec 24, 2015
This should only be necessary until rust-lang/rust#29775 lands in stable
Rust with 1.6.
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