[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cinvoke-svn] r71 - in trunk/cinvoke/bindings/java: . org/cinvoke
From: |
will |
Subject: |
[cinvoke-svn] r71 - in trunk/cinvoke/bindings/java: . org/cinvoke |
Date: |
4 Jul 2006 12:07:25 -0400 |
Author: will
Date: 2006-07-04 12:07:24 -0400 (Tue, 04 Jul 2006)
New Revision: 71
Modified:
trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java
trunk/cinvoke/bindings/java/org/cinvoke/Natives.java
trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp
trunk/cinvoke/bindings/java/org_cinvoke_Natives.h
Log:
more marshalling
Modified: trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java
===================================================================
--- trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java 2006-07-04
05:28:22 UTC (rev 70)
+++ trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java 2006-07-04
16:07:24 UTC (rev 71)
@@ -293,11 +293,37 @@
return ret;
}
- private void marshalStruct(long outp, Object s, Class type) {
+ private long marshalStruct(long outp, Object s, Class cls) {
if (s == null)
throw new CInvokeError("Invalid null value");
- // XXX
- // thought: have writeValue return int == size written
+
+ long st = getNativeStruct(cls).st;
+ Field[] fields = cls.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ Field fld = fields[i];
+ Class tcls = fld.getType();
+ Object val;
+ try {
+ val = fld.get(s);
+ } catch (IllegalAccessException iae) {
+ throw new CInvokeError("field access failed");
+ }
+ int type = gettypeint(tcls, false);
+ if (type == -999) {
+ long p = Natives.getMemberPtrStruct(_ctx, st,
+ outp, fld.getName());
+ if (p == 0) fail();
+ marshalStruct(p, val, tcls);
+ } else {
+ if (Natives.setMemberValueStruct(_ctx, st, outp,
+ fld.getName(), val, type) == 0)
+ fail();
+ }
+ }
+
+ int sz = Natives.sizeStruct(_ctx, st);
+ if (sz == -1) fail();
+ return outp + sz;
}
private Object marshalBasic(Object o, Class cls) {
@@ -327,8 +353,7 @@
if (val == null) return new Ptr(0);
int numels = Array.getLength(val);
- int elsize = sizeof(eltype);
- int len = numels * elsize;
+ int len = numels * sizeof(eltype);
long ret = Natives.alloc(len);
if (ret == 0)
@@ -346,18 +371,17 @@
for (int i = 0; i < numels; i++) {
Object o = Array.get(val, i);
if (strct)
- marshalStruct(r, o, eltype);
+ r = marshalStruct(r, o, eltype);
else if (string)
- Natives.writeValue(r, marshalString((String)o),
itype);
+ r = Natives.writeValue(r,
marshalString((String)o), itype);
else
- Natives.writeValue(r, marshalBasic(o, eltype),
itype);
- r += elsize;
+ r = Natives.writeValue(r, marshalBasic(o,
eltype), itype);
}
return new Ptr(ret);
}
- private void unmarshalArray(Ptr ptr, Object[] arr, Class type) {
+ private void unmarshalArray(Ptr ptr, Object arr, Class type) {
if (ptr.longValue() == 0)
throw new CInvokeError("Reading array from null
pointer");
// XXX
@@ -419,11 +443,11 @@
if (type.isInterface())
throw new CInvokeError("Arrays of callbacks not
supported");
- Object[] ret = (Object[])Array.newInstance(type, num);
+ Object ret = Array.newInstance(type, num);
unmarshalArray(ptr, ret, type);
- return ret;
+ return (Object[])ret;
}
public int sizeof(Class type) {
int itype = gettypeint(type, false);
Modified: trunk/cinvoke/bindings/java/org/cinvoke/Natives.java
===================================================================
--- trunk/cinvoke/bindings/java/org/cinvoke/Natives.java 2006-07-04
05:28:22 UTC (rev 70)
+++ trunk/cinvoke/bindings/java/org/cinvoke/Natives.java 2006-07-04
16:07:24 UTC (rev 71)
@@ -24,12 +24,14 @@
public static native long alloc(int sz);
public static native void free(long m);
public static native int sizeofBasic(int type);
- public static native void writeValue(long m, Object val, int type);
+ public static native long writeValue(long m, Object val, int type);
public static native Object readValue(long m, Class cls, int type);
public static native int setMemberValueStruct(long ctx, long strct,
long m, String name, Object val, int type);
public static native Object getMemberValueStruct(long ctx, long strct,
long m, String name, Class cls, int type);
+ public static native long getMemberPtrStruct(long ctx, long strct,
+ long m, String name);
public static native int finishStruct(long ctx, long strct);
public static native int sizeStruct(long ctx, long strct);
public static native int deleteStruct(long ctx, long strct);
Modified: trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp
===================================================================
--- trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp 2006-07-04 05:28:22 UTC
(rev 70)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp 2006-07-04 16:07:24 UTC
(rev 71)
@@ -192,10 +192,10 @@
void *ptr = (void *)p;
free(ptr);
}
-JNIEXPORT void JNICALL Java_org_cinvoke_Natives_writeValue(
+JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_writeValue(
JNIEnv *env, jclass, jlong p, jobject val, jint type) {
jclass cls = env->GetObjectClass(val);
- if (!cls) return;
+ if (!cls) return 0;
jmethodID meth;
jbyte b; jshort s; jint i; jlong l; jfloat f; jdouble d;
@@ -203,13 +203,13 @@
switch (type) {
case CINV_T_CHAR:
meth = env->GetMethodID(cls, "byteValue", "()B");
- if (!meth) return;
+ if (!meth) return 0;
b = env->CallByteMethod(val, meth);
break;
case CINV_T_SHORT:
case T_JINT:
meth = env->GetMethodID(cls, "intValue", "()I");
- if (!meth) return;
+ if (!meth) return 0;
i = env->CallIntMethod(val, meth);
break;
case CINV_T_INT:
@@ -218,27 +218,27 @@
case CINV_T_PTR:
case T_JLONG:
meth = env->GetMethodID(cls, "longValue", "()J");
- if (!meth) return;
+ if (!meth) return 0;
l = env->CallLongMethod(val, meth);
break;
case CINV_T_FLOAT:
meth = env->GetMethodID(cls, "floatValue", "()F");
- if (!meth) return;
+ if (!meth) return 0;
f = env->CallFloatMethod(val, meth);
break;
case CINV_T_DOUBLE:
meth = env->GetMethodID(cls, "doubleValue", "()D");
- if (!meth) return;
+ if (!meth) return 0;
d = env->CallDoubleMethod(val, meth);
break;
case T_JSHORT:
meth = env->GetMethodID(cls, "shortValue", "()S");
- if (!meth) return;
+ if (!meth) return 0;
s = env->CallShortMethod(val, meth);
break;
}
- if (env->ExceptionOccurred()) return;
+ if (env->ExceptionOccurred()) return 0;
switch (type) {
case CINV_T_CHAR:
@@ -275,6 +275,10 @@
*(cinv_int64_t *)p = (cinv_int64_t)l;
break;
}
+
+ char *ptr = (char *)p;
+ ptr += Java_org_cinvoke_Natives_sizeofBasic(env, NULL, type);
+ return (jlong)ptr;
}
JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_readValue(
JNIEnv *env, jclass, jlong p, jclass cls, jint type) {
@@ -384,6 +388,21 @@
return Java_org_cinvoke_Natives_readValue(env, NULL, (jlong)p, cls,
type);
}
+JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_getMemberPtrStruct(
+ JNIEnv *env, jclass, jlong c, jlong s, jlong i, jstring name) {
+ CInvContext *ctx = (CInvContext *)c;
+ CInvStructure *st = (CInvStructure *)s;
+ void *inst = (void *)i;
+ const char *chrs = env->GetStringUTFChars(name, NULL);
+ if (chrs == NULL) return 0;
+
+ void *p = cinv_structure_instance_getvalue(ctx, st, inst, chrs);
+ if (p == NULL) return 0;
+
+ env->ReleaseStringUTFChars(name, chrs);
+
+ return (jlong)p;
+}
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_finishStruct(
JNIEnv *env, jclass, jlong c, jlong s) {
CInvContext *ctx = (CInvContext *)c;
Modified: trunk/cinvoke/bindings/java/org_cinvoke_Natives.h
===================================================================
--- trunk/cinvoke/bindings/java/org_cinvoke_Natives.h 2006-07-04 05:28:22 UTC
(rev 70)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.h 2006-07-04 16:07:24 UTC
(rev 71)
@@ -25,10 +25,11 @@
JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_alloc (JNIEnv *env, jclass,
jint);
JNIEXPORT void JNICALL Java_org_cinvoke_Natives_free (JNIEnv *env, jclass,
jlong);
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_sizeofBasic (JNIEnv *env,
jclass, jint);
-JNIEXPORT void JNICALL Java_org_cinvoke_Natives_writeValue (JNIEnv *env,
jclass, jlong, jobject, jint);
+JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_writeValue (JNIEnv *env,
jclass, jlong, jobject, jint);
JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_readValue (JNIEnv *env,
jclass, jlong, jclass, jint);
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_setMemberValueStruct (JNIEnv
*env, jclass, jlong, jlong, jlong, jstring, jobject, jint);
JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_getMemberValueStruct
(JNIEnv *env, jclass, jlong, jlong, jlong, jstring, jclass, jint);
+JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_getMemberPtrStruct (JNIEnv
*env, jclass, jlong, jlong, jlong, jstring);
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_finishStruct (JNIEnv *env,
jclass, jlong, jlong);
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_sizeStruct (JNIEnv *env,
jclass, jlong, jlong);
JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteStruct (JNIEnv *env,
jclass, jlong, jlong);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cinvoke-svn] r71 - in trunk/cinvoke/bindings/java: . org/cinvoke,
will <=