jnigi icon indicating copy to clipboard operation
jnigi copied to clipboard

Support converting int32 return values

Open timob opened this issue 2 years ago • 2 comments

See https://github.com/timob/jnigi/pull/62#issuecomment-1242789704

Right now we convert return int values but not int32.

I think we should probably do int -> Int , int32 -> Int and int <- Int, int32 <- Int.

But with int -> Int on 64 bit systems if the int value is greater than max Int value return an error.

timob avatar Sep 15 '22 13:09 timob

I think we should rather modify int type-casting to int32 at https://github.com/timob/jnigi/blob/47aa21d956c7110830560fcf85c9daa829d3a76c/jnigi.go#L1243 because in Java every Integer or int are 32 bit. I can't be so sure about int (the primitive) inside JVM, but my knowledge of value overflow behavior hints that they should be 32bit as well (I could be testing that on 32-bit JVM!). Following up we should also add support for int32 in assignDest() and typeOfValue() both from jnigi.go Interesting enough I found out that there is "support" for int32 slice types in typeOfValue(), then why can't we also do similar for int32, *int32?

Also we could consider casting int32 to int (no value overflows - int is 32 bit or 64 bit and int32 is always 32 bit) for backward compatibility and generally ease of use for users used to int type.

Edit: As stated in docs, jint is signed 32 bits or at least was as of Java 1.7 https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html

londek avatar Sep 16 '22 17:09 londek

That's what I'm implying, treating Int as int32 internally.

timob avatar Sep 21 '22 10:09 timob

Been a while... but https://github.com/timob/jnigi/pull/76

timob avatar Nov 23 '23 23:11 timob

Merged in master now

timob avatar Nov 26 '23 21:11 timob

Closing this, pls reopen if any problems.

timob avatar Nov 26 '23 22:11 timob