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

Bindgen skips macros with token concatenation. #2402

Closed
TranquilRock opened this issue Jan 28, 2023 · 6 comments
Closed

Bindgen skips macros with token concatenation. #2402

TranquilRock opened this issue Jan 28, 2023 · 6 comments

Comments

@TranquilRock
Copy link

Input C/C++ Header

# define UL(x) x##UL
# define A UL(4294967295)
# define B 4294967295UL

Bindgen Invocation

$ bindgen input.h

Actual Result

/* automatically generated by rust-bindgen 0.59.1 */

pub const B: u32 = 4294967295;

Expected Results

/* automatically generated by rust-bindgen 0.59.1 */

pub const A: u32 = 4294967295;
pub const B: u32 = 4294967295;

Ref

@K900
Copy link

K900 commented Jan 31, 2023

I'm pretty sure it's not just token concatenation - any invocation of a macro in a #define seems ignored, even something as simple as

#define WRAP(v) v
#define WRAPPED WRAP(1)
#define NOT_WRAPPED 2

@K900
Copy link

K900 commented Jan 31, 2023

Actually looks like this is just a subset of #753

@pvdrz
Copy link
Contributor

pvdrz commented Jan 31, 2023

yeah this happens just because we don't know how to process function-like macros. Closing as a duplicate of #753

@pvdrz pvdrz closed this as completed Jan 31, 2023
@oToToT
Copy link

oToToT commented Jan 31, 2023

The bindgen output of the C code below

#define A 1 ## 2
#define B 2

is

/* automatically generated by rust-bindgen 0.61.0 */

pub const B: u32 = 2;

IIUC, it doesn't seem to be included in #753.

@jbaublitz
Copy link
Contributor

@oToToT The newest bindgen release includes work that resolves this issue despite not being included in the issue. I just tested with the newest bindgen and this syntax is handled with the --clang-macro-fallback flag.

@pvdrz
Copy link
Contributor

pvdrz commented Aug 21, 2024

Closed via #2779

@pvdrz pvdrz closed this as completed Aug 21, 2024
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

No branches or pull requests

5 participants