luhenry / netlib

An high-performance, hardware-accelerated implementation of Netlib in Java
Other
60 stars 12 forks source link

JVM segfaults when calling JNILAPACK#dlange with null workspace #16

Closed jonathanschilling closed 2 years ago

jonathanschilling commented 2 years ago

Hi,

I just stumbled across an issue that popped up with JNILAPACK (which gets used by default on my machine). A minimal non-working example is found here: https://github.com/jonathanschilling/netlib_mnwe/blob/master/src/test/java/de/labathome/netlib_mnwe/NetlibMNWE.java

Essentially I want to call LAPACK's dlange with an empty workspace array, which is considered valid with the Fortran implementation. Using JavaLAPACK and the old netlib-java by fommil, it is ok to pass null for the workspace array. However, it seems to be required to pass new double[0] to NativeLAPACK in order to circumvent a segfault.

My guess is that it is always tried to resolve the workspace array in the JNI wrapper of the local native LAPACK, which fails if the array is passed as null on the Java side. My vague idea for a fix is to introduce an additional check in the JNI wrapper that maps a null array from the Java side to NULL passed to the native LAPACK method.

It would be great if you could fix this, since it would allow us to really use this library as a drop-in replacement for netlib-java.

Thanks in advance for your efforts in this case! I am happy to provide more details on the problem and test potential fixes.

luhenry commented 2 years ago

@jonathanschilling sorry for the delayed response. Yes, that seems like a no brainer, let me fix it. If you want to provide a test, that would be ideal.

jonathanschilling commented 2 years ago

Great, thanks for the quick fix!

luhenry commented 1 year ago

@jonathanschilling that's getting released in v3.0.3 today.