Skip to content

Commit c9c7a78

Browse files
authored
Jl string wrapper (#3)
* added string wrapper for char* jl_... result * added test for returned string value * extended swig interface * updated swig generated files
1 parent b9d2132 commit c9c7a78

File tree

7 files changed

+366
-1
lines changed

7 files changed

+366
-1
lines changed

src/main/java/org/julia/jni/swig/Julia4J.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,45 @@ public static SWIGTYPE_p_jl_value_t jl_eval_string(String str) {
106106
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
107107
}
108108

109+
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) {
110+
long cPtr = Julia4JJNI.jl_apply_generic(SWIGTYPE_p_jl_value_t.getCPtr(F), SWIGTYPE_p_p_jl_value_t.getCPtr(args), nargs);
111+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
112+
}
113+
114+
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) {
115+
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));
116+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
117+
}
118+
119+
public static int jl_invoke_api(SWIGTYPE_p_jl_code_instance_t linfo) {
120+
return Julia4JJNI.jl_invoke_api(SWIGTYPE_p_jl_code_instance_t.getCPtr(linfo));
121+
}
122+
123+
public static SWIGTYPE_p_jl_value_t jl_call(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_p_jl_value_t args, int nargs) {
124+
long cPtr = Julia4JJNI.jl_call(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_p_jl_value_t.getCPtr(args), nargs);
125+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
126+
}
127+
128+
public static SWIGTYPE_p_jl_value_t jl_call0(SWIGTYPE_p_jl_function_t f) {
129+
long cPtr = Julia4JJNI.jl_call0(SWIGTYPE_p_jl_function_t.getCPtr(f));
130+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
131+
}
132+
133+
public static SWIGTYPE_p_jl_value_t jl_call1(SWIGTYPE_p_jl_function_t f, SWIGTYPE_p_jl_value_t a) {
134+
long cPtr = Julia4JJNI.jl_call1(SWIGTYPE_p_jl_function_t.getCPtr(f), SWIGTYPE_p_jl_value_t.getCPtr(a));
135+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
136+
}
137+
138+
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) {
139+
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));
140+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
141+
}
142+
143+
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) {
144+
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));
145+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
146+
}
147+
109148
public static SWIGTYPE_p_jl_value_t jl_new_bits(SWIGTYPE_p_jl_value_t bt, SWIGTYPE_p_void data) {
110149
long cPtr = Julia4JJNI.jl_new_bits(SWIGTYPE_p_jl_value_t.getCPtr(bt), SWIGTYPE_p_void.getCPtr(data));
111150
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
@@ -285,6 +324,11 @@ public static SWIGTYPE_p_jl_value_t jl_box_voidpointer(SWIGTYPE_p_void x) {
285324
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
286325
}
287326

327+
public static SWIGTYPE_p_jl_value_t jl_box_uint8pointer(SWIGTYPE_p_unsigned_char x) {
328+
long cPtr = Julia4JJNI.jl_box_uint8pointer(SWIGTYPE_p_unsigned_char.getCPtr(x));
329+
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
330+
}
331+
288332
public static SWIGTYPE_p_jl_value_t jl_box_ssavalue(long x) {
289333
long cPtr = Julia4JJNI.jl_box_ssavalue(x);
290334
return (cPtr == 0) ? null : new SWIGTYPE_p_jl_value_t(cPtr, false);
@@ -344,8 +388,21 @@ public static SWIGTYPE_p_void jl_unbox_voidpointer(SWIGTYPE_p_jl_value_t v) {
344388
return (cPtr == 0) ? null : new SWIGTYPE_p_void(cPtr, false);
345389
}
346390

391+
public static SWIGTYPE_p_unsigned_char jl_unbox_uint8pointer(SWIGTYPE_p_jl_value_t v) {
392+
long cPtr = Julia4JJNI.jl_unbox_uint8pointer(SWIGTYPE_p_jl_value_t.getCPtr(v));
393+
return (cPtr == 0) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
394+
}
395+
347396
public static int jl_get_size(SWIGTYPE_p_jl_value_t val, SWIGTYPE_p_size_t pnt) {
348397
return Julia4JJNI.jl_get_size(SWIGTYPE_p_jl_value_t.getCPtr(val), SWIGTYPE_p_size_t.getCPtr(pnt));
349398
}
350399

400+
public static String jl_unbox_string(SWIGTYPE_p_jl_value_t v) {
401+
return Julia4JJNI.jl_unbox_string(SWIGTYPE_p_jl_value_t.getCPtr(v));
402+
}
403+
404+
public static void jl_show(SWIGTYPE_p_jl_value_t v) {
405+
Julia4JJNI.jl_show(SWIGTYPE_p_jl_value_t.getCPtr(v));
406+
}
407+
351408
}

src/main/java/org/julia/jni/swig/Julia4JJNI.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public class Julia4JJNI {
3131
public final static native long jl_expand(long jarg1, long jarg2);
3232
public final static native long jl_expand_stmt(long jarg1, long jarg2);
3333
public final static native long jl_eval_string(String jarg1);
34+
public final static native long jl_apply_generic(long jarg1, long jarg2, long jarg3);
35+
public final static native long jl_invoke(long jarg1, long jarg2, long jarg3, long jarg4);
36+
public final static native int jl_invoke_api(long jarg1);
37+
public final static native long jl_call(long jarg1, long jarg2, int jarg3);
38+
public final static native long jl_call0(long jarg1);
39+
public final static native long jl_call1(long jarg1, long jarg2);
40+
public final static native long jl_call2(long jarg1, long jarg2, long jarg3);
41+
public final static native long jl_call3(long jarg1, long jarg2, long jarg3, long jarg4);
3442
public final static native long jl_new_bits(long jarg1, long jarg2);
3543
public final static native long jl_new_struct(long jarg1);
3644
public final static native long jl_new_structv(long jarg1, long jarg2, long jarg3);
@@ -67,6 +75,7 @@ public class Julia4JJNI {
6775
public final static native long jl_box_float32(float jarg1);
6876
public final static native long jl_box_float64(double jarg1);
6977
public final static native long jl_box_voidpointer(long jarg1);
78+
public final static native long jl_box_uint8pointer(long jarg1);
7079
public final static native long jl_box_ssavalue(long jarg1);
7180
public final static native long jl_box_slotnumber(long jarg1);
7281
public final static native byte jl_unbox_bool(long jarg1);
@@ -81,5 +90,8 @@ public class Julia4JJNI {
8190
public final static native float jl_unbox_float32(long jarg1);
8291
public final static native double jl_unbox_float64(long jarg1);
8392
public final static native long jl_unbox_voidpointer(long jarg1);
93+
public final static native long jl_unbox_uint8pointer(long jarg1);
8494
public final static native int jl_get_size(long jarg1, long jarg2);
95+
public final static native String jl_unbox_string(long jarg1);
96+
public final static native void jl_show(long jarg1);
8597
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 4.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package org.julia.jni.swig;
10+
11+
public class SWIGTYPE_p_jl_code_instance_t {
12+
private transient long swigCPtr;
13+
14+
protected SWIGTYPE_p_jl_code_instance_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
15+
swigCPtr = cPtr;
16+
}
17+
18+
protected SWIGTYPE_p_jl_code_instance_t() {
19+
swigCPtr = 0;
20+
}
21+
22+
protected static long getCPtr(SWIGTYPE_p_jl_code_instance_t obj) {
23+
return (obj == null) ? 0 : obj.swigCPtr;
24+
}
25+
}
26+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 4.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package org.julia.jni.swig;
10+
11+
public class SWIGTYPE_p_unsigned_char {
12+
private transient long swigCPtr;
13+
14+
protected SWIGTYPE_p_unsigned_char(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
15+
swigCPtr = cPtr;
16+
}
17+
18+
protected SWIGTYPE_p_unsigned_char() {
19+
swigCPtr = 0;
20+
}
21+
22+
protected static long getCPtr(SWIGTYPE_p_unsigned_char obj) {
23+
return (obj == null) ? 0 : obj.swigCPtr;
24+
}
25+
}
26+

src/main/java/org/julia/jni/swig/julia4jJAVA_wrap.c

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
213213

214214
/* Put header files here or function declarations like below */
215215
#include "julia.h"
216+
217+
char * jl_unbox_string(jl_value_t *v) {
218+
return jl_string_data((char *)(v));
219+
}
220+
221+
void *jl_show(jl_value_t *v) {
222+
jl_static_show(jl_stdout_stream(), v);
223+
};
224+
216225

217226

218227
#ifdef __cplusplus
@@ -593,6 +602,144 @@ SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1eval_1string(JNI
593602
}
594603

595604

605+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1apply_1generic(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jlong jarg3) {
606+
jlong jresult = 0 ;
607+
jl_value_t *arg1 = (jl_value_t *) 0 ;
608+
jl_value_t **arg2 = (jl_value_t **) 0 ;
609+
uint32_t arg3 ;
610+
jl_value_t *result = 0 ;
611+
612+
(void)jenv;
613+
(void)jcls;
614+
arg1 = *(jl_value_t **)&jarg1;
615+
arg2 = *(jl_value_t ***)&jarg2;
616+
arg3 = (uint32_t)jarg3;
617+
result = (jl_value_t *)jl_apply_generic(arg1,arg2,arg3);
618+
*(jl_value_t **)&jresult = result;
619+
return jresult;
620+
}
621+
622+
623+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1invoke(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jlong jarg3, jlong jarg4) {
624+
jlong jresult = 0 ;
625+
jl_value_t *arg1 = (jl_value_t *) 0 ;
626+
jl_value_t **arg2 = (jl_value_t **) 0 ;
627+
uint32_t arg3 ;
628+
jl_method_instance_t *arg4 = (jl_method_instance_t *) 0 ;
629+
jl_value_t *result = 0 ;
630+
631+
(void)jenv;
632+
(void)jcls;
633+
arg1 = *(jl_value_t **)&jarg1;
634+
arg2 = *(jl_value_t ***)&jarg2;
635+
arg3 = (uint32_t)jarg3;
636+
arg4 = *(jl_method_instance_t **)&jarg4;
637+
result = (jl_value_t *)jl_invoke(arg1,arg2,arg3,arg4);
638+
*(jl_value_t **)&jresult = result;
639+
return jresult;
640+
}
641+
642+
643+
SWIGEXPORT jint JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1invoke_1api(JNIEnv *jenv, jclass jcls, jlong jarg1) {
644+
jint jresult = 0 ;
645+
jl_code_instance_t *arg1 = (jl_code_instance_t *) 0 ;
646+
int32_t result;
647+
648+
(void)jenv;
649+
(void)jcls;
650+
arg1 = *(jl_code_instance_t **)&jarg1;
651+
result = (int32_t)jl_invoke_api(arg1);
652+
jresult = (jint)result;
653+
return jresult;
654+
}
655+
656+
657+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1call(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jint jarg3) {
658+
jlong jresult = 0 ;
659+
jl_function_t *arg1 = (jl_function_t *) 0 ;
660+
jl_value_t **arg2 = (jl_value_t **) 0 ;
661+
int32_t arg3 ;
662+
jl_value_t *result = 0 ;
663+
664+
(void)jenv;
665+
(void)jcls;
666+
arg1 = *(jl_function_t **)&jarg1;
667+
arg2 = *(jl_value_t ***)&jarg2;
668+
arg3 = (int32_t)jarg3;
669+
result = (jl_value_t *)jl_call(arg1,arg2,arg3);
670+
*(jl_value_t **)&jresult = result;
671+
return jresult;
672+
}
673+
674+
675+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1call0(JNIEnv *jenv, jclass jcls, jlong jarg1) {
676+
jlong jresult = 0 ;
677+
jl_function_t *arg1 = (jl_function_t *) 0 ;
678+
jl_value_t *result = 0 ;
679+
680+
(void)jenv;
681+
(void)jcls;
682+
arg1 = *(jl_function_t **)&jarg1;
683+
result = (jl_value_t *)jl_call0(arg1);
684+
*(jl_value_t **)&jresult = result;
685+
return jresult;
686+
}
687+
688+
689+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1call1(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2) {
690+
jlong jresult = 0 ;
691+
jl_function_t *arg1 = (jl_function_t *) 0 ;
692+
jl_value_t *arg2 = (jl_value_t *) 0 ;
693+
jl_value_t *result = 0 ;
694+
695+
(void)jenv;
696+
(void)jcls;
697+
arg1 = *(jl_function_t **)&jarg1;
698+
arg2 = *(jl_value_t **)&jarg2;
699+
result = (jl_value_t *)jl_call1(arg1,arg2);
700+
*(jl_value_t **)&jresult = result;
701+
return jresult;
702+
}
703+
704+
705+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1call2(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jlong jarg3) {
706+
jlong jresult = 0 ;
707+
jl_function_t *arg1 = (jl_function_t *) 0 ;
708+
jl_value_t *arg2 = (jl_value_t *) 0 ;
709+
jl_value_t *arg3 = (jl_value_t *) 0 ;
710+
jl_value_t *result = 0 ;
711+
712+
(void)jenv;
713+
(void)jcls;
714+
arg1 = *(jl_function_t **)&jarg1;
715+
arg2 = *(jl_value_t **)&jarg2;
716+
arg3 = *(jl_value_t **)&jarg3;
717+
result = (jl_value_t *)jl_call2(arg1,arg2,arg3);
718+
*(jl_value_t **)&jresult = result;
719+
return jresult;
720+
}
721+
722+
723+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1call3(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jlong jarg3, jlong jarg4) {
724+
jlong jresult = 0 ;
725+
jl_function_t *arg1 = (jl_function_t *) 0 ;
726+
jl_value_t *arg2 = (jl_value_t *) 0 ;
727+
jl_value_t *arg3 = (jl_value_t *) 0 ;
728+
jl_value_t *arg4 = (jl_value_t *) 0 ;
729+
jl_value_t *result = 0 ;
730+
731+
(void)jenv;
732+
(void)jcls;
733+
arg1 = *(jl_function_t **)&jarg1;
734+
arg2 = *(jl_value_t **)&jarg2;
735+
arg3 = *(jl_value_t **)&jarg3;
736+
arg4 = *(jl_value_t **)&jarg4;
737+
result = (jl_value_t *)jl_call3(arg1,arg2,arg3,arg4);
738+
*(jl_value_t **)&jresult = result;
739+
return jresult;
740+
}
741+
742+
596743
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1new_1bits(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2) {
597744
jlong jresult = 0 ;
598745
jl_value_t *arg1 = (jl_value_t *) 0 ;
@@ -1152,6 +1299,20 @@ SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1box_1voidpointer
11521299
}
11531300

11541301

1302+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1box_1uint8pointer(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1303+
jlong jresult = 0 ;
1304+
uint8_t *arg1 = (uint8_t *) 0 ;
1305+
jl_value_t *result = 0 ;
1306+
1307+
(void)jenv;
1308+
(void)jcls;
1309+
arg1 = *(uint8_t **)&jarg1;
1310+
result = (jl_value_t *)jl_box_uint8pointer(arg1);
1311+
*(jl_value_t **)&jresult = result;
1312+
return jresult;
1313+
}
1314+
1315+
11551316
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1box_1ssavalue(JNIEnv *jenv, jclass jcls, jlong jarg1) {
11561317
jlong jresult = 0 ;
11571318
size_t arg1 ;
@@ -1365,6 +1526,20 @@ SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1unbox_1voidpoint
13651526
}
13661527

13671528

1529+
SWIGEXPORT jlong JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1unbox_1uint8pointer(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1530+
jlong jresult = 0 ;
1531+
jl_value_t *arg1 = (jl_value_t *) 0 ;
1532+
uint8_t *result = 0 ;
1533+
1534+
(void)jenv;
1535+
(void)jcls;
1536+
arg1 = *(jl_value_t **)&jarg1;
1537+
result = (uint8_t *)jl_unbox_uint8pointer(arg1);
1538+
*(uint8_t **)&jresult = result;
1539+
return jresult;
1540+
}
1541+
1542+
13681543
SWIGEXPORT jint JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1get_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2) {
13691544
jint jresult = 0 ;
13701545
jl_value_t *arg1 = (jl_value_t *) 0 ;
@@ -1381,6 +1556,30 @@ SWIGEXPORT jint JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1get_1size(JNIEnv
13811556
}
13821557

13831558

1559+
SWIGEXPORT jstring JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1unbox_1string(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1560+
jstring jresult = 0 ;
1561+
jl_value_t *arg1 = (jl_value_t *) 0 ;
1562+
char *result = 0 ;
1563+
1564+
(void)jenv;
1565+
(void)jcls;
1566+
arg1 = *(jl_value_t **)&jarg1;
1567+
result = (char *)jl_unbox_string(arg1);
1568+
if (result) jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
1569+
return jresult;
1570+
}
1571+
1572+
1573+
SWIGEXPORT void JNICALL Java_org_julia_jni_swig_Julia4JJNI_jl_1show(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1574+
jl_value_t *arg1 = (jl_value_t *) 0 ;
1575+
1576+
(void)jenv;
1577+
(void)jcls;
1578+
arg1 = *(jl_value_t **)&jarg1;
1579+
jl_show(arg1);
1580+
}
1581+
1582+
13841583
#ifdef __cplusplus
13851584
}
13861585
#endif

0 commit comments

Comments
 (0)