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

Dyn keyword is not escaped. #1946

Closed
pronebird opened this issue Dec 17, 2020 · 1 comment · Fixed by #1951
Closed

Dyn keyword is not escaped. #1946

pronebird opened this issue Dec 17, 2020 · 1 comment · Fixed by #1951
Labels

Comments

@pronebird
Copy link

Input C/C++ Header

struct pf_addr_wrap {
	union {
		struct {
			struct pf_addr		 addr;
			struct pf_addr		 mask;
		}			 a;
		char			 ifname[IFNAMSIZ];
		char			 tblname[PF_TABLE_NAME_SIZE];
		char			 rtlabelname[RTLABEL_LEN];
		u_int32_t		 rtlabel;
	}			 v;
	union {
#ifdef KERNEL
		struct pfi_dynaddr	*dyn	__attribute__((aligned(8)));
		struct pfr_ktable	*tbl	__attribute__((aligned(8)));
#else /* !KERNEL */
		void			*dyn	__attribute__((aligned(8)));
		void			*tbl	__attribute__((aligned(8)));
#endif /* !KERNEL */
		int			 dyncnt __attribute__((aligned(8)));
		int			 tblcnt __attribute__((aligned(8)));
	}			 p __attribute__((aligned(8)));
	u_int8_t		 type;		/* PF_ADDR_* */
	u_int8_t		 iflags;	/* PFI_AFLAG_* */
};

Bindgen Invocation

bindgen::Builder::default()
    .header("input.h")
    .generate()
    .unwrap()

or

$ bindgen input.h --whatever --flags

Actual Results

error: expected identifier, found keyword `dyn`
   --> src/ffi/pfvar.rs:581:9
    |
581 |     pub dyn: *mut ::std::os::raw::c_void,
    |         ^^^ expected identifier, found keyword
    |
help: you can escape reserved keywords to use them as identifiers
    |
581 |     pub r#dyn: *mut ::std::os::raw::c_void,
    |         ^^^^^

error: unions cannot have zero fields
   --> src/ffi/pfvar.rs:580:1
    |
580 | / pub union pf_addr_wrap__bindgen_ty_2 {
581 | |     pub dyn: *mut ::std::os::raw::c_void,
582 | |     pub tbl: *mut ::std::os::raw::c_void,
583 | |     pub dyncnt: ::std::os::raw::c_int,
584 | |     pub tblcnt: ::std::os::raw::c_int,
585 | |     _bindgen_union_align: u64,
586 | | }
    | |_^

and/or

// Insert the (incorrect/buggy) generated bindings here

and/or

Insert compilation errors generated when compiling the bindings with rustc here

Expected Results

@emilio
Copy link
Contributor

emilio commented Dec 20, 2020

Nice catch, easy enough :)

#1951

@emilio emilio added the bug label Dec 20, 2020
emilio added a commit that referenced this issue Dec 20, 2020
LoganBarnett pushed a commit to LoganBarnett/rust-bindgen that referenced this issue Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants