diff 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
line wrap: on
line diff
--- a/java/jdc/org_dyncall_DC.c	Wed Mar 30 02:40:56 2016 +0200
+++ b/java/jdc/org_dyncall_DC.c	Wed Mar 30 23:40:52 2016 +0200
@@ -10,13 +10,25 @@
 
 jlong JNICALL Java_org_dyncall_DC_load(JNIEnv *pEnv, jclass clazz, jstring s)
 {
-	return (jlong)dlLoadLibrary((const char*)s);
+	jlong l = 0;
+	const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
+	if(sz != NULL) {
+		l = (jlong)dlLoadLibrary(sz);
+		(*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
 //@@@ free
+	}
+	return l;
 }
 
 jlong JNICALL Java_org_dyncall_DC_find(JNIEnv *pEnv, jclass clazz, jlong libhandle, jstring s)
 {
-	return (jlong)dlFindSymbol((DLLib*)libhandle, (const char*)s);
+	jlong l = 0;
+	const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
+	if(sz != NULL) {
+		l = (jlong)dlFindSymbol((DLLib*)libhandle, sz);
+		(*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
+	}
+	return l;
 }
 
 //jint JNICALL Java_org_dyncall_DC_symsCount(JNIEnv *pEnv, jclass clazz, jlong symshandle)
@@ -31,42 +43,43 @@
 
 void JNICALL Java_org_dyncall_DC_mode(JNIEnv *pEnv, jclass clazz, jlong vm, jint i)
 {
-	dcMode((DCCallVM*)vm, i);
+	dcMode((DCCallVM*)vm, i);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_reset(JNIEnv *pEnv, jclass clazz, jlong vm)
 {
 	dcReset((DCCallVM*)vm);
+//@@@add cleanup code here for temporary memory held by jni
 }
 
 void JNICALL Java_org_dyncall_DC_argBool(JNIEnv *pEnv, jclass clazz, jlong vm, jboolean b)
 {
-	dcArgBool((DCCallVM*)vm, b);
+	dcArgBool((DCCallVM*)vm, b);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argChar(JNIEnv *pEnv, jclass clazz, jlong vm, jbyte b)
 {
-	dcArgChar((DCCallVM*)vm, b);
+	dcArgChar((DCCallVM*)vm, b);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argShort(JNIEnv *pEnv, jclass clazz, jlong vm, jshort s)
 {
-	dcArgShort((DCCallVM*)vm, s);
+	dcArgShort((DCCallVM*)vm, s);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argInt(JNIEnv *pEnv, jclass clazz, jlong vm, jint i)
 {
-	dcArgInt((DCCallVM*)vm, i);
+	dcArgInt((DCCallVM*)vm, i);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
 {
-	dcArgLong((DCCallVM*)vm, l);
+	dcArgLong((DCCallVM*)vm, l);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
 {
-	dcArgLongLong((DCCallVM*)vm, l);
+	dcArgLongLong((DCCallVM*)vm, l);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jfloat f)
@@ -76,57 +89,62 @@
 
 void JNICALL Java_org_dyncall_DC_argDouble(JNIEnv *pEnv, jclass clazz, jlong vm, jdouble d)
 {
-	dcArgDouble((DCCallVM*)vm, d);	
+	dcArgDouble((DCCallVM*)vm, d);
 }
 
 void JNICALL Java_org_dyncall_DC_argPointer__JJ(JNIEnv *pEnv, jclass clazz, jlong vm, jlong l)
 {
-	dcArgPointer((DCCallVM*)vm, (DCpointer)l);
+	dcArgPointer((DCCallVM*)vm, (DCpointer)l);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argPointer__JLjava_lang_Object_2(JNIEnv *pEnv, jclass clazz, jlong vm, jobject o)
 {
-	dcArgPointer((DCCallVM*)vm, (DCpointer)o);
+	dcArgPointer((DCCallVM*)vm, (DCpointer)o);//@@@test
 }
 
 void JNICALL Java_org_dyncall_DC_argString(JNIEnv *pEnv, jclass clazz, jlong vm, jstring s)
 {
-	dcArgPointer((DCCallVM*)vm, (DCpointer)s);
+	const char *sz = (*pEnv)->GetStringUTFChars(pEnv, s, NULL);
+	if(sz != NULL) {
+		dcArgPointer((DCCallVM*)vm, (DCpointer)sz);
+		//(*pEnv)->ReleaseStringUTFChars(pEnv, s, sz);
+		//@@@ free this string when vm is destroyed, reset
+	}
 }
 
 void JNICALL Java_org_dyncall_DC_callVoid (JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	dcCallVoid((DCCallVM*)vm, (DCpointer)target);
+	dcCallVoid((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jboolean JNICALL Java_org_dyncall_DC_callBool(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallBool((DCCallVM*)vm, (DCpointer)target);
+	return dcCallBool((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jbyte JNICALL Java_org_dyncall_DC_callChar(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallChar((DCCallVM*)vm, (DCpointer)target);
+	return dcCallChar((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jshort JNICALL Java_org_dyncall_DC_callShort(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallShort((DCCallVM*)vm, (DCpointer)target);
+	return dcCallShort((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jint JNICALL Java_org_dyncall_DC_callInt(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallInt((DCCallVM*)vm, (DCpointer)target);
+	return dcCallInt((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jlong JNICALL Java_org_dyncall_DC_callLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallLong((DCCallVM*)vm, (DCpointer)target);
+	return dcCallLong((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jlong JNICALL Java_org_dyncall_DC_callLongLong(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallLongLong((DCCallVM*)vm, (DCpointer)target);
+	return dcCallLongLong((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jfloat JNICALL Java_org_dyncall_DC_callFloat(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
@@ -141,16 +159,16 @@
 
 jlong JNICALL Java_org_dyncall_DC_callPointer(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return (jlong)dcCallPointer((DCCallVM*)vm, (DCpointer)target);
+	return (jlong)dcCallPointer((DCCallVM*)vm, (DCpointer)target);//@@@test
 }
 
 jstring JNICALL Java_org_dyncall_DC_callString(JNIEnv *pEnv, jclass clazz, jlong vm, jlong target)
 {
-	return dcCallPointer((DCCallVM*)vm, (DCpointer)target);
+	return (*pEnv)->NewStringUTF(pEnv, dcCallPointer((DCCallVM*)vm, (DCpointer)target));//@@@test
 }
 
 jint JNICALL Java_org_dyncall_DC_getError(JNIEnv *pEnv, jclass clazz, jlong vm)
 {
-	return dcGetError((DCCallVM*)vm);
+	return dcGetError((DCCallVM*)vm);//@@@test
 }