Author: j16sdiz
Date: 2009-04-23 01:40:25 +0000 (Thu, 23 Apr 2009)
New Revision: 27218

Modified:
   trunk/contrib/fec/src/com/onionnetworks/fec/Native16Code.java
   trunk/contrib/fec/src/com/onionnetworks/fec/Native8Code.java
   trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native16Code.h
   trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native8Code.h
   trunk/contrib/fec/src/csrc/fec16-jinterf.c
   trunk/contrib/fec/src/csrc/fec8-jinterf.c
Log:
Use GetLongField() / SetLongField()

Modified: trunk/contrib/fec/src/com/onionnetworks/fec/Native16Code.java
===================================================================
--- trunk/contrib/fec/src/com/onionnetworks/fec/Native16Code.java       
2009-04-23 01:40:07 UTC (rev 27217)
+++ trunk/contrib/fec/src/com/onionnetworks/fec/Native16Code.java       
2009-04-23 01:40:25 UTC (rev 27218)
@@ -18,13 +18,14 @@
     // One must be very very careful not to let code escape, it stores the
     // memory address of a fec_parms struct and if modified could give an
     // attacker the ability to point to anything in memory.
-    private final long code;
+    private long code;
     
     static {
         String path = NativeDeployer.getLibraryPath
             (Native8Code.class.getClassLoader(),"fec16");
         if (path != null) {
             System.load(path);
+                       initFEC();
         } else {
             System.out.println("Unable to find native library for fec16 for 
platform "+NativeDeployer.OS_ARCH);
             System.out.println(path);
@@ -34,7 +35,7 @@
     public Native16Code(int k, int n) {
         super(k,n);
                synchronized (Native16Code.class) {
-                       code = nativeNewFEC(k,n);
+                       nativeNewFEC(k,n);
                }
     }
 
@@ -45,7 +46,7 @@
             throw new IllegalArgumentException("For 16 bit codes, buffers "+
                                                "must be 16 bit aligned.");
         }
-        nativeEncode(code,src,srcOff,index,repair,repairOff,k,packetLength);
+        nativeEncode(src,srcOff,index,repair,repairOff,k,packetLength);
     }
 
     protected void decode(byte[][] pkts, int[] pktsOff,
@@ -57,22 +58,24 @@
         if (!inOrder) {
             shuffle(pkts,pktsOff,index,k);
         }
-        nativeDecode(code,pkts,pktsOff,index,k,packetLength);
+        nativeDecode(pkts,pktsOff,index,k,packetLength);
     }
 
     protected native void nativeEncode
-        (long code, byte[][] src, int[] srcOff, int[] index, byte[][] repair, 
+        (byte[][] src, int[] srcOff, int[] index, byte[][] repair, 
          int[] repairOff, int k, int packetLength);
 
-    protected native void nativeDecode(long code, byte[][] pkts, int[] pktsOff,
+    protected native void nativeDecode(byte[][] pkts, int[] pktsOff,
                                        int[] index, int k, int packetLength);
 
-    protected synchronized native long nativeNewFEC(int k, int n);
+    protected synchronized native void nativeNewFEC(int k, int n);
 
-    protected synchronized native void nativeFreeFEC(long code);
+    protected synchronized native void nativeFreeFEC();
 
+    protected static synchronized native void initFEC();
+
     protected void finalize() throws Throwable {
-        nativeFreeFEC(code);
+        nativeFreeFEC();
     }
 
     public String toString() {

Modified: trunk/contrib/fec/src/com/onionnetworks/fec/Native8Code.java
===================================================================
--- trunk/contrib/fec/src/com/onionnetworks/fec/Native8Code.java        
2009-04-23 01:40:07 UTC (rev 27217)
+++ trunk/contrib/fec/src/com/onionnetworks/fec/Native8Code.java        
2009-04-23 01:40:25 UTC (rev 27218)
@@ -18,30 +18,31 @@
     // One must be very very careful not to let code escape, it stores the
     // memory address of a fec_parms struct and if modified could give an
     // attacker the ability to point to anything in memory.
-    private final long code;
+    private long code;
     
     static {
         String path = NativeDeployer.getLibraryPath
             (Native8Code.class.getClassLoader(),"fec8");
         if (path != null) {
             System.load(path);
+                       initFEC();
         } else {
             System.out.println("Unable to find native library for fec8 for 
platform "+NativeDeployer.OS_ARCH);
-           System.out.println(path);
+                       System.out.println(path);
         }
     }
     
     public Native8Code(int k, int n) {
         super(k,n);
                synchronized(Native8Code.class) {
-                       code = nativeNewFEC(k,n);
+                       nativeNewFEC(k,n);
                }
     }
 
     protected void encode(byte[][] src, int[] srcOff, byte[][] repair, 
                           int[] repairOff, int[] index, int packetLength) {
         
-        nativeEncode(code,src,srcOff,index,repair,repairOff,k,packetLength);
+        nativeEncode(src,srcOff,index,repair,repairOff,k,packetLength);
     }
 
     protected void decode(byte[][] pkts, int[] pktsOff,
@@ -51,22 +52,24 @@
         if (!inOrder) {
             shuffle(pkts,pktsOff,index,k);
         }
-        nativeDecode(code,pkts,pktsOff,index,k,packetLength);
+        nativeDecode(pkts,pktsOff,index,k,packetLength);
     }
 
     protected native void nativeEncode
-        (long code, byte[][] src, int[] srcOff, int[] index, byte[][] repair, 
+        (byte[][] src, int[] srcOff, int[] index, byte[][] repair, 
          int[] repairOff, int k, int packetLength);
 
-    protected native void nativeDecode(long code, byte[][] pkts, int[] pktsOff,
+    protected native void nativeDecode(byte[][] pkts, int[] pktsOff,
                                        int[] index, int k, int packetLength);
 
-    protected synchronized native long nativeNewFEC(int k, int n);
+    protected synchronized native void nativeNewFEC(int k, int n);
 
-    protected synchronized native void nativeFreeFEC(long code);
+    protected synchronized native void nativeFreeFEC();
 
+    protected static synchronized native void initFEC();
+
     protected void finalize() throws Throwable {
-        nativeFreeFEC(code);
+        nativeFreeFEC();
     }
 
     public String toString() {

Modified: trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native16Code.h
===================================================================
--- trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native16Code.h     
2009-04-23 01:40:07 UTC (rev 27217)
+++ trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native16Code.h     
2009-04-23 01:40:25 UTC (rev 27218)
@@ -10,35 +10,43 @@
 /*
  * Class:     com_onionnetworks_fec_Native16Code
  * Method:    nativeEncode
- * Signature: (J[[B[I[I[[B[III)V
+ * Signature: ([[B[I[I[[B[III)V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeEncode
-  (JNIEnv *, jobject, jlong, jobjectArray, jintArray, jintArray, jobjectArray, 
jintArray, jint, jint);
+  (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jobjectArray, 
jintArray, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native16Code
  * Method:    nativeDecode
- * Signature: (J[[B[I[III)V
+ * Signature: ([[B[I[III)V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeDecode
-  (JNIEnv *, jobject, jlong, jobjectArray, jintArray, jintArray, jint, jint);
+  (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native16Code
  * Method:    nativeNewFEC
- * Signature: (II)J
+ * Signature: (II)V
  */
-JNIEXPORT jlong JNICALL Java_com_onionnetworks_fec_Native16Code_nativeNewFEC
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeNewFEC
   (JNIEnv *, jobject, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native16Code
  * Method:    nativeFreeFEC
- * Signature: (J)V
+ * Signature: ()V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeFreeFEC
-  (JNIEnv *, jobject, jlong);
+  (JNIEnv *, jobject);
 
+/*
+ * Class:     com_onionnetworks_fec_Native16Code
+ * Method:    initFEC
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_initFEC
+  (JNIEnv *, jclass);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native8Code.h
===================================================================
--- trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native8Code.h      
2009-04-23 01:40:07 UTC (rev 27217)
+++ trunk/contrib/fec/src/csrc/com_onionnetworks_fec_Native8Code.h      
2009-04-23 01:40:25 UTC (rev 27218)
@@ -10,35 +10,43 @@
 /*
  * Class:     com_onionnetworks_fec_Native8Code
  * Method:    nativeEncode
- * Signature: (J[[B[I[I[[B[III)V
+ * Signature: ([[B[I[I[[B[III)V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeEncode
-  (JNIEnv *, jobject, jlong, jobjectArray, jintArray, jintArray, jobjectArray, 
jintArray, jint, jint);
+  (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jobjectArray, 
jintArray, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native8Code
  * Method:    nativeDecode
- * Signature: (J[[B[I[III)V
+ * Signature: ([[B[I[III)V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeDecode
-  (JNIEnv *, jobject, jlong, jobjectArray, jintArray, jintArray, jint, jint);
+  (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native8Code
  * Method:    nativeNewFEC
- * Signature: (II)J
+ * Signature: (II)V
  */
-JNIEXPORT jlong JNICALL Java_com_onionnetworks_fec_Native8Code_nativeNewFEC
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeNewFEC
   (JNIEnv *, jobject, jint, jint);
 
 /*
  * Class:     com_onionnetworks_fec_Native8Code
  * Method:    nativeFreeFEC
- * Signature: (J)V
+ * Signature: ()V
  */
 JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeFreeFEC
-  (JNIEnv *, jobject, jlong);
+  (JNIEnv *, jobject);
 
+/*
+ * Class:     com_onionnetworks_fec_Native8Code
+ * Method:    initFEC
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_initFEC
+  (JNIEnv *, jclass);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/contrib/fec/src/csrc/fec16-jinterf.c
===================================================================
--- trunk/contrib/fec/src/csrc/fec16-jinterf.c  2009-04-23 01:40:07 UTC (rev 
27217)
+++ trunk/contrib/fec/src/csrc/fec16-jinterf.c  2009-04-23 01:40:25 UTC (rev 
27218)
@@ -10,28 +10,34 @@
 #include "com_onionnetworks_fec_Native16Code.h"
 #include "fec.h"
 
+jfieldID codeField;
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_initFEC
+  (JNIEnv * env, jclass clz) {
+       codeField = (*env)->GetFieldID(env, clz, "code", "J");
+}
+
 /*
  * encode
  *
  * @param code This int is actually stores a memory address that points to
  * an fec_parms struct.
  */
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native16Code_nativeEncode
-    (JNIEnv *env, jobject obj, jlong code, jobjectArray src, jintArray srcOff,
-     jintArray index, jobjectArray ret, jintArray retOff, jint k, 
-     jint packetLength) {
-    
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeEncode
+  (JNIEnv *env, jobject obj, jobjectArray src, jintArray srcOff,
+       jintArray index, jobjectArray ret, jintArray retOff, jint k,
+       jint packetLength) {
+
     jint *localSrcOff, *localIndex, *localRetOff;
        jbyteArray *inArr, *retArr;
     jbyte **inarr, **retarr;
        jobject result = NULL;
 
        int i, numRet;
+       jlong code = (*env)->GetLongField(env, obj, codeField);
 
        /* allocate memory for the arrays */
     inArr  = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
-    retArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);        
+    retArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
 
     inarr  = (jbyte **) malloc(sizeof(jbyte *) * k);
     retarr = (jbyte **) malloc(sizeof(jbyte *) * k);
@@ -64,7 +70,7 @@
                                return; /* exception occured */
                        }
 
-               inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0); 
+               inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0);
         if (inarr[i] == NULL) {
             return; /* exception occured */
         }
@@ -77,7 +83,7 @@
             return; /* exception occured */
         }
 
-               retarr[i] = (*env)->GetByteArrayElements(env, retArr[i], 0); 
+               retarr[i] = (*env)->GetByteArrayElements(env, retArr[i], 0);
         if (retarr[i] == NULL) {
             return; /* exception occured */
         }
@@ -85,18 +91,18 @@
     }
 
     for (i=0;i<numRet;i++) {
-        fec_encode((void *)(uintptr_t)code, (gf **)(uintptr_t)inarr, (void 
*)(uintptr_t)retarr[i], 
-                   (int)localIndex[i], (int)packetLength); 
+        fec_encode((void *)(uintptr_t)code, (gf **)(uintptr_t)inarr, (void 
*)(uintptr_t)retarr[i],
+                   (int)localIndex[i], (int)packetLength);
     }
 
     for (i=0;i<k;i++) {
-        inarr[i] -= localSrcOff[i]; 
+        inarr[i] -= localSrcOff[i];
                (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0);
-    } 
- 
+    }
+
     for (i=0;i<numRet;i++) {
         retarr[i] -= localRetOff[i];
-               (*env)->ReleaseByteArrayElements(env, retArr[i], retarr[i], 0); 
+               (*env)->ReleaseByteArrayElements(env, retArr[i], retarr[i], 0);
     }
 
     (*env)->ReleaseIntArrayElements(env, srcOff, localSrcOff, 0);
@@ -106,24 +112,16 @@
        /* free the memory reserved by PushLocalFrame() */
        result = (*env)->PopLocalFrame(env, result);
 
-       /* free() may not be necessary. complements malloc() */
+       /* free() complements malloc() */
        free(inArr);
        free(retArr);
        free(inarr);
        free(retarr);
-
 }
 
 
-/*
- * The data[] MUST be preshuffled before this call is made or it WILL NOT
- * WORK!  It is very difficult to make Java aware that the pointers have
- * been shuffled in the encode() call, so we must pre-shuffle the data
- * so that encode doesn't move any pointers around.
- */
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native16Code_nativeDecode
-    (JNIEnv *env, jobject obj, jlong code, jobjectArray data, jintArray 
dataOff,
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeDecode
+    (JNIEnv *env, jobject obj, jobjectArray data, jintArray dataOff,
      jintArray whichdata, jint k, jint packetLength) {
 
     jint *localWhich, *localDataOff;
@@ -132,6 +130,7 @@
        jobject result = NULL;
        
        int i;
+       jlong code = (*env)->GetLongField(env, obj, codeField);
 
        /* allocate memory for the arrays */
        inArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
@@ -157,7 +156,7 @@
         if (inArr[i] == NULL) {
             return;  /* exception occured */
         }
-       inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0); 
+       inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0);
         if (inarr[i] == NULL) {
             return;  /* exception occured */
         }
@@ -172,7 +171,7 @@
     }
 
     for (i = 0; i < k; i++) {
-               (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0); 
+               (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0);
     }
 
     (*env)->ReleaseIntArrayElements(env, whichdata, localWhich, 0);
@@ -184,22 +183,19 @@
        /* free() may not be necessary. complements malloc() */
        free(inArr);
        free(inarr);
-
 }
 
-JNIEXPORT jlong JNICALL
-    Java_com_onionnetworks_fec_Native16Code_nativeNewFEC
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeNewFEC
     (JNIEnv * env, jobject obj, jint k, jint n) {
-    
     // uintptr_t is needed for systems where sizeof(void*) < sizeof(long)
-    return (jlong)(uintptr_t)fec_new(k,n); 
+    jlong code = (jlong)(uintptr_t)fec_new(k,n);
 
+       (*env)->SetLongField(env, obj, codeField, code);
 }
 
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native16Code_nativeFreeFEC
-    (JNIEnv * env, jobject obj, jlong code) {
-    
-    fec_free((void *)(uintptr_t)code); 
-
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native16Code_nativeFreeFEC
+    (JNIEnv * env, jobject obj) {
+       jlong code = (*env)->GetLongField(env, obj, codeField);
+    fec_free((void *)(uintptr_t)code);
+       (*env)->SetLongField(env, obj, codeField, 0);
 }

Modified: trunk/contrib/fec/src/csrc/fec8-jinterf.c
===================================================================
--- trunk/contrib/fec/src/csrc/fec8-jinterf.c   2009-04-23 01:40:07 UTC (rev 
27217)
+++ trunk/contrib/fec/src/csrc/fec8-jinterf.c   2009-04-23 01:40:25 UTC (rev 
27218)
@@ -10,28 +10,34 @@
 #include "com_onionnetworks_fec_Native8Code.h"
 #include "fec.h"
 
+jfieldID codeField;
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_initFEC
+  (JNIEnv * env, jclass clz) {
+       codeField = (*env)->GetFieldID(env, clz, "code", "J");
+}
+
 /*
  * encode
  *
  * @param code This int is actually stores a memory address that points to
  * an fec_parms struct.
  */
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native8Code_nativeEncode
-    (JNIEnv *env, jobject obj, jlong code, jobjectArray src, jintArray srcOff,
-     jintArray index, jobjectArray ret, jintArray retOff, jint k, 
-     jint packetLength) {
-    
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeEncode
+  (JNIEnv *env, jobject obj, jobjectArray src, jintArray srcOff,
+       jintArray index, jobjectArray ret, jintArray retOff, jint k,
+       jint packetLength) {
+
     jint *localSrcOff, *localIndex, *localRetOff;
        jbyteArray *inArr, *retArr;
     jbyte **inarr, **retarr;
        jobject result = NULL;
 
        int i, numRet;
+       jlong code = (*env)->GetLongField(env, obj, codeField);
 
        /* allocate memory for the arrays */
     inArr  = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
-    retArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);        
+    retArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
 
     inarr  = (jbyte **) malloc(sizeof(jbyte *) * k);
     retarr = (jbyte **) malloc(sizeof(jbyte *) * k);
@@ -64,11 +70,11 @@
                                return; /* exception occured */
                        }
 
-               inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0); 
+               inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0);
         if (inarr[i] == NULL) {
             return; /* exception occured */
         }
-        inarr[i] += localSrcOff[i]; 
+        inarr[i] += localSrcOff[i];
     }
 
     for (i=0;i<numRet;i++) {
@@ -77,7 +83,7 @@
             return; /* exception occured */
         }
 
-               retarr[i] = (*env)->GetByteArrayElements(env, retArr[i], 0); 
+               retarr[i] = (*env)->GetByteArrayElements(env, retArr[i], 0);
         if (retarr[i] == NULL) {
             return; /* exception occured */
         }
@@ -85,18 +91,18 @@
     }
 
     for (i=0;i<numRet;i++) {
-        fec_encode((void *)(uintptr_t)code, (gf **)(uintptr_t)inarr, (void 
*)(uintptr_t)retarr[i], 
-                   (int)localIndex[i], (int)packetLength); 
+        fec_encode((void *)(uintptr_t)code, (gf **)(uintptr_t)inarr, (void 
*)(uintptr_t)retarr[i],
+                   (int)localIndex[i], (int)packetLength);
     }
 
     for (i=0;i<k;i++) {
-        inarr[i] -= localSrcOff[i]; 
+        inarr[i] -= localSrcOff[i];
                (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0);
-    } 
- 
+    }
+
     for (i=0;i<numRet;i++) {
         retarr[i] -= localRetOff[i];
-               (*env)->ReleaseByteArrayElements(env, retArr[i], retarr[i], 0); 
+               (*env)->ReleaseByteArrayElements(env, retArr[i], retarr[i], 0);
     }
 
     (*env)->ReleaseIntArrayElements(env, srcOff, localSrcOff, 0);
@@ -111,19 +117,11 @@
        free(retArr);
        free(inarr);
        free(retarr);
-
 }
 
 
-/*
- * The data[] MUST be preshuffled before this call is made or it WILL NOT
- * WORK!  It is very difficult to make Java aware that the pointers have
- * been shuffled in the encode() call, so we must pre-shuffle the data
- * so that encode doesn't move any pointers around.
- */
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native8Code_nativeDecode
-    (JNIEnv *env, jobject obj, jlong code, jobjectArray data, jintArray 
dataOff,
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeDecode
+    (JNIEnv *env, jobject obj, jobjectArray data, jintArray dataOff,
      jintArray whichdata, jint k, jint packetLength) {
 
     jint *localWhich, *localDataOff;
@@ -132,6 +130,7 @@
        jobject result = NULL;
        
        int i;
+       jlong code = (*env)->GetLongField(env, obj, codeField);
 
        /* allocate memory for the arrays */
        inArr = (jbyteArray *) malloc(sizeof(jbyteArray) * k);
@@ -157,7 +156,7 @@
         if (inArr[i] == NULL) {
             return;  /* exception occured */
         }
-       inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0); 
+       inarr[i] = (*env)->GetByteArrayElements(env, inArr[i], 0);
         if (inarr[i] == NULL) {
             return;  /* exception occured */
         }
@@ -172,7 +171,7 @@
     }
 
     for (i = 0; i < k; i++) {
-               (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0); 
+               (*env)->ReleaseByteArrayElements(env, inArr[i], inarr[i], 0);
     }
 
     (*env)->ReleaseIntArrayElements(env, whichdata, localWhich, 0);
@@ -184,21 +183,19 @@
        /* free() may not be necessary. complements malloc() */
        free(inArr);
        free(inarr);
-
 }
 
-JNIEXPORT jlong JNICALL
-    Java_com_onionnetworks_fec_Native8Code_nativeNewFEC
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeNewFEC
     (JNIEnv * env, jobject obj, jint k, jint n) {
-    
     // uintptr_t is needed for systems where sizeof(void*) < sizeof(long)
-    return (jlong)(uintptr_t)fec_new(k,n);
+    jlong code = (jlong)(uintptr_t)fec_new(k,n);
+
+       (*env)->SetLongField(env, obj, codeField, code);
 }
 
-JNIEXPORT void JNICALL
-    Java_com_onionnetworks_fec_Native8Code_nativeFreeFEC
-    (JNIEnv * env, jobject obj, jlong code) {
-    
-    fec_free((void *)(uintptr_t)code); 
-
+JNIEXPORT void JNICALL Java_com_onionnetworks_fec_Native8Code_nativeFreeFEC
+    (JNIEnv * env, jobject obj) {
+       jlong code = (*env)->GetLongField(env, obj, codeField);
+    fec_free((void *)(uintptr_t)code);
+       (*env)->SetLongField(env, obj, codeField, 0);
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to