Skip to content

Fixes #31229 fixes up BSD type mismatch errors and updates libc dependency part deux #31263

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

Merged
merged 5 commits into from
Feb 3, 2016
Merged

Fixes #31229 fixes up BSD type mismatch errors and updates libc dependency part deux #31263

merged 5 commits into from
Feb 3, 2016

Conversation

dhuseby
Copy link

@dhuseby dhuseby commented Jan 28, 2016

Something went haywire with github last night and the old PR #31230 got closed somehow. This new PR is to replace the old one. This incorporates all of the feedback from the other PR.

@alexcrichton I incorporated the suggestion from @semarie and the result is cleaner and clearer. I think this is ready to go.

@dhuseby dhuseby added A-bsd O-openbsd Operating system: OpenBSD O-freebsd Operating system: FreeBSD O-netbsd Operating system: NetBSD labels Jan 28, 2016
@rust-highfive
Copy link
Contributor

r? @brson

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

@dhuseby dhuseby changed the title fixes up BSD type mismatch errors and updates libc dependency part deux Fixes #31229 fixes up BSD type mismatch errors and updates libc dependency part deux Jan 28, 2016
if stackp == MAP_FAILED {
panic!("failed to allocate an alternative stack");
}
libc::stack_t { ss_sp: stackp as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
Copy link
Member

Choose a reason for hiding this comment

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

I'd personally prefer to not duplicate these calls to mmap (they both return have the exact same call). I saw discussion about a stack_t on the other thread, but why's that done here?

Copy link
Author

Choose a reason for hiding this comment

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

The reason this is duplicated is because there is only one mmap and it always returns a *mut libc::c_void. On FreeBSD and DragonflyBSD, the libc::stack_t.ss_sp member is a *mut i8. Also, because we have compile flags that say treat all warnings as errors, the FreeBSD and DragonflyBSD builds were failing.

What is needed is a conditional compilation block that casts the result of mmap to a *mut i8 when building for FreeBSD and DragonflyBSD. BUT, we don't have conditional compilation for general expressions yet. We only have it for functions. So I'm forced to wrap the mmap call and libc::stack_t initialization in a function that can be conditionally compiled based on OS.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we need this at all, though, doesn't this work on all platforms?

let stackp = mmap(...);
if stackp == MAP_FAILED { ... }
return stackp as *mut u8

Copy link
Author

Choose a reason for hiding this comment

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

No it doesn't. There are compile flags that turn warnings into errors and this generates a warning.

Copy link
Member

Choose a reason for hiding this comment

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

What flags are those? I thought we removed the lint for trivial casts... Either way a local #[allow] is better than all-out code duplication here I think

Copy link
Author

Choose a reason for hiding this comment

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

The errors on FreeBSD look like this:

../src/libstd/sys/unix/stack_overflow.rs:151:23: 151:32 error: mismatched types:
 expected `*mut i8`,
    found `*mut libc::c_void`
(expected i8,
    found enum `libc::c_void`) [E0308]
../src/libstd/sys/unix/stack_overflow.rs:151         stack.ss_sp = alt_stack;
                                                                   ^~~~~~~~~

Copy link
Author

Choose a reason for hiding this comment

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

oh wait, i see what you're saying. maybe we get an error whenever we go from *mut libc::c_void to *mut i8 but we may not get an error going the other way. so if we have a get_stack() function that always return the stack pointer as *mut i8 then we eliminate the error above on platforms that have an i8 stack pointer. let me try that in the morning.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah if everything returns *mut foo then returning bar as *mut foo shouldn't warn

Copy link
Author

Choose a reason for hiding this comment

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

@alexcrichton it didn't work. i changed the code to get_stack() -> *mut i8 for all platforms and now on non-freebsd, i'm getting:

../src/libstd/sys/unix/stack_overflow.rs:152:44: 152:55 error: mismatched types:
 expected `*mut libc::c_void`,
    found `*mut i8`
(expected enum `libc::c_void`,
    found i8) [E0308]
../src/libstd/sys/unix/stack_overflow.rs:152         let stack = libc::stack_t { ss_sp: get_stack(), ss_flags: 0, ss_size: SIGSTKSZ };

i don't think your solution works. we should go with this patch instead.

Copy link
Member

Choose a reason for hiding this comment

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

Right it's not working because this is using stack_t (and I don't know why). If that's not used and only pointers are used it shouldn't require duplication of the calls to mmap (which needs to be prioritized)

@bors
Copy link
Collaborator

bors commented Jan 29, 2016

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

@alexcrichton
Copy link
Member

I think the merge conflict is from libc, which at this point should be fully upgraded, so that part can probably be backed out of this change

@dhuseby
Copy link
Author

dhuseby commented Jan 29, 2016

@alexcrichton I backed out the libc update revision. If you accept my explanation for duplicating the call to mmap, then this PR should be GTG.

@brson
Copy link
Contributor

brson commented Feb 2, 2016

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned brson Feb 2, 2016
@dhuseby
Copy link
Author

dhuseby commented Feb 3, 2016

@alexcrichton i rebased and rearranged the code so that there is only a single call to mmap. this is simpler than previous solutions, but still relies on conditional compilation.

@alexcrichton
Copy link
Member

@bors: r+ ca6f920

@bors
Copy link
Collaborator

bors commented Feb 3, 2016

⌛ Testing commit ca6f920 with merge 54664f1...

bors added a commit that referenced this pull request Feb 3, 2016
Something went haywire with github last night and the old PR #31230 got closed somehow.  This new PR is to replace the old one.  This incorporates all of the feedback from the other PR.

@alexcrichton I incorporated the suggestion from @semarie and the result is cleaner and clearer.  I think this is ready to go.
@bors bors merged commit ca6f920 into rust-lang:master Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-freebsd Operating system: FreeBSD O-netbsd Operating system: NetBSD O-openbsd Operating system: OpenBSD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants