Mercurial > pub > dyncall > bindings
annotate java/jdc/org_dyncall_DC.c @ 22:4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
- java binding examples
author | cslag |
---|---|
date | Sat, 09 Apr 2016 18:18:34 -0500 |
parents | 40a2c4198016 |
children | 87fd9f34eaa0 |
rev | line source |
---|---|
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
1 #include <stdlib.h> |
0 | 2 #include "org_dyncall_DC.h" |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
3 #include "dyncall.h" |
20 | 4 #include "dynload.h" |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
5 |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
6 // Bookkeping to clean up on reset. |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
7 static int gc_snum = 0; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
8 static jobject* gc_jstr = NULL; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
9 static const char** gc_cstr = NULL; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
10 static void cleanupHeldStrings(JNIEnv *pEnv) |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
11 { |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
12 for(int i=0; i<gc_snum; ++i) |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
13 (*pEnv)->ReleaseStringUTFChars(pEnv, gc_jstr[i], gc_cstr[i]); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
14 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
15 free(gc_jstr); gc_jstr = NULL; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
16 free(gc_cstr); gc_cstr = NULL; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
17 gc_snum = 0; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
18 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
19 } |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
20 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
21 |
20 | 22 jlong JNICALL Java_org_dyncall_DC_newCallVM(JNIEnv *pEnv, jclass clazz, jint size) |
0 | 23 { |
20 | 24 return (jlong)dcNewCallVM(size); |
0 | 25 } |
26 | |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
27 void JNICALL Java_org_dyncall_DC_freeCallVM(JNIEnv *pEnv, jclass clazz, jlong vm) |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
28 { |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
29 cleanupHeldStrings(pEnv); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
30 dcFree((DCCallVM*)vm); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
31 } |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
32 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
33 jlong JNICALL Java_org_dyncall_DC_loadLibrary(JNIEnv *pEnv, jclass clazz, jstring s) |
0 | 34 { |
21 | 35 jlong l = 0; |
36 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL); | |
37 if(sz != NULL) { | |
38 l = (jlong)dlLoadLibrary(sz); | |
39 (*pEnv)->ReleaseStringUTFChars(pEnv, s, sz); | |
40 } | |
41 return l; | |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
42 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
43 |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
44 void JNICALL Java_org_dyncall_DC_freeLibrary(JNIEnv *pEnv, jclass clazz, jlong libhandle) |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
45 { |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
46 dlFreeLibrary((DLLib*)libhandle); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
47 } |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
48 |
20 | 49 jlong JNICALL Java_org_dyncall_DC_find(JNIEnv *pEnv, jclass clazz, jlong libhandle, jstring s) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
50 { |
21 | 51 jlong l = 0; |
52 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL); | |
53 if(sz != NULL) { | |
54 l = (jlong)dlFindSymbol((DLLib*)libhandle, sz); | |
55 (*pEnv)->ReleaseStringUTFChars(pEnv, s, sz); | |
56 } | |
57 return l; | |
0 | 58 } |
59 | |
20 | 60 //jint JNICALL Java_org_dyncall_DC_symsCount(JNIEnv *pEnv, jclass clazz, jlong symshandle) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
61 //{ |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
62 // return dlSymsCount((DLSyms*)symshandle); |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
63 //} |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
64 |
20 | 65 //jstring JNICALL Java_org_dyncall_DC_symsName(JNIEnv *pEnv, jclass clazz, jlong symshandle, jint i) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
66 //{ |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
67 // return dlSymsName((DLSyms*)symshandle, i); |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
68 //} |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
69 |
20 | 70 void JNICALL Java_org_dyncall_DC_mode(JNIEnv *pEnv, jclass clazz, jlong vm, jint i) |
0 | 71 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
72 dcMode((DCCallVM*)vm, i); |
0 | 73 } |
74 | |
20 | 75 void JNICALL Java_org_dyncall_DC_reset(JNIEnv *pEnv, jclass clazz, jlong vm) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
76 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
77 cleanupHeldStrings(pEnv); |
20 | 78 dcReset((DCCallVM*)vm); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
79 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
80 |
20 | 81 void JNICALL Java_org_dyncall_DC_argBool(JNIEnv *pEnv, jclass clazz, jlong vm, jboolean b) |
0 | 82 { |
21 | 83 dcArgBool((DCCallVM*)vm, b);//@@@test |
0 | 84 } |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
85 |
20 | 86 void JNICALL Java_org_dyncall_DC_argChar(JNIEnv *pEnv, jclass clazz, jlong vm, jbyte b) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
87 { |
21 | 88 dcArgChar((DCCallVM*)vm, b);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
89 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
90 |
20 | 91 void JNICALL Java_org_dyncall_DC_argShort(JNIEnv *pEnv, jclass clazz, jlong vm, jshort s) |
0 | 92 { |
21 | 93 dcArgShort((DCCallVM*)vm, s);//@@@test |
0 | 94 } |
95 | |
20 | 96 void JNICALL Java_org_dyncall_DC_argInt(JNIEnv *pEnv, jclass clazz, jlong vm, jint i) |
0 | 97 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
98 dcArgInt((DCCallVM*)vm, i); |
0 | 99 } |
100 | |
20 | 101 void JNICALL Java_org_dyncall_DC_argLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) |
0 | 102 { |
21 | 103 dcArgLong((DCCallVM*)vm, l);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
104 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
105 |
20 | 106 void JNICALL Java_org_dyncall_DC_argLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
107 { |
21 | 108 dcArgLongLong((DCCallVM*)vm, l);//@@@test |
0 | 109 } |
110 | |
20 | 111 void JNICALL Java_org_dyncall_DC_argFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jfloat f) |
0 | 112 { |
20 | 113 dcArgFloat((DCCallVM*)vm, f); |
0 | 114 } |
115 | |
20 | 116 void JNICALL Java_org_dyncall_DC_argDouble(JNIEnv *pEnv, jclass clazz, jlong vm, jdouble d) |
0 | 117 { |
21 | 118 dcArgDouble((DCCallVM*)vm, d); |
0 | 119 } |
120 | |
20 | 121 void JNICALL Java_org_dyncall_DC_argPointer__JJ(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) |
0 | 122 { |
21 | 123 dcArgPointer((DCCallVM*)vm, (DCpointer)l);//@@@test |
0 | 124 } |
125 | |
20 | 126 void JNICALL Java_org_dyncall_DC_argPointer__JLjava_lang_Object_2(JNIEnv *pEnv, jclass clazz, jlong vm, jobject o) |
0 | 127 { |
21 | 128 dcArgPointer((DCCallVM*)vm, (DCpointer)o);//@@@test |
0 | 129 } |
130 | |
20 | 131 void JNICALL Java_org_dyncall_DC_argString(JNIEnv *pEnv, jclass clazz, jlong vm, jstring s) |
0 | 132 { |
21 | 133 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL); |
134 if(sz != NULL) { | |
135 dcArgPointer((DCCallVM*)vm, (DCpointer)sz); | |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
136 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
137 // Bookkeeping, to later release on reset or destruction of vm. |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
138 gc_jstr = realloc(gc_jstr, (gc_snum+1)*sizeof(jobject)); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
139 gc_cstr = realloc(gc_cstr, (gc_snum+1)*sizeof(const char*)); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
140 gc_jstr[gc_snum] = s; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
141 gc_cstr[gc_snum] = sz; |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
142 ++gc_snum; |
21 | 143 } |
0 | 144 } |
145 | |
20 | 146 void JNICALL Java_org_dyncall_DC_callVoid (JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
0 | 147 { |
21 | 148 dcCallVoid((DCCallVM*)vm, (DCpointer)target);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
149 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
150 |
20 | 151 jboolean JNICALL Java_org_dyncall_DC_callBool(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
152 { |
21 | 153 return dcCallBool((DCCallVM*)vm, (DCpointer)target);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
154 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
155 |
20 | 156 jbyte JNICALL Java_org_dyncall_DC_callChar(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
157 { |
21 | 158 return dcCallChar((DCCallVM*)vm, (DCpointer)target);//@@@test |
0 | 159 } |
160 | |
20 | 161 jshort JNICALL Java_org_dyncall_DC_callShort(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
162 { |
21 | 163 return dcCallShort((DCCallVM*)vm, (DCpointer)target);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
164 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
165 |
20 | 166 jint JNICALL Java_org_dyncall_DC_callInt(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
0 | 167 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
168 return dcCallInt((DCCallVM*)vm, (DCpointer)target); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
169 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
170 |
20 | 171 jlong JNICALL Java_org_dyncall_DC_callLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
172 { |
21 | 173 return dcCallLong((DCCallVM*)vm, (DCpointer)target);//@@@test |
0 | 174 } |
175 | |
20 | 176 jlong JNICALL Java_org_dyncall_DC_callLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
177 { |
21 | 178 return dcCallLongLong((DCCallVM*)vm, (DCpointer)target);//@@@test |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
179 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
180 |
20 | 181 jfloat JNICALL Java_org_dyncall_DC_callFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
182 { |
20 | 183 return dcCallFloat((DCCallVM*)vm, (DCpointer)target); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
184 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
185 |
20 | 186 jdouble JNICALL Java_org_dyncall_DC_callDouble(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
187 { |
20 | 188 return dcCallDouble((DCCallVM*)vm, (DCpointer)target); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
189 } |
0 | 190 |
20 | 191 jlong JNICALL Java_org_dyncall_DC_callPointer(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
192 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
193 return (jlong)dcCallPointer((DCCallVM*)vm, (DCpointer)target); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
194 } |
0 | 195 |
20 | 196 jstring JNICALL Java_org_dyncall_DC_callString(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
197 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
198 return (*pEnv)->NewStringUTF(pEnv, dcCallPointer((DCCallVM*)vm, (DCpointer)target)); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
199 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
200 |
20 | 201 jint JNICALL Java_org_dyncall_DC_getError(JNIEnv *pEnv, jclass clazz, jlong vm) |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
202 { |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
203 return dcGetError((DCCallVM*)vm); |
18
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
204 } |
3bfef07b0cd9
- cleanup of non-working java binding, restart work, somewhat different interface
cslag
parents:
0
diff
changeset
|
205 |