Skip to content

Treat char as c_char #609

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 1 commit into from
Apr 4, 2017
Merged

Treat char as c_char #609

merged 1 commit into from
Apr 4, 2017

Conversation

dimbleby
Copy link
Contributor

@dimbleby dimbleby commented Apr 3, 2017

Per #603.

This still leaves bindgen having to make a call as to what to say when asked whether Char is_signed(). I've opted just to leave this as true, on the grounds that:

  • I don't currently understand an example where it matters
  • I suspect that if there are cases where it matters, then it shouldn't!
    • Because by definition, use of unadorned char in the original header says that it doesn't care about signedness
  • (signed is the common case, so that's a more sensible guess than unsigned)

@highfive
Copy link

highfive commented Apr 3, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@dimbleby
Copy link
Contributor Author

dimbleby commented Apr 3, 2017

So I experimented with having bindgen claim that char was unsigned, to see what breaks.

The answer is: this input gives MinusOne = 255.

But I reckon that supports what I said above: this header was broken in the first place, because if you set a char to -1, you're asking for trouble on platforms where char is unsigned.

@emilio
Copy link
Contributor

emilio commented Apr 3, 2017

I opened #610 with the approach I suggested in #603, which seems to work. I believe it's a more robust solution, feedback welcome.

@bors-servo
Copy link

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

bors-servo pushed a commit that referenced this pull request Apr 3, 2017
ir: Handle char in a more cross-platform way when possible.

This should address #603, and supersede #609
@dimbleby
Copy link
Contributor Author

dimbleby commented Apr 4, 2017

So compared to this, your #610 was different in three ways:

  • additional testcases. Obviously pure win!
  • treats char in platform-specific way. For reasons given above, I'm neutral about this: but if it's anything, it's an improvement
  • ugly grubbing around with spelling()

I think this last is at best unnecessary: clang already has four types, precisely to distinguish between "signed char", "unsigned char", "char that happens to be signed" and "char that happens to be unsigned". So we can just use them directly.

I'll update this pull request so that it makes that change instead.

@emilio
Copy link
Contributor

emilio commented Apr 4, 2017

Looks good, thanks! Sometimes I wish the libclang docs would be a bit better about that stuff, I just didn't want to dig into LLVM's source to see the difference between those yesterday.

@bors-servo r+

Thanks again!

@bors-servo
Copy link

📌 Commit aa04308 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit aa04308 with merge 642b695...

bors-servo pushed a commit that referenced this pull request Apr 4, 2017
Treat char as c_char

Per #603.

This still leaves `bindgen` having to make a call as to what to say when asked whether `Char` `is_signed()`.  I've opted just to leave this as `true`, on the grounds that:

* I don't currently understand an example where it matters
* I suspect that if there are cases where it matters, then it shouldn't!
  * Because by definition, use of unadorned `char` in the original header says that it doesn't care about signedness
* (signed is the common case, so that's a more sensible guess than unsigned)
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 642b695 to master...

@bors-servo bors-servo merged commit aa04308 into rust-lang:master Apr 4, 2017
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.

4 participants