timob / jnigi

Golang Java JNI library
BSD 2-Clause "Simplified" License
163 stars 44 forks source link

Support converting int32 return values #64

Closed timob closed 10 months ago

timob commented 2 years ago

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.

londek commented 2 years ago

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

timob commented 2 years ago

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

timob commented 11 months ago

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

timob commented 10 months ago

Merged in master now

timob commented 10 months ago

Closing this, pls reopen if any problems.