cinvoke-svn
[Top][All Lists]
Advanced

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

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


From: will
Subject: [cinvoke-svn] r95 - in trunk/cinvoke: . bindings/java bindings/java/org/cinvoke
Date: 15 Jul 2006 14:45:52 -0400

Author: will
Date: 2006-07-15 14:45:44 -0400 (Sat, 15 Jul 2006)
New Revision: 95

Modified:
   trunk/cinvoke/bindings/java/Makefile.templ
   trunk/cinvoke/bindings/java/Test.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
   trunk/cinvoke/configure.pl
Log:
fixed java on macs


Modified: trunk/cinvoke/bindings/java/Makefile.templ
===================================================================
--- trunk/cinvoke/bindings/java/Makefile.templ  2006-07-15 15:36:32 UTC (rev 94)
+++ trunk/cinvoke/bindings/java/Makefile.templ  2006-07-15 18:45:44 UTC (rev 95)
@@ -1,4 +1,4 @@
-TARGET = libcinvoke_java.$DYNEXT
+TARGET = libcinvoke_java.$JNIDYNEXT
 
 all: \$(TARGET)
        javac org/cinvoke/*.java
@@ -10,13 +10,13 @@
        $CXXBUILDSHARED \$(TARGET) \$(OBJ) -L../../lib -lcinvoke
 
 \$(OBJ): \$(SRC) org_cinvoke_Natives.h
-       g++ $CFLAGS $DYNCFLAGS -I../../lib -c \$(SRC) -o \$(OBJ)
+       g++ $CFLAGS $DYNCFLAGS -I../../lib $JNIINCLUDE -c \$(SRC) -o \$(OBJ)
 
 header:
        javah org.cinvoke.Natives
 
 clean:
-       rm -f org/cinvoke/*.class *.class *.o *.so
+       rm -f org/cinvoke/*.class *.class *.o *.jnilib *.so *.dylib
 
 test:
        javac Test.java

Modified: trunk/cinvoke/bindings/java/Test.java
===================================================================
--- trunk/cinvoke/bindings/java/Test.java       2006-07-15 15:36:32 UTC (rev 94)
+++ trunk/cinvoke/bindings/java/Test.java       2006-07-15 18:45:44 UTC (rev 95)
@@ -7,7 +7,12 @@
        }
 
        public static void main(String[] args) {
-               libc c = (libc)CInvoke.load("libc.so.6", libc.class);
+               String libname;
+               if (System.getProperty("os.name").equals("Mac OS X"))
+                       libname = "libc.dylib";
+               else
+                       libname = "libc.so.6";
+               libc c = (libc)CInvoke.load(libname, libc.class);
 
                System.out.println("You entered: " + c.getpass("Enter password: 
"));
 

Modified: trunk/cinvoke/bindings/java/org/cinvoke/Natives.java
===================================================================
--- trunk/cinvoke/bindings/java/org/cinvoke/Natives.java        2006-07-15 
15:36:32 UTC (rev 94)
+++ trunk/cinvoke/bindings/java/org/cinvoke/Natives.java        2006-07-15 
18:45:44 UTC (rev 95)
@@ -53,7 +53,6 @@
                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-15 15:36:32 UTC 
(rev 94)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.cpp 2006-07-15 18:45:44 UTC 
(rev 95)
@@ -36,53 +36,61 @@
 #define T_JINT -2
 #define T_JLONG -3
 
+#ifdef __APPLE_CC__
+#define TO_PTR(jl) ((void *)(int)(jl))
+#define TO_LONG(p) ((jlong)(int)(p))
+#else
+#define TO_PTR(jl) ((void *)(jl))
+#define TO_LONG(p) ((jlong)(p))
+#endif
+
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_createContext(
        JNIEnv *env, jclass) {
-       return (jlong)cinv_context_create();
+       return TO_LONG(cinv_context_create());
 }
 JNIEXPORT jstring JNICALL Java_org_cinvoke_Natives_getError(
        JNIEnv *env, jclass, jlong c) {
-       CInvContext *ctx = (CInvContext *)c;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
        return env->NewStringUTF(cinv_context_geterrormsg(ctx));
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteContext(
        JNIEnv *env, jclass, jlong c) {
-       CInvContext *ctx = (CInvContext *)c;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
        return cinv_context_delete(ctx);
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_createLibrary(
        JNIEnv *env, jclass, jlong c, jstring libname) {
-       CInvContext *ctx = (CInvContext *)c;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
        const char *chrs = env->GetStringUTFChars(libname, NULL);
        if (chrs == NULL) return 0;
 
-       jlong ret = (jlong)cinv_library_create(ctx, chrs);
+       jlong ret = TO_LONG(cinv_library_create(ctx, chrs));
 
        env->ReleaseStringUTFChars(libname, chrs);
        return ret;
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_loadEPLibrary(
        JNIEnv *env, jclass, jlong c, jlong l, jstring name) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvLibrary *lib = (CInvLibrary *)l;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvLibrary *lib = (CInvLibrary *)TO_PTR(l);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return 0;
 
-       jlong ret = (jlong)cinv_library_load_entrypoint(ctx, lib, chrs);
+       jlong ret = TO_LONG(cinv_library_load_entrypoint(ctx, lib, chrs));
 
        env->ReleaseStringUTFChars(name, chrs);
        return ret;
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteLibrary(
        JNIEnv *env, jclass, jlong c, jlong l) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvLibrary *lib = (CInvLibrary *)l;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvLibrary *lib = (CInvLibrary *)TO_PTR(l);
        
        return cinv_library_delete(ctx, lib);
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_createFunction(
        JNIEnv *env, jclass, jlong c, jint cc, jstring retfmt, jstring parmfmt) 
{
-       CInvContext *ctx = (CInvContext *)c;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
        const char *parmchrs = env->GetStringUTFChars(parmfmt, NULL);
        if (parmchrs == NULL) return 0;
        const char *retchrs = env->GetStringUTFChars(retfmt, NULL);
@@ -91,8 +99,8 @@
        if (cc == -1)
                cc = CINV_CC_DEFAULT;
 
-       jlong ret = (jlong)cinv_function_create(ctx, (cinv_callconv_t)cc,
-               retchrs, parmchrs);
+       jlong ret = TO_LONG(cinv_function_create(ctx, (cinv_callconv_t)cc,
+               retchrs, parmchrs));
 
        env->ReleaseStringUTFChars(parmfmt, parmchrs);
        env->ReleaseStringUTFChars(retfmt, retchrs);
@@ -108,9 +116,9 @@
 JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_invokeFunction(
        JNIEnv *env, jclass, jlong c, jlong f, jlong e, jobjectArray params,
        jintArray types, jclass retcls, jint rettype) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvFunction *func = (CInvFunction *)f;
-       void *ep = (void *)e;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvFunction *func = (CInvFunction *)TO_PTR(f);
+       void *ep = (void *)TO_PTR(e);
        jobject ret = NULL;
        void *retp = NULL;
        void **pp = NULL;
@@ -151,7 +159,7 @@
                        fail(env);
                        goto out;
                }
-               Java_org_cinvoke_Natives_writeValue(env, NULL, (jlong)pp[i], 
parm,
+               Java_org_cinvoke_Natives_writeValue(env, NULL, TO_LONG(pp[i]), 
parm,
                        tarr[i]);
        }
        numparms = np;
@@ -163,7 +171,7 @@
        
        if (retp)
                ret = Java_org_cinvoke_Natives_readValue(env, NULL,
-                       (jlong)retp, retcls, rettype);
+                       TO_LONG(retp), retcls, rettype);
 out:
        if (tarr != NULL)
                env->ReleaseIntArrayElements(types, tarr, 0);
@@ -175,21 +183,21 @@
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteFunction(
        JNIEnv *env, jclass, jlong c, jlong f) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvFunction *func = (CInvFunction *)f;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvFunction *func = (CInvFunction *)TO_PTR(f);
 
        return cinv_function_delete(ctx, func);
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_createStruct(
        JNIEnv *env, jclass, jlong c) {
-       CInvContext *ctx = (CInvContext *)c;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
        
-       return (jlong)cinv_structure_create(ctx);
+       return TO_LONG(cinv_structure_create(ctx));
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_addValueMemberStruct(
        JNIEnv *env, jclass, jlong c, jlong s, jstring name, jint type) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return 0;
 
@@ -200,9 +208,9 @@
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_addStructMemberStruct(
        JNIEnv *env, jclass, jlong c, jlong s, jstring name, jlong t) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
-       CInvStructure *type = (CInvStructure *)t;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
+       CInvStructure *type = (CInvStructure *)TO_PTR(t);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return 0;
 
@@ -213,18 +221,13 @@
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_alloc(
        JNIEnv *env, jclass, jint sz) {
-       return (jlong)malloc(sz);
+       return TO_LONG(malloc(sz));
 }
 JNIEXPORT void JNICALL Java_org_cinvoke_Natives_free(
        JNIEnv *env, jclass, jlong p) {
-       void *ptr = (void *)p;
+       void *ptr = (void *)TO_PTR(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);
@@ -275,80 +278,80 @@
 
        switch (type) {
        case CINV_T_CHAR:
-               *(char *)p = (char)b;
+               *(char *)TO_PTR(p) = (char)b;
                break;
        case CINV_T_SHORT:
-               *(short *)p = (short)i;
+               *(short *)TO_PTR(p) = (short)i;
                break;
        case CINV_T_INT:
-               *(int *)p = (int)l;
+               *(int *)TO_PTR(p) = (int)l;
                break;
        case CINV_T_LONG:
-               *(long *)p = (long)l;
+               *(long *)TO_PTR(p) = (long)l;
                break;
        case CINV_T_EXTRALONG:
-               *(long long *)p = (long long)l;
+               *(long long *)TO_PTR(p) = (long long)l;
                break;
        case CINV_T_PTR: 
-               *(void* *)p = (void*)l;
+               *(void* *)TO_PTR(p) = (void*)TO_PTR(l);
                break;
        case CINV_T_FLOAT:
-               *(float *)p = (float)f;
+               *(float *)TO_PTR(p) = (float)f;
                break;
        case CINV_T_DOUBLE:
-               *(double *)p = (double)d;
+               *(double *)TO_PTR(p) = (double)d;
                break;
        case T_JSHORT:
-               *(cinv_int16_t *)p = (cinv_int16_t)s;
+               *(cinv_int16_t *)TO_PTR(p) = (cinv_int16_t)s;
                break;
        case T_JINT:
-               *(cinv_int32_t *)p = (cinv_int32_t)i;
+               *(cinv_int32_t *)TO_PTR(p) = (cinv_int32_t)i;
                break;
        case T_JLONG:
-               *(cinv_int64_t *)p = (cinv_int64_t)l;
+               *(cinv_int64_t *)TO_PTR(p) = (cinv_int64_t)l;
                break;
        }
 
-       char *ptr = (char *)p;
+       char *ptr = (char *)TO_PTR(p);
        ptr += Java_org_cinvoke_Natives_sizeofBasic(env, NULL,  type);
-       return (jlong)ptr;
+       return TO_LONG(ptr);
 }
 JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_readValue(
        JNIEnv *env, jclass, jlong p, jclass cls, jint type) {
        jbyte b; jshort s; jint i; jlong l; jfloat f; jdouble d;
        switch (type) {
        case CINV_T_CHAR:
-               b = (jbyte)*(char *)p;
+               b = (jbyte)*(char *)TO_PTR(p);
                break;
        case CINV_T_SHORT:
-               i = (jint)*(short *)p;
+               i = (jint)*(short *)TO_PTR(p);
                break;
        case CINV_T_INT:
-               l = (jlong)*(int *)p;
+               l = (jlong)*(int *)TO_PTR(p);
                break;
        case CINV_T_LONG:
-               l = (jlong)*(long *)p;
+               l = (jlong)*(long *)TO_PTR(p);
                break;
        case CINV_T_EXTRALONG:
-               l = (jlong)*(long long *)p;
+               l = (jlong)*(long long *)TO_PTR(p);
                break;
        case CINV_T_PTR: 
-               l = (jlong)*(void* *)p;
+               l = TO_LONG(*(void* *)TO_PTR(p));
                break;
        case CINV_T_FLOAT:
-               f = (jfloat)*(float *)p;
+               f = (jfloat)*(float *)TO_PTR(p);
                break;
        case CINV_T_DOUBLE:
-               d = (jdouble)*(double *)p;
+               d = (jdouble)*(double *)TO_PTR(p);
                break;
        case T_JSHORT:
-               s = (jshort)*(cinv_int16_t *)p;
+               s = (jshort)*(cinv_int16_t *)TO_PTR(p);
                break;
        case T_JINT:
-               i = (jint)*(cinv_int32_t *)p;
+               i = (jint)*(cinv_int32_t *)TO_PTR(p);
                break;
        case T_JLONG:
-               l = (jlong)*(cinv_int64_t *)p;
+               l = (jlong)*(cinv_int64_t *)TO_PTR(p);
                break;
        }
        
@@ -390,9 +393,9 @@
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_setMemberValueStruct(
        JNIEnv *env, jclass, jlong c, jlong s, jlong i, jstring name, jobject 
val,
        jint type) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
-       void *inst = (void *)i;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
+       void *inst = (void *)TO_PTR(i);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return 0;
 
@@ -401,16 +404,16 @@
 
        env->ReleaseStringUTFChars(name, chrs);
        
-       Java_org_cinvoke_Natives_writeValue(env, NULL, (jlong)p, val, type);
+       Java_org_cinvoke_Natives_writeValue(env, NULL, TO_LONG(p), val, type);
 
        return CINV_SUCCESS;
 }
 JNIEXPORT jobject JNICALL Java_org_cinvoke_Natives_getMemberValueStruct(
        JNIEnv *env, jclass, jlong c, jlong s, jlong i, jstring name, jclass 
cls,
        jint type) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
-       void *inst = (void *)i;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
+       void *inst = (void *)TO_PTR(i);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return NULL;
 
@@ -419,13 +422,13 @@
 
        env->ReleaseStringUTFChars(name, chrs);
        
-       return Java_org_cinvoke_Natives_readValue(env, NULL, (jlong)p, cls, 
type);
+       return Java_org_cinvoke_Natives_readValue(env, NULL, TO_LONG(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;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
+       void *inst = (void *)TO_PTR(i);
        const char *chrs = env->GetStringUTFChars(name, NULL);
        if (chrs == NULL) return 0;
 
@@ -434,19 +437,19 @@
 
        env->ReleaseStringUTFChars(name, chrs);
        
-       return (jlong)p;
+       return TO_LONG(p);
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_finishStruct(
        JNIEnv *env, jclass, jlong c, jlong s) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
 
        return cinv_structure_finish(ctx, st);
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_sizeStruct(
        JNIEnv *env, jclass, jlong c, jlong s) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
 
        int ret;
        if (!cinv_structure_getsize(ctx, st, &ret))
@@ -455,8 +458,8 @@
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteStruct(
        JNIEnv *env, jclass, jlong c, jlong s) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvStructure *st = (CInvStructure *)s;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvStructure *st = (CInvStructure *)TO_PTR(s);
 
        return cinv_structure_delete(ctx, st);
 }
@@ -496,8 +499,8 @@
        if (!parr) return;
        for (int i = 0; i < numparms; i++) {
                env->SetObjectArrayElement(parr, i,
-                       Java_org_cinvoke_Natives_readValue(env, NULL, 
(jlong)parameters[i],
-                               pclasses[i], ptypes[i]));
+                       Java_org_cinvoke_Natives_readValue(env, NULL,
+                               TO_LONG(parameters[i]), pclasses[i], 
ptypes[i]));
                if (env->ExceptionOccurred()) return;
        }
 
@@ -506,20 +509,21 @@
                return;
 
        if (hasretval)
-               Java_org_cinvoke_Natives_writeValue(env, NULL, (jlong)returnout,
+               Java_org_cinvoke_Natives_writeValue(env, NULL, 
TO_LONG(returnout),
                        retval, rettype);
 }
 
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_createCallback(
        JNIEnv *env, jclass, jlong c, jlong f, jobject cbthunk,
        jobjectArray pclasses, jintArray ptypes, jboolean hasret, jint rettype) 
{
-       CInvContext *ctx = (CInvContext *)c;
-       CInvFunction *func = (CInvFunction *)f;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvFunction *func = (CInvFunction *)TO_PTR(f);
        jobject ref = NULL;
        ud *u = NULL;
        int numparms = 0;
        int *typearr = NULL;
        jclass *clsarr = NULL;
+       jint *tel = NULL;
 
        ref = env->NewGlobalRef(cbthunk);
        if (!ref)
@@ -530,7 +534,7 @@
        typearr = (int *)malloc(sizeof(int) * numparms);
        if (!typearr)
                goto error;
-       jint *tel = env->GetIntArrayElements(ptypes, NULL);
+       tel = env->GetIntArrayElements(ptypes, NULL);
        if (!tel)
                goto error;
        for (int i = 0; i < numparms; i++)
@@ -560,7 +564,7 @@
        u->hasretval = hasret?true:false;
        u->ptypes = typearr;
        u->pclasses = clsarr;
-       return (jlong)cinv_callback_create(ctx, func, u, cbfunc);
+       return TO_LONG(cinv_callback_create(ctx, func, u, cbfunc));
 error:
        if (ref)
                env->DeleteGlobalRef(ref);
@@ -577,15 +581,15 @@
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_getEPCallback(
        JNIEnv *env, jclass, jlong c, jlong b) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvCallback *cb = (CInvCallback *)b;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvCallback *cb = (CInvCallback *)TO_PTR(b);
 
-       return (jlong)cinv_callback_getentrypoint(ctx, cb);
+       return TO_LONG(cinv_callback_getentrypoint(ctx, cb));
 }
 JNIEXPORT jint JNICALL Java_org_cinvoke_Natives_deleteCallback(
        JNIEnv *env, jclass, jlong c, jlong b) {
-       CInvContext *ctx = (CInvContext *)c;
-       CInvCallback *cb = (CInvCallback *)b;
+       CInvContext *ctx = (CInvContext *)TO_PTR(c);
+       CInvCallback *cb = (CInvCallback *)TO_PTR(b);
 
        ud *u = (ud *)cb->userdata;
        u->env->DeleteGlobalRef(u->ref);
@@ -642,17 +646,17 @@
 }
 JNIEXPORT jstring JNICALL Java_org_cinvoke_Natives_ptrToStringUTF8(
        JNIEnv *env, jclass, jlong ptr) {
-       return env->NewStringUTF((char *)ptr);
+       return env->NewStringUTF((char *)TO_PTR(ptr));
 }
 JNIEXPORT jstring JNICALL Java_org_cinvoke_Natives_ptrToStringUnicode(
        JNIEnv *env, jclass, jlong ptr, jint len) {
        if (len < 0) {
-               jchar *t = (jchar *)ptr;
+               jchar *t = (jchar *)TO_PTR(ptr);
                int i = 0;
                while (*t) { i++; t++; }
-               return env->NewString((jchar *)ptr, i);
+               return env->NewString((jchar *)TO_PTR(ptr), i);
        } else
-               return env->NewString((jchar *)ptr, len);
+               return env->NewString((jchar *)TO_PTR(ptr), len);
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_stringToPtrUTF8(
        JNIEnv *env, jclass, jstring str) {
@@ -668,7 +672,7 @@
        memcpy(ret, chrs, len);
        env->ReleaseStringUTFChars(str, chrs);
        ret[len] = 0;
-       return (jlong)ret;
+       return TO_LONG(ret);
 }
 JNIEXPORT jlong JNICALL Java_org_cinvoke_Natives_stringToPtrUnicode(
        JNIEnv *env, jclass, jstring str) {
@@ -684,5 +688,5 @@
        memcpy(ret, chrs, len * sizeof(jchar));
        env->ReleaseStringChars(str, chrs);
        ret[len] = 0;
-       return (jlong)ret;
+       return TO_LONG(ret);
 }

Modified: trunk/cinvoke/bindings/java/org_cinvoke_Natives.h
===================================================================
--- trunk/cinvoke/bindings/java/org_cinvoke_Natives.h   2006-07-15 15:36:32 UTC 
(rev 94)
+++ trunk/cinvoke/bindings/java/org_cinvoke_Natives.h   2006-07-15 18:45:44 UTC 
(rev 95)
@@ -24,7 +24,6 @@
 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);

Modified: trunk/cinvoke/configure.pl
===================================================================
--- trunk/cinvoke/configure.pl  2006-07-15 15:36:32 UTC (rev 94)
+++ trunk/cinvoke/configure.pl  2006-07-15 18:45:44 UTC (rev 95)
@@ -17,6 +17,7 @@
 usage: configure.pl [--prefix=<path>]
        configure.pl --distclean
 EOF
+               exit;
        }
 }
 
@@ -26,6 +27,8 @@
 my $CFLAGS = "-g -Wall -Werror -DCINVOKE_BUILD $BUILDARCH";
 my $ARCH_HEADER = 'gcc_' . lc($platform) . '.h';
 my $DYNEXT;
+my $JNIDYNEXT;
+my $JNIINCLUDE;
 my $BUILDSHARED;
 my $CXXBUILDSHARED;
 my $BUILDSTATIC;
@@ -42,13 +45,17 @@
 # OSX build environment is all wonky
 if ($platform =~ m/_OSX$/) {
        $DYNEXT = 'dylib';
+       $JNIDYNEXT = 'jnilib';
+       $JNIINCLUDE = '-I/System/Library/Frameworks/JavaVM.framework/Headers';
        $BUILDSHARED = 'libtool -dynamic -lc -o';
-       $CXXBUILDSHARED = 'libtool -dynamic -lc -o';
+       $CXXBUILDSHARED = 'g++ -dynamiclib -o';
        $BUILDSTATIC = 'libtool -static -o';
        $RANLIB = 'echo';
        $DYNCFLAGS = '-dynamic';
 } else {
        $DYNEXT = 'so';
+       $JNIDYNEXT = 'so';
+       $JNIINCLUDE = '';
        $BUILDSHARED = 'gcc -shared -o';
        $CXXBUILDSHARED = 'g++ -shared -o';
        $BUILDSTATIC = 'rm -f $(TARGET) && ar rs';





reply via email to

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