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

double negative for i64 min value with i64 suffix #553

Closed
comicfans opened this issue Jul 30, 2020 · 6 comments
Closed

double negative for i64 min value with i64 suffix #553

comicfans opened this issue Jul 30, 2020 · 6 comments

Comments

@comicfans
Copy link

pub const value : i64 = -9_223_372_036_854_775_808i64;   //(i64::MIN)

gives incorrect result

static const int64_t value = --9223372036854775808; //double negative

but following is OK

pub const value : i64 = -9_223_372_036_854_775_807i64; //(not i64::MIN)                                     
pub const value : i64 = -9_223_372_036_854_775_808;  //(without suffix)

another confusing problem I've found is that

pub const value : i64 = i64::MIN;

didn't work, maybe cbindgen work at lexcial level so it can not handle such situation ? It will be helpful if docs mention this.

@emilio
Copy link
Collaborator

emilio commented Jul 31, 2020

Hmm, what version are you testing with? For the first example I get the following on master:

static const int64_t value = -9223372036854775808ULL;

Which seems about right. i64::MIN is not expected to work, for the reason you mention, cbindgen is a bit dumb dumb, see #214 etc :)

@comicfans
Copy link
Author

I've tried force update cbindgen before test, cbindgen -v shows 0.14.3

@emilio
Copy link
Collaborator

emilio commented Jul 31, 2020

Hmmm. This was intended to be fixed in #490 which is in that release... Can you check in master anyhow and confirm it's fixed there?

@comicfans
Copy link
Author

checkout master, cargo build and copy binary to ~/.cargo/bin, rebuild my header , still gives incorrect result. maybe different dependencies?

my rust toolchain

rustc 1.45.0 (5c1f21c3b 2020-07-13)

my cbindgen cargo tree

cbindgen v0.14.3 (/home/wangxinyu/cbindgen)
├── clap v2.33.0
│   ├── ansi_term v0.11.0
│   ├── atty v0.2.13
│   │   └── libc v0.2.66
│   ├── bitflags v1.2.1
│   ├── strsim v0.8.0
│   ├── textwrap v0.11.0
│   │   └── unicode-width v0.1.7
│   ├── unicode-width v0.1.7
│   └── vec_map v0.8.1
├── heck v0.3.1
│   └── unicode-segmentation v1.6.0
├── log v0.4.8
│   └── cfg-if v0.1.10
├── proc-macro2 v1.0.6
│   └── unicode-xid v0.2.0
├── quote v1.0.2
│   └── proc-macro2 v1.0.6 (*)
├── serde v1.0.104
│   └── serde_derive v1.0.104
│       ├── proc-macro2 v1.0.6 (*)
│       ├── quote v1.0.2 (*)
│       └── syn v1.0.11
│           ├── proc-macro2 v1.0.6 (*)
│           ├── quote v1.0.2 (*)
│           └── unicode-xid v0.2.0
├── serde_json v1.0.44
│   ├── itoa v0.4.4
│   ├── ryu v1.0.2
│   └── serde v1.0.104 (*)
├── syn v1.0.11 (*)
├── tempfile v3.1.0
│   ├── cfg-if v0.1.10
│   ├── libc v0.2.66
│   ├── rand v0.7.2
│   │   ├── getrandom v0.1.13
│   │   │   ├── cfg-if v0.1.10
│   │   │   └── libc v0.2.66
│   │   ├── libc v0.2.66
│   │   ├── rand_chacha v0.2.1
│   │   │   ├── c2-chacha v0.2.3
│   │   │   │   └── ppv-lite86 v0.2.6
│   │   │   └── rand_core v0.5.1
│   │   │       └── getrandom v0.1.13 (*)
│   │   └── rand_core v0.5.1 (*)
│   └── remove_dir_all v0.5.2
└── toml v0.5.5
    └── serde v1.0.104 (*)

@comicfans
Copy link
Author

comicfans commented Jul 31, 2020

my bad, although I've install latest cbindgen to path, but my Cargo.lock still points to older version. latest version have no such problem

@emilio
Copy link
Collaborator

emilio commented Jul 31, 2020

Great, thanks for checking!

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