Skip to content

Keep radix for integer literals in generated bindings #3237

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

miikkas
Copy link

@miikkas miikkas commented Jun 18, 2025

The radices of integer literals in the input C/C++ code are retained in the generated bindings.

  • The radix of a C/C++ integer literal in constant, enum, or macro definition is parsed. If it can't be determined, the code falls back to not doing anything about the radix.
  • During Rust code generation, the radix of an integer literal – if it exists – is then used to output the value in that number base.
  • New testing is added in the form of unit tests for parsing the radix of a clang token and as a new test header file with its matching expected Rust binding output.
  • Existing tests are updated, since several had hexadecimal or octal values that now have the radix kept.

Fixes #3236.

@miikkas miikkas force-pushed the keep-radix branch 3 times, most recently from 8f8d206 to 7054e0f Compare June 19, 2025 17:32
@miikkas miikkas marked this pull request as ready for review June 19, 2025 17:35
@miikkas
Copy link
Author

miikkas commented Jun 19, 2025

I have now included additional testing to the PR.

Regarding the 13 failing existing tests: It seems that the differences are due to bindgen now generating, as intended, Rust literals using hexadecimal representation, while the values themselves have correctly stayed the same. Should I fix the expected code accordingly?

@miikkas
Copy link
Author

miikkas commented Jun 21, 2025

The test I added was changed to use C++14 instead of C23, as it seems that the latter is not available for clang 9.0, which IIUC is used in the CI.

I have changed the expected side of the previously failing existing tests. Those changes are currently included in a separate commit in case that makes review less cumbersome. I will squash it later as instructed in the contribution guidelines.

@miikkas miikkas marked this pull request as draft July 6, 2025 09:06
@miikkas miikkas force-pushed the keep-radix branch 4 times, most recently from 9064c00 to 2733cf6 Compare July 6, 2025 13:38
@miikkas miikkas marked this pull request as ready for review July 6, 2025 13:44
@miikkas
Copy link
Author

miikkas commented Jul 6, 2025

I have made the solution a lot more robust and included further unit testing.

r? @emilio

@rustbot
Copy link
Collaborator

rustbot commented Jul 6, 2025

Error: The feature assign is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

miikkas

This comment was marked as resolved.

miikkas added 2 commits July 7, 2025 17:25
Use the different radix literals for integers that were used in the original C
and C++ header files, now that it is supported. The new values were confirmed
by hand to be the same as the original ones - they are just represented using
the Rust equivalent of the original form.
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.

Keep the integer literal radices of C and C++ in generated Rust
2 participants