cinvoke-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-svn] r73 - in trunk/cinvoke/bindings/java: . org/cinvoke


From: will
Subject: [cinvoke-svn] r73 - in trunk/cinvoke/bindings/java: . org/cinvoke
Date: 5 Jul 2006 22:00:09 -0400

Author: will
Date: 2006-07-05 22:00:09 -0400 (Wed, 05 Jul 2006)
New Revision: 73

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 marshaling


Modified: trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java
===================================================================
--- trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java      2006-07-05 
23:44:56 UTC (rev 72)
+++ trunk/cinvoke/bindings/java/org/cinvoke/CInvProxy.java      2006-07-06 
02:00:09 UTC (rev 73)
@@ -267,7 +267,7 @@
                                                long tmp = l;
                                                int len = 
Array.getLength(rawparams[i]);
                                                for (int j = 0; j < len; j++) {
-                                                       Natives.free(tmp);
+                                                       
Natives.freeIndirect(tmp);
                                                        tmp += incr;
                                                }
                                        }
@@ -281,18 +281,27 @@
                }
        }
 
+       private Object unmarshalString(long p) {
+               if (p == 0) return null;
+               if (_encoding == CInvoke.ENC.UNICODE)
+                       return Natives.ptrToStringUnicode(p, -1);
+               else
+                       return Natives.ptrToStringUTF8(p);
+       }
+
        private Object unmarshalReturnValue(Object ret, Class type) {
                if (type.equals(String.class)) {
                        Ptr p = (Ptr)ret;
-                       if (p.longValue() == 0) return null;
-                       if (_encoding == CInvoke.ENC.UNICODE)
-                               return 
Natives.ptrToStringUnicode(p.longValue(), -1);
-                       else
-                               return Natives.ptrToStringUTF8(p.longValue());
+                       return unmarshalString(p.longValue());
                } else
                        return ret;
        }
 
+       private Object unmarshalStruct(long p, Class eltype) {
+               // XXX
+               return null;
+       }
+
        private long marshalStruct(long outp, Object s, Class cls) {
                if (s == null)
                        throw new CInvokeError("Invalid null value");
@@ -309,12 +318,12 @@
                                throw new CInvokeError("field access failed");
                        }
                        int type = gettypeint(tcls, false);
-                       if (type == -999) {
+                       if (type == -999) { // XXX fix all these
                                long p = Natives.getMemberPtrStruct(_ctx, st,
                                        outp, fld.getName());
                                if (p == 0) fail();
                                marshalStruct(p, val, tcls);
-                       } else {
+                       } else { // XXX string struct members
                                if (Natives.setMemberValueStruct(_ctx, st, outp,
                                        fld.getName(), val, type) == 0)
                                        fail();
@@ -381,10 +390,33 @@
                return new Ptr(ret);
        }
 
-       private void unmarshalArray(Ptr ptr, Object arr, Class type) {
-               if (ptr.longValue() == 0)
+       private void unmarshalArray(long ptr, Object arr, Class eltype) {
+               if (ptr == 0)
                        throw new CInvokeError("Reading array from null 
pointer");
-               // XXX
+               int numels = Array.getLength(arr);
+               
+               boolean string = false;
+               boolean strct = false;
+               int itype = gettypeint(eltype, false);
+               if (itype == -999)
+                       strct = true;
+               if (eltype.equals(String.class))
+                       string = true;
+               int elsize = sizeof(eltype);
+
+               long p = ptr;
+               for (int i = 0; i < numels; i++) {
+                       Object toset;
+                       if (strct)
+                               toset = unmarshalStruct(p, eltype);
+                       else if (string)
+                               toset = unmarshalString(p);
+                       else
+                               toset = Natives.readValue(p, eltype, itype);
+                       Array.set(arr, i, toset);
+
+                       p += elsize;
+               }
        }
 
        private NativeStruct getNativeStruct(Class cls) {
@@ -439,13 +471,13 @@
                else
                        return Natives.ptrToStringUTF8(ptr.longValue());
        }
-       public Object[] ptrToArray(Ptr ptr, Class type, int num) {
-               if (type.isInterface())
+       public Object[] ptrToArray(Ptr ptr, Class eltype, int num) {
+               if (eltype.isInterface())
                        throw new CInvokeError("Arrays of callbacks not 
supported");
 
-               Object ret = Array.newInstance(type, num);
+               Object ret = Array.newInstance(eltype, num);
 
-               unmarshalArray(ptr, ret, type);
+               unmarshalArray(ptr.longValue(), ret, eltype);
 
                return (Object[])ret;
        }

Modified: trunk/cinvoke/bindings/java/org/cinvoke/Natives.java
===================================================================
--- trunk/cinvoke/bindings/java/org/cinvoke/Natives.java        2006-07-05 
23:44:56 UTC (rev 72)
+++ trunk/cinvoke/bindings/java/org/cinvoke/Natives.java        2006-07-06 
02:00:09 UTC (rev 73)
@@ -23,6 +23,7 @@
                String name, long type);
        public static native long alloc(int sz);
        public static native void free(long m);
+       public static native void freeIndirect(long mm);
        public static native int sizeofBasic(int type);
        public static native long writeValue(long m, Object val, int type);
        public static native Object readValue(long m, Class cls, int type);

Modified: trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp
===================================================================
--- trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp 2006-07-05 23:44:56 UTC 
(rev 72)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp 2006-07-06 02:00:09 UTC 
(rev 73)
@@ -192,6 +192,11 @@
        void *ptr = (void *)p;
        free(ptr);
 }
+JNIEXPORT void JNICALL Java_org_cinvoke_Natives_freeIndirect(
+       JNIEnv *env, jclass, jlong pp) {
+       void **ptr = (void **)pp;
+       free(*ptr);
+}
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_writeValue(
        JNIEnv *env, jclass, jlong p, jobject val, jint type) {
        jclass cls = env->GetObjectClass(val);

Modified: trunk/cinvoke/bindings/java/org_cinvoke_Natives.h
===================================================================
--- trunk/cinvoke/bindings/java/org_cinvoke_Natives.h   2006-07-05 23:44:56 UTC 
(rev 72)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.h   2006-07-06 02:00:09 UTC 
(rev 73)
@@ -24,6 +24,7 @@
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_addStructMemberStruct (JNIEnv 
*env, jclass, jlong, jlong, jstring, jlong);
 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 void JNICALL Java_org_cinvoke_Natives_freeIndirect (JNIEnv *env, 
jclass, jlong);
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_sizeofBasic (JNIEnv *env, 
jclass, 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);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]