comparison java/jdc/org_dyncall_DC.c @ 21:40a2c4198016

- working jdc (but with memleaks, currently) - added example
author cslag
date Wed, 30 Mar 2016 23:40:52 +0200
parents 77ca609422f1
children 4ee8d6aa7721
comparison
equal deleted inserted replaced
20:77ca609422f1 21:40a2c4198016
8 //@@@ free 8 //@@@ free
9 } 9 }
10 10
11 jlong JNICALL Java_org_dyncall_DC_load(JNIEnv *pEnv, jclass clazz, jstring s) 11 jlong JNICALL Java_org_dyncall_DC_load(JNIEnv *pEnv, jclass clazz, jstring s)
12 { 12 {
13 return (jlong)dlLoadLibrary((const char*)s); 13 jlong l = 0;
14 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
15 if(sz != NULL) {
16 l = (jlong)dlLoadLibrary(sz);
17 (*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
14 //@@@ free 18 //@@@ free
19 }
20 return l;
15 } 21 }
16 22
17 jlong JNICALL Java_org_dyncall_DC_find(JNIEnv *pEnv, jclass clazz, jlong libhandle, jstring s) 23 jlong JNICALL Java_org_dyncall_DC_find(JNIEnv *pEnv, jclass clazz, jlong libhandle, jstring s)
18 { 24 {
19 return (jlong)dlFindSymbol((DLLib*)libhandle, (const char*)s); 25 jlong l = 0;
26 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
27 if(sz != NULL) {
28 l = (jlong)dlFindSymbol((DLLib*)libhandle, sz);
29 (*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
30 }
31 return l;
20 } 32 }
21 33
22 //jint JNICALL Java_org_dyncall_DC_symsCount(JNIEnv *pEnv, jclass clazz, jlong symshandle) 34 //jint JNICALL Java_org_dyncall_DC_symsCount(JNIEnv *pEnv, jclass clazz, jlong symshandle)
23 //{ 35 //{
24 // return dlSymsCount((DLSyms*)symshandle); 36 // return dlSymsCount((DLSyms*)symshandle);
29 // return dlSymsName((DLSyms*)symshandle, i); 41 // return dlSymsName((DLSyms*)symshandle, i);
30 //} 42 //}
31 43
32 void JNICALL Java_org_dyncall_DC_mode(JNIEnv *pEnv, jclass clazz, jlong vm, jint i) 44 void JNICALL Java_org_dyncall_DC_mode(JNIEnv *pEnv, jclass clazz, jlong vm, jint i)
33 { 45 {
34 dcMode((DCCallVM*)vm, i); 46 dcMode((DCCallVM*)vm, i);//@@@test
35 } 47 }
36 48
37 void JNICALL Java_org_dyncall_DC_reset(JNIEnv *pEnv, jclass clazz, jlong vm) 49 void JNICALL Java_org_dyncall_DC_reset(JNIEnv *pEnv, jclass clazz, jlong vm)
38 { 50 {
39 dcReset((DCCallVM*)vm); 51 dcReset((DCCallVM*)vm);
52 //@@@add cleanup code here for temporary memory held by jni
40 } 53 }
41 54
42 void JNICALL Java_org_dyncall_DC_argBool(JNIEnv *pEnv, jclass clazz, jlong vm, jboolean b) 55 void JNICALL Java_org_dyncall_DC_argBool(JNIEnv *pEnv, jclass clazz, jlong vm, jboolean b)
43 { 56 {
44 dcArgBool((DCCallVM*)vm, b); 57 dcArgBool((DCCallVM*)vm, b);//@@@test
45 } 58 }
46 59
47 void JNICALL Java_org_dyncall_DC_argChar(JNIEnv *pEnv, jclass clazz, jlong vm, jbyte b) 60 void JNICALL Java_org_dyncall_DC_argChar(JNIEnv *pEnv, jclass clazz, jlong vm, jbyte b)
48 { 61 {
49 dcArgChar((DCCallVM*)vm, b); 62 dcArgChar((DCCallVM*)vm, b);//@@@test
50 } 63 }
51 64
52 void JNICALL Java_org_dyncall_DC_argShort(JNIEnv *pEnv, jclass clazz, jlong vm, jshort s) 65 void JNICALL Java_org_dyncall_DC_argShort(JNIEnv *pEnv, jclass clazz, jlong vm, jshort s)
53 { 66 {
54 dcArgShort((DCCallVM*)vm, s); 67 dcArgShort((DCCallVM*)vm, s);//@@@test
55 } 68 }
56 69
57 void JNICALL Java_org_dyncall_DC_argInt(JNIEnv *pEnv, jclass clazz, jlong vm, jint i) 70 void JNICALL Java_org_dyncall_DC_argInt(JNIEnv *pEnv, jclass clazz, jlong vm, jint i)
58 { 71 {
59 dcArgInt((DCCallVM*)vm, i); 72 dcArgInt((DCCallVM*)vm, i);//@@@test
60 } 73 }
61 74
62 void JNICALL Java_org_dyncall_DC_argLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) 75 void JNICALL Java_org_dyncall_DC_argLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
63 { 76 {
64 dcArgLong((DCCallVM*)vm, l); 77 dcArgLong((DCCallVM*)vm, l);//@@@test
65 } 78 }
66 79
67 void JNICALL Java_org_dyncall_DC_argLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) 80 void JNICALL Java_org_dyncall_DC_argLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
68 { 81 {
69 dcArgLongLong((DCCallVM*)vm, l); 82 dcArgLongLong((DCCallVM*)vm, l);//@@@test
70 } 83 }
71 84
72 void JNICALL Java_org_dyncall_DC_argFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jfloat f) 85 void JNICALL Java_org_dyncall_DC_argFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jfloat f)
73 { 86 {
74 dcArgFloat((DCCallVM*)vm, f); 87 dcArgFloat((DCCallVM*)vm, f);
75 } 88 }
76 89
77 void JNICALL Java_org_dyncall_DC_argDouble(JNIEnv *pEnv, jclass clazz, jlong vm, jdouble d) 90 void JNICALL Java_org_dyncall_DC_argDouble(JNIEnv *pEnv, jclass clazz, jlong vm, jdouble d)
78 { 91 {
79 dcArgDouble((DCCallVM*)vm, d); 92 dcArgDouble((DCCallVM*)vm, d);
80 } 93 }
81 94
82 void JNICALL Java_org_dyncall_DC_argPointer__JJ(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l) 95 void JNICALL Java_org_dyncall_DC_argPointer__JJ(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
83 { 96 {
84 dcArgPointer((DCCallVM*)vm, (DCpointer)l); 97 dcArgPointer((DCCallVM*)vm, (DCpointer)l);//@@@test
85 } 98 }
86 99
87 void JNICALL Java_org_dyncall_DC_argPointer__JLjava_lang_Object_2(JNIEnv *pEnv, jclass clazz, jlong vm, jobject o) 100 void JNICALL Java_org_dyncall_DC_argPointer__JLjava_lang_Object_2(JNIEnv *pEnv, jclass clazz, jlong vm, jobject o)
88 { 101 {
89 dcArgPointer((DCCallVM*)vm, (DCpointer)o); 102 dcArgPointer((DCCallVM*)vm, (DCpointer)o);//@@@test
90 } 103 }
91 104
92 void JNICALL Java_org_dyncall_DC_argString(JNIEnv *pEnv, jclass clazz, jlong vm, jstring s) 105 void JNICALL Java_org_dyncall_DC_argString(JNIEnv *pEnv, jclass clazz, jlong vm, jstring s)
93 { 106 {
94 dcArgPointer((DCCallVM*)vm, (DCpointer)s); 107 const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
108 if(sz != NULL) {
109 dcArgPointer((DCCallVM*)vm, (DCpointer)sz);
110 //(*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
111 //@@@ free this string when vm is destroyed, reset
112 }
95 } 113 }
96 114
97 void JNICALL Java_org_dyncall_DC_callVoid (JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 115 void JNICALL Java_org_dyncall_DC_callVoid (JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
98 { 116 {
99 dcCallVoid((DCCallVM*)vm, (DCpointer)target); 117 dcCallVoid((DCCallVM*)vm, (DCpointer)target);//@@@test
100 } 118 }
101 119
102 jboolean JNICALL Java_org_dyncall_DC_callBool(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 120 jboolean JNICALL Java_org_dyncall_DC_callBool(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
103 { 121 {
104 return dcCallBool((DCCallVM*)vm, (DCpointer)target); 122 return dcCallBool((DCCallVM*)vm, (DCpointer)target);//@@@test
105 } 123 }
106 124
107 jbyte JNICALL Java_org_dyncall_DC_callChar(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 125 jbyte JNICALL Java_org_dyncall_DC_callChar(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
108 { 126 {
109 return dcCallChar((DCCallVM*)vm, (DCpointer)target); 127 return dcCallChar((DCCallVM*)vm, (DCpointer)target);//@@@test
110 } 128 }
111 129
112 jshort JNICALL Java_org_dyncall_DC_callShort(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 130 jshort JNICALL Java_org_dyncall_DC_callShort(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
113 { 131 {
114 return dcCallShort((DCCallVM*)vm, (DCpointer)target); 132 return dcCallShort((DCCallVM*)vm, (DCpointer)target);//@@@test
115 } 133 }
116 134
117 jint JNICALL Java_org_dyncall_DC_callInt(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 135 jint JNICALL Java_org_dyncall_DC_callInt(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
118 { 136 {
119 return dcCallInt((DCCallVM*)vm, (DCpointer)target); 137 return dcCallInt((DCCallVM*)vm, (DCpointer)target);//@@@test
120 } 138 }
121 139
122 jlong JNICALL Java_org_dyncall_DC_callLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 140 jlong JNICALL Java_org_dyncall_DC_callLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
123 { 141 {
124 return dcCallLong((DCCallVM*)vm, (DCpointer)target); 142 return dcCallLong((DCCallVM*)vm, (DCpointer)target);//@@@test
125 } 143 }
126 144
127 jlong JNICALL Java_org_dyncall_DC_callLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 145 jlong JNICALL Java_org_dyncall_DC_callLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
128 { 146 {
129 return dcCallLongLong((DCCallVM*)vm, (DCpointer)target); 147 return dcCallLongLong((DCCallVM*)vm, (DCpointer)target);//@@@test
130 } 148 }
131 149
132 jfloat JNICALL Java_org_dyncall_DC_callFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 150 jfloat JNICALL Java_org_dyncall_DC_callFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
133 { 151 {
134 return dcCallFloat((DCCallVM*)vm, (DCpointer)target); 152 return dcCallFloat((DCCallVM*)vm, (DCpointer)target);
139 return dcCallDouble((DCCallVM*)vm, (DCpointer)target); 157 return dcCallDouble((DCCallVM*)vm, (DCpointer)target);
140 } 158 }
141 159
142 jlong JNICALL Java_org_dyncall_DC_callPointer(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 160 jlong JNICALL Java_org_dyncall_DC_callPointer(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
143 { 161 {
144 return (jlong)dcCallPointer((DCCallVM*)vm, (DCpointer)target); 162 return (jlong)dcCallPointer((DCCallVM*)vm, (DCpointer)target);//@@@test
145 } 163 }
146 164
147 jstring JNICALL Java_org_dyncall_DC_callString(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target) 165 jstring JNICALL Java_org_dyncall_DC_callString(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
148 { 166 {
149 return dcCallPointer((DCCallVM*)vm, (DCpointer)target); 167 return (*pEnv)->NewStringUTF(pEnv, dcCallPointer((DCCallVM*)vm, (DCpointer)target));//@@@test
150 } 168 }
151 169
152 jint JNICALL Java_org_dyncall_DC_getError(JNIEnv *pEnv, jclass clazz, jlong vm) 170 jint JNICALL Java_org_dyncall_DC_getError(JNIEnv *pEnv, jclass clazz, jlong vm)
153 { 171 {
154 return dcGetError((DCCallVM*)vm); 172 return dcGetError((DCCallVM*)vm);//@@@test
155 } 173 }
156 174