You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/22 09:56:27 UTC

svn commit: r806805 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in include/acr_dso.h include/acr_error.h os/unix/dso.c shared/error.c test/testsuite.c

Author: mturk
Date: Sat Aug 22 07:56:26 2009
New Revision: 806805

URL: http://svn.apache.org/viewvc?rev=806805&view=rev
Log:
Better error handling in dso

Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr_dso.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat Aug 22 07:56:26 2009
@@ -99,6 +99,7 @@
 
 WINDOWS_OBJS= \
 	$(SRCDIR)/os/win32/dirent.$(OBJ) \
+	$(SRCDIR)/os/win32/dso.$(OBJ) \
 	$(SRCDIR)/os/win32/env.$(OBJ) \
 	$(SRCDIR)/os/win32/execmem.$(OBJ) \
 	$(SRCDIR)/os/win32/file.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_dso.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_dso.h?rev=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_dso.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_dso.h Sat Aug 22 07:56:26 2009
@@ -54,7 +54,7 @@
  * @param symname Name of the symbol to load.
  */
 ACR_DECLARE(void *) ACR_DsoSym(JNIEnv *env, int dso,
-                               const acr_pchar_t *symname);
+                               const char *symname);
 
 
 #ifdef __cplusplus

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Sat Aug 22 07:56:26 2009
@@ -47,6 +47,7 @@
     ACR_EX_EINSTANCE,       /* java/lang/InstantiationException */
     ACR_EX_EINTERNAL,       /* java/lang/InternalError */
     ACR_EX_ESECURITY,       /* java/lang/SecurityException */
+    ACR_EX_ULINK,           /* java/lang/UnsatisfiedLinkError */
     ACR_EX_ENOTIMPL,        /* java/lang/UnsupportedOperationException */
     ACR_EX_EIO,             /* java/io/IOException */
     ACR_EX_ESYNC,           /* java/io/SyncFailedException */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c?rev=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c Sat Aug 22 07:56:26 2009
@@ -66,21 +66,24 @@
 
 ACR_DECLARE(int) ACR_DsoUnload(JNIEnv *_E, int dso)
 {
-    int rv;
-
-    rv = acr_ioh_close(dso);
+    int rc;
 
-    ACR_THROW_IO_IF_ERR(rv);
-    return rv;
+    if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
+        return ACR_EINVAL;
+    }
+    rc = acr_ioh_close(dso);
+    ACR_THROW_IO_IF_ERR(rc);
+    return rc;
 }
 
-ACR_DECLARE(void *) ACR_DsoSym(JNIEnv *_E, int dso, const acr_pchar_t *symname)
+ACR_DECLARE(void *) ACR_DsoSym(JNIEnv *_E, int dso, const char *symname)
 {
     int rc;
     void *handle = ACR_IOH(dso);
 
     if (IS_INVALID_HANDLE(handle) || ACR_IOH_TYPE(dso) != ACR_DT_DSO) {
-        ACR_SET_OS_ERROR(ACR_EINVAL);
+        ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EINVAL);
         return NULL;
     }
     else {
@@ -88,7 +91,7 @@
         if (retval == NULL) {
             rc = ACR_GET_OS_ERROR();
             if (IS_VALID_HANDLE(_E)) {
-                ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EIO, dlerror());
+                ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_ULINK, dlerror());
             }
             ACR_SET_OS_ERROR(rc);
         }

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=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Aug 22 07:56:26 2009
@@ -33,6 +33,7 @@
     "java/lang/InstantiationException",
     "java/lang/InternalError",
     "java/lang/SecurityException",
+    "java/lang/UnsatisfiedLinkError",
     "java/lang/UnsupportedOperationException",
     "java/io/IOException",
     "java/io/SyncFailedException",
@@ -155,7 +156,14 @@
 
 static char *stuffunknown(char *buf, acr_size_t bufsize, int statcode)
 {
-    snprintf(buf, bufsize, "Unrecognized ACR error code %d", statcode);
+    switch (statcode) {
+        case ACR_EFTYPE:
+            strlcpy(buf, "Inappropriate file type or format", bufsize);
+        break;
+        default:
+            snprintf(buf, bufsize, "Unrecognized ACR error code %d", statcode);
+        break;
+    }
     return buf;
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=806805&r1=806804&r2=806805&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Sat Aug 22 07:56:26 2009
@@ -235,6 +235,17 @@
 }
 
 
+static int test_errno(int argc, const char *const argv[])
+{
+    char buf[1024];
+
+    ACR_GetErrorString(ACR_EFTYPE, buf, sizeof(buf));
+    fprintf(stdout, "ACR_EFTYPE     : %s\n", buf);
+
+    fprintf(stdout, "errno:         OK\n");
+    return 0;
+}
+
 int main(int argc, const char *const argv[])
 {
     int rv = 0;
@@ -291,6 +302,9 @@
         else if (!strcasecmp(run_test, "jvm")) {
             rv = test_runjvm(argc, argv);
         }
+        else if (!strcasecmp(run_test, "error")) {
+            rv = test_errno(argc, argv);
+        }
     }
 
 cleanup: