Skip to content

Invalid rust syntax in generated constants #582

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

Closed
Michael-F-Bryan opened this issue Mar 15, 2017 · 3 comments
Closed

Invalid rust syntax in generated constants #582

Michael-F-Bryan opened this issue Mar 15, 2017 · 3 comments

Comments

@Michael-F-Bryan
Copy link
Contributor

Input C/C++ Header

#include <r_lib.h>

Bindgen Invokation

extern crate bindgen;

use std::env;
use std::path::Path;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let _ = bindgen::builder()
        .header("bindings.h")
        .clang_arg("-I/usr/include/libr/")
        .generate()
        .unwrap()
        .write_to_file(Path::new(&out_dir).join("ffi.rs"));
}

Actual Results

$ cargo build
   Compiling radare2-sys v0.1.0 (file:///home/michael/Documents/radare2-sys)
error: unexpected token: `;`
   --> /home/michael/Documents/radare2-sys/target/debug/build/radare2-sys-53f778355b791841/out/ffi.rs:126:31
    |
126 | pub const INFINITY: f32 = inf.;
    |                               ^

error: unexpected token: `;`
   --> /home/michael/Documents/radare2-sys/target/debug/build/radare2-sys-53f778355b791841/out/ffi.rs:127:26
    |
127 | pub const NAN: f32 = NaN.;
    |                          ^

error: aborting due to 2 previous errors

error: Could not compile `radare2-sys`.

Expected Results

Bindgen shouldn't generate invalid syntax when declaring the two 32-bit float constants. That exact same C header file compiles fine when using Clang:

$ clang -I/usr/include/libr bindings.h

I am trying to generate bindings for radare2. radare2 was installed from source and its include files are put in /usr/include/libr.

RUST_LOG=bindgen Output

(output is identical to Actual Results section)

Miscellaneous Other Details

rustc: rustc 1.17.0-nightly (6f10e2f63 2017-03-14)
cargo: cargo 0.18.0-nightly (4a3c0a63b 2017-03-12)
bindgen: 0.22.1
llvm: 3.9.1
target triple: x86_64-unknown-linux-gnu
OS: Arch Linux

@emilio
Copy link
Contributor

emilio commented Mar 15, 2017

Reduced test case:

#define INFINITY (1.0f/0.0f)
#define NAN (0.0f/0.0f)

@Michael-F-Bryan
Copy link
Contributor Author

@emilio, thanks for simplifying the test case. I haven't looked through the radare2 source code yet, so I wasn't sure whether they came from a basic #define NAN (0.0f/0.0f) or if it was something more complex than that.

@emilio
Copy link
Contributor

emilio commented Mar 15, 2017

No worries! Fix over #583.

bors-servo pushed a commit that referenced this issue Mar 15, 2017
ir: Ignore non-finite macro constants from macros.

Fixes #582.
bors-servo pushed a commit that referenced this issue Mar 15, 2017
ir: Ignore non-finite macro constants from macros.

Fixes #582.
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

2 participants