classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] RFC: cleanup in nio native code


From: Roman Kennke
Subject: [cp-patches] RFC: cleanup in nio native code
Date: Mon, 25 Jul 2005 12:51:56 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

While merging some nio code I came upon some strange code in gnu_java_nio_channels_FileChannelImpl.c. There is some code that initializes the field in, out and err, which I would think would better fit in the Java code. I propose the following patch to move this init code there. Are there any objections? May I commit this?

2005-07-25  Roman Kennke  <address@hidden>

        * gnu/java/nio/channels/FileChannelImpl.java
        (static initializer): Init out, err and in here.
        * native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
        (Java_gnu_java_nio_channels_FileChannelImpl_init): Moved init
        code
        for in, out and err to Java code.

/Roman
Index: gnu/java/nio/channels/FileChannelImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/nio/channels/FileChannelImpl.java,v
retrieving revision 1.15
diff -u -r1.15 FileChannelImpl.java
--- gnu/java/nio/channels/FileChannelImpl.java  11 Jul 2005 17:27:55 -0000      
1.15
+++ gnu/java/nio/channels/FileChannelImpl.java  25 Jul 2005 10:46:41 -0000
@@ -73,6 +73,10 @@
   public static final int SYNC   = 16;
   public static final int DSYNC  = 32;
 
+  public static FileChannelImpl in;
+  public static FileChannelImpl out;
+  public static FileChannelImpl err;
+
   private static native void init();
 
   static
@@ -83,6 +87,12 @@
       }
     
     init();
+
+    // Replaced native code by simpler, equivalent Java code for
+    // readability and analysability.
+    in  = new FileChannelImpl(0,READ);
+    out = new FileChannelImpl(1,WRITE);
+    err = new FileChannelImpl(2,WRITE);
   }
 
   /**
@@ -130,16 +140,20 @@
       }
   }
 
-  /* Used by init() (native code) */
+  /**
+   * Constructor for default channels in, out and err.
+   *
+   * Used by init() (native code).
+   *
+   * @param fd the file descriptor (0, 1, 2 for stdin, stdout, stderr).
+   *
+   * @param mode READ or WRITE
+   */
   FileChannelImpl (int fd, int mode)
   {
     this.fd = fd;
     this.mode = mode;
   }
-
-  public static FileChannelImpl in;
-  public static FileChannelImpl out;
-  public static FileChannelImpl err;
 
   private native int open (String path, int mode) throws FileNotFoundException;
 
Index: native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c,v
retrieving revision 1.19
diff -u -r1.19 gnu_java_nio_channels_FileChannelImpl.c
--- native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 24 Jul 2005 
03:35:58 -0000      1.19
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 25 Jul 2005 
10:46:41 -0000
@@ -136,28 +136,6 @@
     }
 
   native_fd_fieldID = field;
-
-  constructor = (*env)->GetMethodID (env, clazz, "<init>", "(II)V");
-  if (!constructor)
-    return;
-
-#define INIT_FIELD(FIELDNAME, FDVALUE, MODE)                           \
-  field = (*env)->GetStaticFieldID (env, clazz, FIELDNAME,             \
-                                   "Lgnu/java/nio/channels/FileChannelImpl;"); 
\
-  if (! field)                                                         \
-    return;                                                            \
-  obj = (*env)->NewObject (env, clazz, constructor, FDVALUE, MODE);    \
-  if (! obj)                                                           \
-    return;                                                            \
-  (*env)->SetStaticObjectField (env, clazz, field, obj);               \
-  if ((*env)->ExceptionOccurred (env))                                 \
-    return;
-
-  INIT_FIELD ("in", 0, FILECHANNELIMPL_READ);
-  INIT_FIELD ("out", 1, FILECHANNELIMPL_WRITE);
-  INIT_FIELD ("err", 2, FILECHANNELIMPL_WRITE);
-
-#undef INIT_FIELD
 }
 
 /*

reply via email to

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