You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2008/02/07 22:51:21 UTC

svn commit: r619658 - in /harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared: deflater.c inflater.c

Author: hindessm
Date: Thu Feb  7 13:51:18 2008
New Revision: 619658

URL: http://svn.apache.org/viewvc?rev=619658&view=rev
Log:
More error handling improvements and compiler warnings fixes.

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/deflater.c
    harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/inflater.c

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/deflater.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/deflater.c?rev=619658&r1=619657&r2=619658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/deflater.c (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/deflater.c Thu Feb  7 13:51:18 2008
@@ -45,15 +45,15 @@
       throwNewOutOfMemoryError (env, "");
       return;
     }
-  (*env)->GetByteArrayRegion (env, dict, off, len, dBytes);
+  (*env)->GetByteArrayRegion (env, dict, off, len, (jbyte *) dBytes);
   err = deflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
   if (err != Z_OK)
     {
       jclmem_free_memory (env, dBytes);
-      throwNewIllegalArgumentException (env, "");
+      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
       return;
     }
-  stream->dict = dBytes;
+  stream->dict = (U_8*) dBytes;
 }
 
 JNIEXPORT jlong JNICALL
@@ -133,11 +133,10 @@
 		      wbits,	/*Window bits to use. 15 is fastest but consumes the most memory */
 		      9,	/*Memory allocation for internal compression state. 9 uses the most. */
 		      strategy);
-  if (err != Z_OK)
-    {
-      throwNewIllegalArgumentException (env, "");
-      return -1;
-    }
+  if (err != Z_OK) {
+    THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
+    return -1;
+  }
 
   return (jlong) ((IDATA) jstream);
 }
@@ -162,8 +161,10 @@
       return;
     }
   in = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
-  if (in == NULL)
+  if (in == NULL) {
+    throwNewOutOfMemoryError(env, "");
     return;
+  }
   memcpy (stream->inaddr, (in + off), len);
   ((*env)->ReleasePrimitiveArrayCritical (env, buf, in, JNI_ABORT));
   stream->stream->next_in = (Bytef *) stream->inaddr;
@@ -177,8 +178,6 @@
 					 jbyteArray buf, int off, int len,
 					 jlong handle, int flushParm)
 {
-  PORT_ACCESS_FROM_ENV (env);
-
   jbyte *out;
   JCLZipStream *stream;
   jint err = 0;
@@ -195,30 +194,35 @@
   sin = stream->stream->total_in;
   sout = stream->stream->total_out;
   out = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
-  if (out == NULL)
+  if (out == NULL) {
+    throwNewOutOfMemoryError(env, "");
     return -1;
+  }
   stream->stream->next_out = (Bytef *) out + off;
   err = deflate (stream->stream, flushParm);
   ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
-  if (err != Z_OK)
-    {
-      if (err == Z_STREAM_END)
-	{
-	  ((*env)->
-	   SetBooleanField (env, recv,
-			    JCL_CACHE_GET (env,
-					   FID_java_util_zip_Deflater_finished),
-			    JNI_TRUE));
-	  return stream->stream->total_out - sout;
-	}
-    }
+  if (err != Z_OK) {
+    if (err == Z_MEM_ERROR) {
+      throwNewOutOfMemoryError(env, "");
+      return 0;
+    }
+    if (err == Z_STREAM_END)
+      {
+        ((*env)->
+         SetBooleanField (env, recv,
+                          JCL_CACHE_GET (env,
+                                         FID_java_util_zip_Deflater_finished),
+                          JNI_TRUE));
+        return stream->stream->total_out - sout;
+      }
+  }
   if (flushParm != Z_FINISH)
     {
       /* Need to update the number of input bytes read. */
       ((*env)->
        SetIntField (env, recv,
-		    JCL_CACHE_GET (env, FID_java_util_zip_Deflater_inRead),
-		    (jint) stream->stream->total_in - sin + inBytes));
+                    JCL_CACHE_GET (env, FID_java_util_zip_Deflater_inRead),
+                    (jint) stream->stream->total_in - sin + inBytes));
     }
   return stream->stream->total_out - sout;
 }
@@ -255,8 +259,6 @@
 					   int level, int strategy,
 					   jlong handle)
 {
-  PORT_ACCESS_FROM_ENV (env);
-
   JCLZipStream *stream;
   jbyte b = 0;
   int err = 0;
@@ -269,8 +271,9 @@
   stream = (JCLZipStream *) ((IDATA) handle);
   stream->stream->next_out = (Bytef *) & b;
   err = deflateParams (stream->stream, level, strategy);
-  if (err != Z_OK)
-    throwNewIllegalStateException (env, "");
+  if (err != Z_OK) {
+    THROW_ZIP_EXCEPTION(env, err, IllegalStateException);
+  }
 }
 
 JNIEXPORT void JNICALL

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/inflater.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/inflater.c?rev=619658&r1=619657&r2=619658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/inflater.c (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/native/archive/shared/inflater.c Thu Feb  7 13:51:18 2008
@@ -75,7 +75,7 @@
     {
       jclmem_free_memory (env, stream);
       jclmem_free_memory (env, jstream);
-      throwNewIllegalArgumentException (env, "");
+      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
       return -1;
     }
 
@@ -105,8 +105,10 @@
   stream->stream->next_in = (Bytef *) baseAddr;
   stream->stream->avail_in = len;
   in = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
-  if (in == NULL)
+  if (in == NULL) {
+    throwNewOutOfMemoryError(env, "");
     return;
+  }
   memcpy (baseAddr, (in + off), len);
   ((*env)->ReleasePrimitiveArrayCritical (env, buf, in, JNI_ABORT));
   return;
@@ -117,8 +119,6 @@
                                          jbyteArray buf, int off, int len,
                                          jlong handle)
 {
-  PORT_ACCESS_FROM_ENV (env);
-
   jbyte *out;
   JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
   jint err = 0;
@@ -133,8 +133,10 @@
   sin = stream->stream->total_in;
   sout = stream->stream->total_out;
   out = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
-  if (out == NULL)
+  if (out == NULL) {
+    throwNewOutOfMemoryError(env, "");
     return -1;
+  }
   stream->stream->next_out = (Bytef *) out + off;
   err = inflate (stream->stream, Z_SYNC_FLUSH);
   ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
@@ -158,7 +160,7 @@
         }
       else
         {
-          throwNewDataFormatException (env, "");
+          THROW_ZIP_EXCEPTION(env, err, DataFormatException);
           return -1;
         }
     }
@@ -216,12 +218,12 @@
       throwNewOutOfMemoryError (env, "");
       return;
     }
-  (*env)->GetByteArrayRegion (env, dict, off, len, dBytes);
+  (*env)->GetByteArrayRegion (env, dict, off, len, (jbyte*)dBytes);
   err = inflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
   if (err != Z_OK)
     {
       jclmem_free_memory (env, dBytes);
-      throwNewIllegalArgumentException (env, "");
+      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
       return;
     }
   stream->dict = dBytes;
@@ -238,7 +240,7 @@
   err = inflateReset (stream->stream);
   if (err != Z_OK)
     {
-      throwNewIllegalArgumentException (env, "");
+      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
       return;
     }
 }