United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6792066 src/share/native/java/io/io_util.c clean-ups
JDK-6792066 : src/share/native/java/io/io_util.c clean-ups

Details
Type:
Bug
Submit Date:
2009-01-09
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2009-01-17
Component:
core-libs
OS:
generic
Sub-Component:
java.io
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
Martin has proposed some additional clean-ups to src/share/native/java/io/io_util.c

diff --git a/src/share/native/java/io/io_util.c
b/src/share/native/java/io/io_util.c
--- a/src/share/native/java/io/io_util.c
+++ b/src/share/native/java/io/io_util.c
@@ -25,6 +25,7 @@

 #include <stdlib.h>
 #include <string.h>
+#include <stddef.h>

 #include "jni.h"
 #include "jni_util.h"
@@ -34,9 +35,9 @@

 /* IO helper functions */

-int
+jint
 readSingle(JNIEnv *env, jobject this, jfieldID fid) {
-    int nread;
+    jint nread;
     char ret;
     FD fd = GET_FD(this, fid);
     if (fd == -1) {
@@ -49,7 +50,7 @@
     } else if (nread == JVM_IO_ERR) { /* error */
         JNU_ThrowIOExceptionWithLastError(env, "Read error");
     } else if (nread == JVM_IO_INTR) {
-        JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
+        JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL);
     }
     return ret & 0xFF;
 }
@@ -71,22 +72,22 @@
             ((*env)->GetArrayLength(env, array) - off < len));
 }

-int
+jint
 readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
           jint off, jint len, jfieldID fid)
 {
-    int nread;
+    jint nread;
     char stackBuf[BUF_SIZE];
-    char *buf = 0;
+    char *buf = NULL;
     FD fd;

     if (IS_NULL(bytes)) {
-        JNU_ThrowNullPointerException(env, 0);
+        JNU_ThrowNullPointerException(env, NULL);
         return -1;
     }

     if (outOfBounds(env, off, len, bytes)) {
-        JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0);
+        JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL);
         return -1;
     }

@@ -94,8 +95,8 @@
         return 0;
     } else if (len > BUF_SIZE) {
         buf = malloc(len);
-        if (buf == 0) {
-            JNU_ThrowOutOfMemoryError(env, 0);
+        if (buf == NULL) {
+            JNU_ThrowOutOfMemoryError(env, NULL);
             return 0;
         }
     } else {
@@ -112,8 +113,8 @@
             (*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf);
         } else if (nread == JVM_IO_ERR) {
             JNU_ThrowIOExceptionWithLastError(env, "Read error");
-        } else if (nread == JVM_IO_INTR) { /* EOF */
-            JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
+        } else if (nread == JVM_IO_INTR) {
+            JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL);
         } else { /* EOF */
             nread = -1;
         }
@@ -128,7 +129,7 @@
 void
 writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid) {
     char c = byte;
-    int n;
+    jint n;
     FD fd = GET_FD(this, fid);
     if (fd == -1) {
         JNU_ThrowIOException(env, "Stream Closed");
@@ -138,26 +139,26 @@
     if (n == JVM_IO_ERR) {
         JNU_ThrowIOExceptionWithLastError(env, "Write error");
     } else if (n == JVM_IO_INTR) {
-        JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
+        JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL);
     }
 }

 void
 writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
-          jint off, jint len, jfieldID fid)
+           jint off, jint len, jfieldID fid)
 {
-    int n;
+    jint n;
     char stackBuf[BUF_SIZE];
-    char *buf = 0;
+    char *buf = NULL;
     FD fd;

     if (IS_NULL(bytes)) {
-        JNU_ThrowNullPointerException(env, 0);
+        JNU_ThrowNullPointerException(env, NULL);
         return;
     }

     if (outOfBounds(env, off, len, bytes)) {
-        JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0);
+        JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL);
         return;
     }

@@ -165,8 +166,8 @@
         return;
     } else if (len > BUF_SIZE) {
         buf = malloc(len);
-        if (buf == 0) {
-            JNU_ThrowOutOfMemoryError(env, 0);
+        if (buf == NULL) {
+            JNU_ThrowOutOfMemoryError(env, NULL);
             return;
         }
     } else {
@@ -188,7 +189,7 @@
                 JNU_ThrowIOExceptionWithLastError(env, "Write error");
                 break;
             } else if (n == JVM_IO_INTR) {
-                JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
+                JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL);
                 break;
             }
             off += n;
@@ -204,19 +205,19 @@
 throwFileNotFoundException(JNIEnv *env, jstring path)
 {
     char buf[256];
-    int n;
+    jint n;
     jobject x;
     jstring why = NULL;

     n = JVM_GetLastErrorString(buf, sizeof(buf));
     if (n > 0) {
-    why = JNU_NewStringPlatform(env, buf);
+        why = JNU_NewStringPlatform(env, buf);
     }
     x = JNU_NewObjectByName(env,
-                "java/io/FileNotFoundException",
-                "(Ljava/lang/String;Ljava/lang/String;)V",
-                path, why);
+                            "java/io/FileNotFoundException",
+                            "(Ljava/lang/String;Ljava/lang/String;)V",
+                            path, why);
     if (x != NULL) {
-    (*env)->Throw(env, x);
+        (*env)->Throw(env, x);
     }
 }
diff --git a/src/share/native/java/io/io_util.h
b/src/share/native/java/io/io_util.h
--- a/src/share/native/java/io/io_util.h
+++ b/src/share/native/java/io/io_util.h
@@ -38,9 +38,9 @@
  * IO helper functions
  */

-int readSingle(JNIEnv *env, jobject this, jfieldID fid);
-int readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
-              jint len, jfieldID fid);
+jint readSingle(JNIEnv *env, jobject this, jfieldID fid);
+jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
+               jint len, jfieldID fid);
 void writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid);
 void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
                 jint len, jfieldID fid);

                                    

Comments
EVALUATION

Clean-up.
                                     
2009-01-11



Hardware and Software, Engineered to Work Together