Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
}

plugins {
id 'java'
id 'maven-publish'
}

group 'org.julia'
version '0.0.1-SNAPSHOT'
version '0.0.2-SNAPSHOT'

sourceCompatibility = 1.8
sourceCompatibility = 1.11

repositories {
mavenCentral()
}

publishing {
publications {
maven(MavenPublication) {
groupId = group
artifactId = rootProject.name
version = version

from components.java
}
}
}

test {
useJUnitPlatform()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.2.0")
testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.2')
testImplementation('org.junit.jupiter:junit-jupiter-engine:5.8.2')
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
47 changes: 39 additions & 8 deletions src/main/java/org/julia/jni/NativeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
*/
package org.julia.jni;

import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.ProviderNotFoundException;
import java.nio.file.StandardCopyOption;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* A simple library class which helps with loading dynamic libraries stored in the
Expand All @@ -49,6 +50,7 @@ public class NativeUtils {
*/
private static final int MIN_PREFIX_LENGTH = 3;
public static final String NATIVE_FOLDER_PATH_PREFIX = "nativeutils";
public static final String JAVA_LIBRARY_PATH = "java.library.path";

/**
* Temporary directory which will contain the DLLs.
Expand All @@ -75,7 +77,8 @@ private NativeUtils() {
* (restriction of {@link File#createTempFile(java.lang.String, java.lang.String)}).
* @throws FileNotFoundException If the file could not be found inside the JAR.
*/
public static void loadLibraryFromJar(String path) throws IOException {
public static void loadLibraryFromJar(String path, String libraryPaths) throws IOException {
setupJavaLibraryPaths(libraryPaths);

if (null == path || !path.startsWith("/")) {
throw new IllegalArgumentException("The path has to be absolute (start with '/').");
Expand Down Expand Up @@ -110,6 +113,10 @@ public static void loadLibraryFromJar(String path) throws IOException {

try {
System.load(temp.getAbsolutePath());
} catch (UnsatisfiedLinkError e) {
throw new UnsatisfiedLinkError(
String.format("%s\njava.library.path=%s\n",
e.getMessage(), System.getProperty(JAVA_LIBRARY_PATH)));
} finally {
if (isPosixCompliant()) {
// Assume POSIX compliant file system, can be deleted after loading
Expand All @@ -121,6 +128,10 @@ public static void loadLibraryFromJar(String path) throws IOException {
}
}

public static void loadLibraryFromJar(String path) throws IOException {
loadLibraryFromJar(path, "");
}

private static boolean isPosixCompliant() {
try {
return FileSystems.getDefault()
Expand Down Expand Up @@ -175,11 +186,31 @@ public static List<String> loadedLibraryNames() {
final Field lib = ClassLoader.class.getDeclaredField("loadedLibraryNames");
lib.setAccessible(true);
Object list = lib.get(ClassLoader.getSystemClassLoader());
if (list instanceof List)
if (list instanceof List<?>)
return (List<String>) list;
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
return Collections.emptyList();
}

private static void setupJavaLibraryPaths(String externalPaths) {
String javaLibraryPath = System.getProperty(JAVA_LIBRARY_PATH);
String javaHome = System.getProperty("java.home");
// if (!javaLibraryPath.contains(javaHome)) {
String javaLibPath = javaHome + File.separator + "lib";
final List<String> newSysPaths =
new ArrayList<>(List.of(javaLibraryPath.split(File.pathSeparator)));
newSysPaths.add(javaLibPath);
newSysPaths.add(javaLibPath + File.separator + "server");
newSysPaths.addAll(List.of(externalPaths.split(File.pathSeparator)));

System.setProperty(JAVA_LIBRARY_PATH,
newSysPaths.stream()
.filter(s -> !s.isEmpty())
.distinct()
.collect(Collectors.joining(File.pathSeparator))
);
// }
}
}
72 changes: 60 additions & 12 deletions src/main/java/org/julia/jni/swig/Julia4J.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down Expand Up @@ -45,8 +45,8 @@ public static void jl_set_sysimg_so(SWIGTYPE_p_void handle) {
Julia4JJNI.jl_set_sysimg_so(SWIGTYPE_p_void.getCPtr(handle));
}

public static SWIGTYPE_p_ios_t jl_create_system_image() {
long cPtr = Julia4JJNI.jl_create_system_image();
public static SWIGTYPE_p_ios_t jl_create_system_image(SWIGTYPE_p_void arg0) {
long cPtr = Julia4JJNI.jl_create_system_image(SWIGTYPE_p_void.getCPtr(arg0));
return (cPtr == 0) ? null : new SWIGTYPE_p_ios_t(cPtr, false);
}

Expand Down Expand Up @@ -106,6 +106,45 @@ public static SWIGTYPE_p_jl_value_t jl_eval_string(String str) {
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_apply_generic(SWIGTYPE_p_jl_value_t F, SWIGTYPE_p_p_jl_value_t args, long nargs) {
long cPtr = Julia4JJNI.jl_apply_generic(SWIGTYPE_p_jl_value_t.getCPtr(F), SWIGTYPE_p_p_jl_value_t.getCPtr(args), nargs);
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_invoke(SWIGTYPE_p_jl_value_t F, SWIGTYPE_p_p_jl_value_t args, long nargs, SWIGTYPE_p_jl_method_instance_t meth) {
long cPtr = Julia4JJNI.jl_invoke(SWIGTYPE_p_jl_value_t.getCPtr(F), SWIGTYPE_p_p_jl_value_t.getCPtr(args), nargs, SWIGTYPE_p_jl_method_instance_t.getCPtr(meth));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static int jl_invoke_api(SWIGTYPE_p_jl_code_instance_t linfo) {
return Julia4JJNI.jl_invoke_api(SWIGTYPE_p_jl_code_instance_t.getCPtr(linfo));
}

public static SWIGTYPE_p_jl_value_t jl_call(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_p_jl_value_t args, int nargs) {
long cPtr = Julia4JJNI.jl_call(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_p_jl_value_t.getCPtr(args), nargs);
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_call0(SWIGTYPE_p_jl_function_t f) {
long cPtr = Julia4JJNI.jl_call0(SWIGTYPE_p_jl_function_t.getCPtr(f));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_call1(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_jl_value_t a) {
long cPtr = Julia4JJNI.jl_call1(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_jl_value_t.getCPtr(a));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_call2(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_jl_value_t a, SWIGTYPE_p_jl_value_t b) {
long cPtr = Julia4JJNI.jl_call2(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_jl_value_t.getCPtr(a), SWIGTYPE_p_jl_value_t.getCPtr(b));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_call3(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_jl_value_t a, SWIGTYPE_p_jl_value_t b, SWIGTYPE_p_jl_value_t c) {
long cPtr = Julia4JJNI.jl_call3(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_jl_value_t.getCPtr(a), SWIGTYPE_p_jl_value_t.getCPtr(b), SWIGTYPE_p_jl_value_t.getCPtr(c));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_new_bits(SWIGTYPE_p_jl_value_t bt, SWIGTYPE_p_void data) {
long cPtr = Julia4JJNI.jl_new_bits(SWIGTYPE_p_jl_value_t.getCPtr(bt), SWIGTYPE_p_void.getCPtr(data));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
Expand Down Expand Up @@ -201,15 +240,6 @@ public static SWIGTYPE_p_jl_sym_t jl_get_root_symbol() {
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_sym_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_generic_function_def(SWIGTYPE_p_jl_sym_t name, SWIGTYPE_p_jl_module_t module, SWIGTYPE_p_p_jl_value_t bp, SWIGTYPE_p_jl_value_t bp_owner, SWIGTYPE_p_jl_binding_t bnd) {
long cPtr = Julia4JJNI.jl_generic_function_def(SWIGTYPE_p_jl_sym_t.getCPtr(name), SWIGTYPE_p_jl_module_t.getCPtr(module), SWIGTYPE_p_p_jl_value_t.getCPtr(bp), SWIGTYPE_p_jl_value_t.getCPtr(bp_owner), SWIGTYPE_p_jl_binding_t.getCPtr(bnd));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static void jl_method_def(SWIGTYPE_p_jl_svec_t argdata, SWIGTYPE_p_jl_code_info_t f, SWIGTYPE_p_jl_module_t module) {
Julia4JJNI.jl_method_def(SWIGTYPE_p_jl_svec_t.getCPtr(argdata), SWIGTYPE_p_jl_code_info_t.getCPtr(f), SWIGTYPE_p_jl_module_t.getCPtr(module));
}

public static SWIGTYPE_p_jl_code_info_t jl_code_for_staged(SWIGTYPE_p_jl_method_instance_t linfo) {
long cPtr = Julia4JJNI.jl_code_for_staged(SWIGTYPE_p_jl_method_instance_t.getCPtr(linfo));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_code_info_t(cPtr, false);
Expand Down Expand Up @@ -294,6 +324,11 @@ public static SWIGTYPE_p_jl_value_t jl_box_voidpointer(SWIGTYPE_p_void x) {
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_box_uint8pointer(SWIGTYPE_p_unsigned_char x) {
long cPtr = Julia4JJNI.jl_box_uint8pointer(SWIGTYPE_p_unsigned_char.getCPtr(x));
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
}

public static SWIGTYPE_p_jl_value_t jl_box_ssavalue(long x) {
long cPtr = Julia4JJNI.jl_box_ssavalue(x);
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
Expand Down Expand Up @@ -353,8 +388,21 @@ public static SWIGTYPE_p_void jl_unbox_voidpointer(SWIGTYPE_p_jl_value_t v) {
return (cPtr == 0) ? null : new SWIGTYPE_p_void(cPtr, false);
}

public static SWIGTYPE_p_unsigned_char jl_unbox_uint8pointer(SWIGTYPE_p_jl_value_t v) {
long cPtr = Julia4JJNI.jl_unbox_uint8pointer(SWIGTYPE_p_jl_value_t.getCPtr(v));
return (cPtr == 0) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
}

public static int jl_get_size(SWIGTYPE_p_jl_value_t val, SWIGTYPE_p_size_t pnt) {
return Julia4JJNI.jl_get_size(SWIGTYPE_p_jl_value_t.getCPtr(val), SWIGTYPE_p_size_t.getCPtr(pnt));
}

public static String jl_unbox_string(SWIGTYPE_p_jl_value_t v) {
return Julia4JJNI.jl_unbox_string(SWIGTYPE_p_jl_value_t.getCPtr(v));
}

public static void jl_show(SWIGTYPE_p_jl_value_t v) {
Julia4JJNI.jl_show(SWIGTYPE_p_jl_value_t.getCPtr(v));
}

}
18 changes: 14 additions & 4 deletions src/main/java/org/julia/jni/swig/Julia4JJNI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand All @@ -18,7 +18,7 @@ public class Julia4JJNI {
public final static native String jl_pathname_for_handle(long jarg1);
public final static native void jl_preload_sysimg_so(String jarg1);
public final static native void jl_set_sysimg_so(long jarg1);
public final static native long jl_create_system_image();
public final static native long jl_create_system_image(long jarg1);
public final static native void jl_save_system_image(String jarg1);
public final static native void jl_restore_system_image(String jarg1);
public final static native void jl_restore_system_image_data(String jarg1, long jarg2);
Expand All @@ -31,6 +31,14 @@ public class Julia4JJNI {
public final static native long jl_expand(long jarg1, long jarg2);
public final static native long jl_expand_stmt(long jarg1, long jarg2);
public final static native long jl_eval_string(String jarg1);
public final static native long jl_apply_generic(long jarg1, long jarg2, long jarg3);
public final static native long jl_invoke(long jarg1, long jarg2, long jarg3, long jarg4);
public final static native int jl_invoke_api(long jarg1);
public final static native long jl_call(long jarg1, long jarg2, int jarg3);
public final static native long jl_call0(long jarg1);
public final static native long jl_call1(long jarg1, long jarg2);
public final static native long jl_call2(long jarg1, long jarg2, long jarg3);
public final static native long jl_call3(long jarg1, long jarg2, long jarg3, long jarg4);
public final static native long jl_new_bits(long jarg1, long jarg2);
public final static native long jl_new_struct(long jarg1);
public final static native long jl_new_structv(long jarg1, long jarg2, long jarg3);
Expand All @@ -50,8 +58,6 @@ public class Julia4JJNI {
public final static native long jl_gensym();
public final static native long jl_tagged_gensym(String jarg1, int jarg2);
public final static native long jl_get_root_symbol();
public final static native long jl_generic_function_def(long jarg1, long jarg2, long jarg3, long jarg4, long jarg5);
public final static native void jl_method_def(long jarg1, long jarg2, long jarg3);
public final static native long jl_code_for_staged(long jarg1);
public final static native long jl_copy_code_info(long jarg1);
public final static native long jl_get_world_counter();
Expand All @@ -69,6 +75,7 @@ public class Julia4JJNI {
public final static native long jl_box_float32(float jarg1);
public final static native long jl_box_float64(double jarg1);
public final static native long jl_box_voidpointer(long jarg1);
public final static native long jl_box_uint8pointer(long jarg1);
public final static native long jl_box_ssavalue(long jarg1);
public final static native long jl_box_slotnumber(long jarg1);
public final static native byte jl_unbox_bool(long jarg1);
Expand All @@ -83,5 +90,8 @@ public class Julia4JJNI {
public final static native float jl_unbox_float32(long jarg1);
public final static native double jl_unbox_float64(long jarg1);
public final static native long jl_unbox_voidpointer(long jarg1);
public final static native long jl_unbox_uint8pointer(long jarg1);
public final static native int jl_get_size(long jarg1, long jarg2);
public final static native String jl_unbox_string(long jarg1);
public final static native void jl_show(long jarg1);
}
2 changes: 1 addition & 1 deletion src/main/java/org/julia/jni/swig/SWIGTYPE_p_ios_t.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package org.julia.jni.swig;

public class SWIGTYPE_p_jl_code_instance_t {
private transient long swigCPtr;

protected SWIGTYPE_p_jl_code_instance_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}

protected SWIGTYPE_p_jl_code_instance_t() {
swigCPtr = 0;
}

protected static long getCPtr(SWIGTYPE_p_jl_code_instance_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
Expand Down
Loading