Author: mturk
Date: Sat Jun  4 11:28:26 2011
New Revision: 1131378

URL: http://svn.apache.org/viewvc?rev=1131378&view=rev
Log:
Do not use natve function wrappers

Modified:
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Utils.java
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java

Modified: 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java?rev=1131378&r1=1131377&r2=1131378&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
 Sat Jun  4 11:28:26 2011
@@ -333,19 +333,16 @@ public final class Errno
      */
     public static native String msg();
 
-    public static native void throw0(int errno, String msg)
+    private static native void  throw0(int errno, String msg)
         throws Exception;
-    public static native void throw1(int errno)
+    private static native void  throw1(int errno)
         throws Exception;
 
     /**
      * Throws an exception according to the error code.
      */
-    public static void throwException(int errno, String msg)
-        throws Exception
-    {
-        throw0(errno, msg);
-    }
+    public static native void throwException(int errno, String msg)
+        throws Exception;
 
     /**
      * Throws an exception according to the error code.
@@ -353,7 +350,7 @@ public final class Errno
     public static void throwException(int errno)
         throws Exception
     {
-        throw1(errno);
+        throwException(errno, null);
     }
     
 }

Modified: 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Utils.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Utils.java?rev=1131378&r1=1131377&r2=1131378&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Utils.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Utils.java
 Sat Jun  4 11:28:26 2011
@@ -18,6 +18,7 @@
 
 package org.apache.commons.runtime.io;
 import java.io.FileDescriptor;
+import java.io.IOException;
 
 public final class Utils
 {
@@ -29,6 +30,7 @@ public final class Utils
     private static native int   getFd0(FileDescriptor fd);
     private static native long  getFd1(FileDescriptor fd);
 
+
     /**
      * Get native file descriptor.
      */
@@ -51,4 +53,19 @@ public final class Utils
         return getFd1(fd);
     }
 
+    /**
+     * Throws an exception according to the error code.
+     */
+    public static native void  throwException(int errno, String msg)
+        throws IOException;
+
+    /**
+     * Throws an exception according to the error code.
+     */
+    public static void throwException(int errno)
+        throws IOException
+    {
+        throwException(errno, null);
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1131378&r1=1131377&r2=1131378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Jun  4 
11:28:26 2011
@@ -751,6 +751,7 @@ void
 AcrThrowByError(JNI_STDENV, int def, int err, const char *msg)
 {
     int cls = def;
+    char buf[ACR_MBUFF_SIZ] = "";
     const char *str = 0;
 
     if (ACR_STATUS_IS_EEXIST(err))
@@ -785,8 +786,13 @@ AcrThrowByError(JNI_STDENV, int def, int
         cls = ACR_EX_EOVERFLOW;
     else if (err == ACR_ETIMEDOUT)
         cls = ACR_EX_TIMEOUT;
-    else
+    else {
         str = msg;
+        if (str == 0) {
+            _cr_strerror_r(err, buf, ACR_MBUFF_SIZ);
+            str = buf;
+        }
+    }
     AcrThrow(env, cls, str);
 }
 
@@ -958,7 +964,7 @@ ACR_JNI_EXPORT(jstring, Errno, msg)(JNI_
     return AcrNewJavaStringA(env, buf);
 }
 
-ACR_JNI_EXPORT(void, Errno, throw0)(JNI_STDARGS, jint err, jstring msg)
+ACR_JNI_EXPORT(void, Errno, throwException)(JNI_STDARGS, jint err, jstring msg)
 {
     WITH_CSTR(msg) {
         AcrThrowByError(env, ACR_EX_ESYS, err, J2S(msg));
@@ -966,10 +972,9 @@ ACR_JNI_EXPORT(void, Errno, throw0)(JNI_
 
 }
 
-ACR_JNI_EXPORT(void, Errno, throw1)(JNI_STDARGS, jint err)
+ACR_IO_EXPORT(void, Util, throwException)(JNI_STDARGS, jint err, jstring msg)
 {
-    char msg[ACR_MBUFF_SIZ] = "";
-
-    _cr_strerror_r(err, msg, ACR_MBUFF_SIZ);
-    AcrThrowByError(env, ACR_EX_ESYS, err, msg);
+    WITH_CSTR(msg) {
+        AcrThrowByError(env, ACR_EX_EIO, err, J2S(msg));
+    } DONE_WITH_STR(msg);
 }

Modified: 
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java?rev=1131378&r1=1131377&r2=1131378&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
 Sat Jun  4 11:28:26 2011
@@ -21,6 +21,10 @@ import java.io.File;
 import org.testng.annotations.*;
 import org.testng.Assert;
 import org.apache.commons.runtime.util.Utils;
+import org.apache.commons.runtime.Errno;
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.TimeoutException;
+import org.apache.commons.runtime.SystemException;
 
 public class TestUtils extends Assert
 {
@@ -87,4 +91,18 @@ public class TestUtils extends Assert
         assertEquals(s[1], "bcd");
     }
 
+    @Test(groups = { "core" }, expectedExceptions = TimeoutException.class)
+    public void checkTimeoutException()
+        throws Exception
+    {
+        Errno.throwException(Errno.ETIMEDOUT);
+    }
+
+    @Test(groups = { "core" }, expectedExceptions = SystemException.class)
+    public void checkSystemExceptions()
+        throws Exception
+    {
+        Errno.throwException(Errno.ECANCELED, "Unused");
+    }
+
 }


Reply via email to