commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r898708 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_private.h include/arch/unix/acr_arch.h include/arch/windows/acr_arch.h shared/callback.c shared/memory.c
Date Wed, 13 Jan 2010 10:39:53 GMT
Author: mturk
Date: Wed Jan 13 10:39:52 2010
New Revision: 898708

URL: http://svn.apache.org/viewvc?rev=898708&view=rev
Log:
Add macro for obtaining the JNIEnv

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=898708&r1=898707&r2=898708&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Wed Jan 13 10:39:52
2010
@@ -294,6 +294,10 @@
 #define IS_JOBJECT_VALID(E, O)  \
         ((O) && !((*(E))->IsSameObject((E), (O), NULL) == JNI_TRUE))
 
+#define IF_ACR_JNI_ENV(E)                                   \
+        if ((E) == NULL)                                    \
+            (E) = ACR_GetJNIEnv();                          \
+        if ((E) != NULL && (E) != INVALID_HANDLE_VALUE)
 
 #define ACR_CLASS_LDEF(CL)  \
     int acr_class_##CL##_load(JNIEnv *_E)

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=898708&r1=898707&r2=898708&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Wed Jan 13
10:39:52 2010
@@ -180,7 +180,7 @@
     char *d = NULL;
     if (s) {
         size_t size = strlen(s);
-        d = (char *)x_malloc(size + 2);
+        d = s_malloc(char, size + 2);
         if (d) {
             memcpy(d, s, size);
             d[size]   = '\0';
@@ -195,7 +195,7 @@
     wchar_t *d = NULL;
     if (s) {
         size_t size = wcslen(s);
-        d = (wchar_t *)x_malloc((size + 2) * sizeof(wchar_t));
+        d = s_malloc(wchar_t, size + 2);
         if (d) {
             memcpy(d, s, size * sizeof(wchar_t));
             d[size]   = L'\0';

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=898708&r1=898707&r2=898708&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Wed Jan
13 10:39:52 2010
@@ -414,7 +414,7 @@
     char *d = NULL;
     if (s) {
         size_t size = strlen(s);
-        d = (char *)x_malloc(size + 2);
+        d = s_malloc(char, size + 2);
         if (d) {
             memcpy(d, s, size);
             d[size]   = '\0';
@@ -429,7 +429,7 @@
     wchar_t *d = NULL;
     if (s) {
         size_t size = wcslen(s);
-        d = (wchar_t *)x_malloc((size + 2) * sizeof(wchar_t));
+        d = s_malloc(wchar_t, size + 2);
         if (d) {
             memcpy(d, s, size * sizeof(wchar_t));
             d[size]   = L'\0';

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/callback.c?rev=898708&r1=898707&r2=898708&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Wed Jan 13 10:39:52 2010
@@ -197,3 +197,4 @@
         return 0;
     }
 }
+

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=898708&r1=898707&r2=898708&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Wed Jan 13 10:39:52 2010
@@ -38,10 +38,9 @@
     void *mem = x_malloc(size);
 
     if (!mem) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, ACR_ENOMEM);
+        }
     }
     return mem;
 }
@@ -52,10 +51,9 @@
     void *mem = x_calloc(size);
 
     if (!mem) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, ACR_ENOMEM);
+        }
     }
     return mem;
 }
@@ -66,10 +64,9 @@
     void *mem = realloc(org, size);
 
     if (!mem) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, ACR_ENOMEM);
+        }
     }
     return mem;
 }
@@ -78,11 +75,10 @@
                            void *mem)
 {
     if (IS_INVALID_HANDLE(mem)) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
+        }
     }
     else
         x_free(mem);
@@ -113,9 +109,10 @@
             if (size > ACR_SIZE_T_MAX) {
                 /* We should fall lot before that.
                  */
-                if (IS_VALID_HANDLE(_E))
+                IF_ACR_JNI_ENV(_E) {
                     ACR_ThrowException(_E, file, line, ACR_EX_EINVAL,
                                        ACR_EINVAL);
+                }
                 ACR_SET_OS_ERROR(ACR_EINVAL);
                 return NULL;
             }
@@ -187,9 +184,10 @@
     if (size > ACR_SIZE_T_MAX) {
         /* We should fail lot before that.
          */
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_EINVAL,
                                ACR_EINVAL);
+        }
         ACR_SET_OS_ERROR(ACR_EINVAL);
         return NULL;
     }
@@ -221,11 +219,10 @@
                                 acr_sbh_t *sbh)
 {
     if (!sbh) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
+        }
         return;
     }
     if (sbh->dpos && sbh->dbuf) {
@@ -243,11 +240,10 @@
                                   acr_sbh_t *sbh)
 {
     if (!sbh) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
+        }
         return;
     }
     ACR_SbhReset(_E, file, line, sbh);
@@ -263,10 +259,9 @@
 
     if (!arr) {
         int err = ACR_GET_OS_ERROR();
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
+        }
         ACR_SET_OS_ERROR(ACR_ENOMEM);
     }
     return arr;
@@ -278,11 +273,10 @@
     void **ptr = arr;
 
     if (IS_INVALID_HANDLE(arr)) {
-        if (_E == NULL)
-            _E = ACR_GetJNIEnv();
-        if (IS_VALID_HANDLE(_E))
+        IF_ACR_JNI_ENV(_E) {
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                 ACR_EISNULL);
+        }
     }
     else {
         while (*ptr != NULL)



Mime
View raw message