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

mismatched types - enif_make_long(env, i) ^ expected i32, found i64 #284

Closed
delta1 opened this issue Nov 20, 2019 · 3 comments · Fixed by #285
Closed

mismatched types - enif_make_long(env, i) ^ expected i32, found i64 #284

delta1 opened this issue Nov 20, 2019 · 3 comments · Fixed by #285

Comments

@delta1
Copy link

delta1 commented Nov 20, 2019

Hey guys! In my excitement at the lovely improvements in #254 I'm trying to build against the current master branch (revision 5da9019)

I'm getting a weird error in cargo build, error: Could not compile 'rustler_sys'.

There are 4 errors about mismatched types in rustler_sys nif_api.snippet

Do you have any suggestions how I could fix this please?

error[E0308]: mismatched types
   --> C:\path\to\my_app\native\mynif\target\debug\build\rustler_sys-7ebc48992530b824\out/nif_api.snippet:907:27
    |
907 |     { enif_make_long(env, i) }
    |                           ^ expected i32, found i64
help: you can convert an `i64` to `i32` and panic if the converted value wouldn't fit
    |
907 |     { enif_make_long(env, i.try_into().unwrap()) }
    |                           ^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> C:\path\to\my_app\native\mynif\target\debug\build\rustler_sys-7ebc48992530b824\out/nif_api.snippet:912:28
    |
912 |     { enif_make_ulong(env, i) }
    |                            ^ expected u32, found u64
help: you can convert an `u64` to `u32` and panic if the converted value wouldn't fit
    |
912 |     { enif_make_ulong(env, i.try_into().unwrap()) }
    |                            ^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> C:\path\to\my_app\native\mynif\target\debug\build\rustler_sys-7ebc48992530b824\out/nif_api.snippet:917:32
    |
917 |     { enif_get_long(env, term, ip) }
    |                                ^^ expected i32, found i64
    |
    = note: expected type `*mut i32`
               found type `*mut i64`

error[E0308]: mismatched types
   --> C:\path\to\my_app\native\mynif\target\debug\build\rustler_sys-7ebc48992530b824\out/nif_api.snippet:922:33
    |
922 |     { enif_get_ulong(env, term, ip) }
    |                                 ^^ expected u32, found u64
    |
    = note: expected type `*mut u32`
               found type `*mut u64`

error: aborting due to 4 previous errors

I'm on windows but hopefully that's not an issue - rustler 0.21 works perfectly

Thank you for your time and this cool project!

@delta1
Copy link
Author

delta1 commented Nov 20, 2019

cc @scrogson @filmor @scohen

@filmor
Copy link
Member

filmor commented Nov 20, 2019

Oh man, I don't know how often I've been bitten by this now. Windows uses 32bit longs even on 64bit archs, different from Unix. That means that the logic in https://github.com/rusterlium/rustler/blob/master/rustler_sys/build.rs#L31 that attempts to derive the size of long from the target pointer width is wrong.

I'll create a PR for this.

@delta1
Copy link
Author

delta1 commented Nov 21, 2019

Today I learned! Thank you so much for your help, I can confirm that fixed the issue. Appreciated!

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 a pull request may close this issue.

2 participants