commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1085661 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/jnidefs.h include/acr/jnimacros.h include/acr/jnitypes.h shared/clazz.c shared/object.c shared/string.c shared/unsafe.c
Date Sat, 26 Mar 2011 07:30:29 GMT
Author: mturk
Date: Sat Mar 26 07:30:29 2011
New Revision: 1085661

URL: http://svn.apache.org/viewvc?rev=1085661&view=rev
Log:
Simplify method access macros

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/object.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Sat Mar 26 07:30:29
2011
@@ -79,8 +79,7 @@
 #define J_DECLARE_M_ID(I)       static JAVA_M_ID _m##I##n
 #define J4MID(I)                _m##I##n.i
 
-#define CLAZZ_LOADED()          (_clazzn.i != 0 && _m0000n.i != 0)
-#define CLAZZ_NOT_LOADED()      (_clazzn.i == 0 || _m0000n.i == 0)
+#define CLAZZ_LOADED            (_clazzn.u != 0)
 
 #define UTF8_TO_JSTRING(V)      AcrNewJavaStringU(_E, (const char *)(V))
 #define CSTR_TO_JSTRING(V)      AcrNewJavaStringA(_E, (const char *)(V))

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h Sat Mar 26 07:30:29
2011
@@ -25,10 +25,10 @@
 #include "acr/stddefs.h"
 
 #define IS_JOBJECT_NULL(E, O)  \
-        (!(O) || ((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
+        ((O) == 0 || ((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
 
 #define IS_JOBJECT_VALID(E, O)  \
-        ((O) && !((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
+        ((O) != 0 && ((*(E))->IsSameObject((E), (O), 0) == JNI_FALSE))
 
 #define J_LOAD_METHOD(I)    \
     if (_m##I##n.i == 0) {                                                  \
@@ -68,148 +68,113 @@
 
 
 #define GET_IFIELD_J(I, O)  \
-    (_f##I##n.i && (O)) ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+    (*_E)->GetLongField(_E, (O), _f##I##n.i)
 
 #define GET_IFIELD_I(I, O)  \
-    (_f##I##n.i && (O)) ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : 0
-
-#define GET_DFIELD_I(I, O, D)  \
-    (_f##I##n.i && (O)) ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : (D)
+    (*_E)->GetIntField(_E, (O), _f##I##n.i)
 
 #define GET_IFIELD_O(I, O)  \
-    (_f##I##n.i && (O)) ? (*_E)->GetObjectField(_E, (O), _f##I##n.i) : 0
+    (*_E)->GetObjectField(_E, (O), _f##I##n.i)
 
 #define GET_SFIELD_O(I, C)  \
-    (_f##I##n.i && (C)) ? (*_E)->GetStaticObjectField(_E, (C), _f##I##n.i) : 0
+    (*_E)->GetStaticObjectField(_E, (C), _f##I##n.i)
 
-#define SET_IFIELD_J(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                \
-        (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)(V));               \
-    } else (void)(0)
+#define SET_IFIELD_J(I, O, V) \
+    (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)(V))
 
-#define SET_IFIELD_I(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                \
-        (*_E)->SetIntField(_E, (O), _f##I##n.i, (jint)(V));                 \
-    } else (void)(0)
+#define SET_IFIELD_I(I, O, V) \
+    (*_E)->SetIntField(_E, (O), _f##I##n.i, (jint)(V))
 
-#define SET_IFIELD_D(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                \
-        (*_E)->SetDoubleField(_E, (O), _f##I##n.i, (jdouble)(V));           \
-    } else (void)(0)
+#define SET_IFIELD_D(I, O, V) \
+    (*_E)->SetDoubleField(_E, (O), _f##I##n.i, (jdouble)(V))
 
 #define SET_IFIELD_Z(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                \
-        if ((V)) (*_E)->SetBooleanField(_E, (O), _f##I##n.i, JNI_TRUE);     \
-        else     (*_E)->SetBooleanField(_E, (O), _f##I##n.i, JNI_FALSE);    \
-    } else (void)(0)
+    (*_E)->SetBooleanField(_E, (O), _f##I##n.i, (V) ? JNI_TRUE : JNI_FALSE)
 
 #define SET_IFIELD_S(I, O, V)  \
-    if (_f##I##n.i && (V) && (O)) {                                     
   \
+    if ((V)) {                                                              \
         jstring _str = ACR_NewJavaStringA(_E, (V));                         \
         (*_E)->SetObjectField(_E, (O), _f##I##n.i, _str);                   \
         (*_E)->DeleteLocalRef(_E, _str);                                    \
     } else (void)(0)
 
 #define SET_IFIELD_N(I, O, V)  \
-    if (_f##I##n.i && (V) && *(V) && (O)) {                     
           \
+    if ((V) && *(V)) {                                                      \
         jstring _str = ACR_NewJavaStringA(_E, (V));                         \
         (*_E)->SetObjectField(_E, (O), _f##I##n.i, _str);                   \
         (*_E)->DeleteLocalRef(_E, _str);                                    \
     } else (void)(0)
 
 #define SET_IFIELD_W(I, O, V)  \
-    if (_f##I##n.i && (V) && (O)) {                                     
   \
+    if ((V)) {                                                              \
         jstring _str = ACR_NewJavaStringW(_E, (V));                         \
         (*_E)->SetObjectField(_E, (O), _f##I##n.i, _str);                   \
         (*_E)->DeleteLocalRef(_E, _str);                                    \
     } else (void)(0)
 
 #define SET_IFIELD_C(I, O, V)  \
-    if (_f##I##n.i && (V) && *(V) && (O)) {                     
           \
+    if ((V) && *(V)) {                                                      \
         jstring _str = ACR_NewJavaStringW(_E, (V));                         \
         (*_E)->SetObjectField(_E, (O), _f##I##n.i, _str);                   \
         (*_E)->DeleteLocalRef(_E, _str);                                    \
     } else (void)(0)
 
 #define SET_IFIELD_O(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                \
-        (*_E)->SetObjectField(_E, (O), _f##I##n.i, (jobject)(V));           \
-    } else (void)(0)
+    (*_E)->SetObjectField(_E, (O), _f##I##n.i, (jobject)(V))
 
 #define SET_SFIELD_Z(I, V)  \
-    if (_f##I##n.i && (O)) {                                                    
       \
-        if ((V)) (*_E)->SetStaticBooleanField(_E, _clazzn.i, _f##I##n.i, JNI_TRUE);  
  \
-        else     (*_E)->SetStaticBooleanField(_E, _clazzn.i, _f##I##n.i, JNI_FALSE); 
  \
-    } else (void)(0)
+    (*_E)->SetStaticBooleanField(_E, _clazzn.i, _f##I##n.i, (V) ? JNI_TRUE : JNI_FALSE)
 
 #define GET_IFIELD_P(I, O, T)  \
-    (_f##I##n.i && (O)) ? (T)(*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+    (T)(*_E)->GetLongField(_E, (O), _f##I##n.i)
 
 #define GET_IFIELD_V(I, O, T)  \
-    (_f##I##n.i && (O)) ? (T)((acr_ssize_t)(*_E)->GetLongField(_E, (O),      \
-                              _f##I##n.i)) : NULL
+    (T)((ptrdiff_t)(*_E)->GetLongField(_E, (O), _f##I##n.i)
 
 #define SET_IFIELD_P(I, O, V)  \
-    if (_f##I##n.i && (O)) {                                                 \
-        (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)((acr_ssize_t)(V))); \
-    } else (void)(0)
-
+    (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)((ptrdiff_t)(V)))
 
 #define CALL_VMETHOD0(I, O)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallVoidMethod(_E, (O), _m##I##n.i);                         \
-    } else (void)(0)
+    (*_E)->CallVoidMethod(_E, (O), _m##I##n.i)
 
 #define CALL_VMETHOD1(I, O, A)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A));                    \
-    } else (void)(0)
+    (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A))
 
 #define CALL_VMETHOD2(I, O, A1, A2)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2));             \
-    } else (void)(0)
+    (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2))
 
 #define CALL_VMETHOD3(I, O, A1, A2, A3)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2), (A3));       \
-    } else (void)(0)
+    (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2), (A3))
 
 #define CALL_METHOD0(T, I, O)  \
-        (*_E)->Call##T##Method(_E, (O), _m##I##n.i)
+    (*_E)->Call##T##Method(_E, (O), _m##I##n.i)
 
 #define CALL_METHOD1(T, I, O, A)  \
-        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A))
+    (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A))
 
 #define CALL_METHOD2(T, I, O, A1, A2)  \
-        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2))
+    (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2))
 
 #define CALL_METHOD3(T, I, O, A1, A2, A3)  \
-        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2), (A3))
+    (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2), (A3))
 
 #define CALL_MLOCAL0(T, I)  \
-        (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i)
+    (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i)
 
 #define CALL_MLOCAL1(T, I, A)  \
-        (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A))
+    (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A))
 
 #define CALL_MLOCAL2(T, I, A1, A2)  \
-        (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A1), (A2))
+    (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A1), (A2))
 
 #define CALL_VMLOCAL0(I)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i);             \
-    } else (void)(0)
+    (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i)
 
 #define CALL_VMLOCAL1(I, A)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A));        \
-    } else (void)(0)
+    (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A))
 
 #define CALL_VMLOCAL2(I, A1, A2)  \
-    if (_m##I##n.i) {                                                       \
-        (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A1), (A2)); \
-    } else (void)(0)
+    (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A1), (A2))
 
 #define SET_SARRAY_A(A, I, V)                               \
     if ((A) && (V)) {                                       \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h Sat Mar 26 07:30:29
2011
@@ -28,6 +28,7 @@
 
 typedef struct JAVA_C_ID {
     int          o;
+    int          u;
     jclass       i;
     jclass       a;
     const char  *n;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sat Mar 26 07:30:29 2011
@@ -23,6 +23,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
+    0,
     "java/lang/Class"
 };
 
@@ -173,6 +174,7 @@ ACR_CLASS_CTOR(Class)
     J_LOAD_METHOD(0013);
     J_LOAD_METHOD(0014);
 
+    _clazzn.u = 1;
     return 0;
 }
 
@@ -338,7 +340,7 @@ AcrClassGetFlags(JNI_STDARGS)
     if (IS_JOBJECT_NULL(_E, _O))
         return 0;
 
-    if (CLAZZ_LOADED()) {
+    if (CLAZZ_LOADED) {
         if (CALL_METHOD0(Boolean, 0006, _O) == JNI_TRUE)
             flags |= ACR_CLASS_ANNOTATION;
         if (CALL_METHOD0(Boolean, 0007, _O) == JNI_TRUE)
@@ -368,7 +370,7 @@ AcrClassGetName(JNI_STDARGS, int simple)
     if (IS_JOBJECT_NULL(_E, _O))
         return 0;
 
-    if (CLAZZ_LOADED()) {
+    if (CLAZZ_LOADED) {
         jstring sn;
         if (simple)
              sn = CALL_METHOD0(Object, 0001, _O);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Sat Mar 26 07:30:29 2011
@@ -22,6 +22,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
+    0,
     "java/lang/Object"
 };
 
@@ -88,6 +89,7 @@ ACR_CLASS_CTOR(Object)
     J_LOAD_METHOD(0006);
     J_LOAD_METHOD(0007);
 
+    _clazzn.u = 1;
     return 0;
 }
 
@@ -103,7 +105,7 @@ AcrObjectNotify(JNI_STDARGS)
 
     if (IS_JOBJECT_NULL(_E, _O))
         return ACR_EINVAL;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD0(0001, _O);
         if ((*_E)->ExceptionCheck(_E)) {
             (*_E)->ExceptionClear(_E);
@@ -122,7 +124,7 @@ AcrObjectNotifyAll(JNI_STDARGS)
 
     if (IS_JOBJECT_NULL(_E, _O))
         return ACR_EINVAL;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD0(0002, _O);
         if ((*_E)->ExceptionCheck(_E)) {
             (*_E)->ExceptionClear(_E);
@@ -141,7 +143,7 @@ AcrObjectWait0(JNI_STDARGS)
 
     if (IS_JOBJECT_NULL(_E, _O))
         return ACR_EINVAL;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD0(0005, _O);
         if ((*_E)->ExceptionCheck(_E)) {
             (*_E)->ExceptionClear(_E);
@@ -160,7 +162,7 @@ AcrObjectWait1(JNI_STDARGS, jlong ms)
 
     if (IS_JOBJECT_NULL(_E, _O))
         return ACR_EINVAL;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD1(0003, _O, ms);
         if ((*_E)->ExceptionCheck(_E)) {
             (*_E)->ExceptionClear(_E);
@@ -179,7 +181,7 @@ AcrObjectWait2(JNI_STDARGS, jlong ms, ji
 
     if (IS_JOBJECT_NULL(_E, _O))
         return ACR_EINVAL;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD2(0004, _O, ms, ns);
         if ((*_E)->ExceptionCheck(_E)) {
             (*_E)->ExceptionClear(_E);
@@ -196,7 +198,7 @@ AcrObjectFinalize(JNI_STDARGS)
 {
     if (IS_JOBJECT_NULL(_E, _O))
         return;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         CALL_VMETHOD0(0006, _O);
     }
 }
@@ -226,7 +228,7 @@ AcrObjectGetClass(JNI_STDARGS)
 
     if (IS_JOBJECT_NULL(_E, _O))
         return c;
-    if (_clazzn.i && J4MID(0000)) {
+    if (CLAZZ_LOADED) {
         c = CALL_METHOD0(Object, 0007, _O);
     }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sat Mar 26 07:30:29 2011
@@ -22,6 +22,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
+    0,
     "java/lang/String"
 };
 
@@ -46,6 +47,7 @@ ACR_CLASS_CTOR(String)
     J_LOAD_METHOD(0000);
     J_LOAD_METHOD(0001);
 
+    _clazzn.u = 1;
     return 0;
 }
 
@@ -703,7 +705,7 @@ static char *get_string_default(JNIEnv *
     jbyteArray sb = 0;
     char *rs = 0;
 
-    if (CLAZZ_NOT_LOADED()) {
+    if (!CLAZZ_LOADED) {
         ACR_SET_OS_ERROR(ACR_EINIT);
         return 0;
     }
@@ -736,6 +738,10 @@ static jstring new_string_default(JNIEnv
     jbyteArray ba;
     jsize      sl;
 
+    if (!CLAZZ_LOADED) {
+        ACR_SET_OS_ERROR(ACR_EINIT);
+        return 0;
+    }
     sl = (jsize)strlen(str);
     ba = (*_E)->NewByteArray(_E, sl);
     if (ba != 0) {
@@ -750,27 +756,25 @@ static jstring new_string_default(JNIEnv
 static jstring new_string_iso_8859_1(JNIEnv *_E, const char *s)
 {
     jstring rs = 0;
+    jsize l = (jsize)strlen(s);
 
-    if (s != 0) {
-        jsize l = (jsize)strlen(s);
-        if (l < ACR_MBUFF_SIZ) {
-            jchar  cc[ACR_MBUFF_SIZ];
-            jsize  i;
+    if (l < ACR_MBUFF_SIZ) {
+        jchar  cc[ACR_MBUFF_SIZ];
+        jsize  i;
+        for (i = 0; i < l; i++) {
+            cc[i] = s[i];
+        }
+        rs = (*_E)->NewString(_E, cc, l);
+    }
+    else {
+        jchar  *cc;
+        if ((cc = ACR_MALLOC(jchar, l + 1)) != 0) {
+            size_t  i;
             for (i = 0; i < l; i++) {
                 cc[i] = s[i];
             }
             rs = (*_E)->NewString(_E, cc, l);
-        }
-        else {
-            jchar  *cc;
-            if ((cc = ACR_MALLOC(jchar, l + 1))) {
-                size_t  i;
-                for (i = 0; i < l; i++) {
-                    cc[i] = s[i];
-                }
-                rs = (*_E)->NewString(_E, cc, l);
-                AcrFree(cc);
-            }
+            AcrFree(cc);
         }
     }
     return rs;
@@ -779,28 +783,26 @@ static jstring new_string_iso_8859_1(JNI
 static jstring new_string_utf_8(JNIEnv *_E, const char *s)
 {
     jstring rs = 0;
+    int ex;
+    jsize sl = (jsize)strlen(s);
 
-    if (s != 0) {
-        int ex;
-        jsize sl = (jsize)strlen(s);
-        if (sl < ACR_MBUFF_SIZ) {
-            jchar  cc[ACR_MBUFF_SIZ];
-            jsize  wl = ACR_MBUFF_LEN;
+    if (sl < ACR_MBUFF_SIZ) {
+        jchar  cc[ACR_MBUFF_SIZ];
+        jsize  wl = ACR_MBUFF_LEN;
+        if ((ex = conv_utf8_to_ucs2(s, sl, cc, &wl)) == ACR_SUCCESS)
+            rs = (*_E)->NewString(_E, cc, sl);
+        else
+            ACR_THROW_EX(ACR_EX_EINVAL, ex);
+    }
+    else {
+        jchar  *cc;
+        if ((cc = ACR_MALLOC(jchar, sl + 1)) != 0) {
+            jsize wl = sl;
             if ((ex = conv_utf8_to_ucs2(s, sl, cc, &wl)) == ACR_SUCCESS)
                 rs = (*_E)->NewString(_E, cc, sl);
             else
                 ACR_THROW_EX(ACR_EX_EINVAL, ex);
-        }
-        else {
-            jchar  *cc;
-            if ((cc = ACR_MALLOC(jchar, sl + 1))) {
-                jsize wl = sl;
-                if ((ex = conv_utf8_to_ucs2(s, sl, cc, &wl)) == ACR_SUCCESS)
-                    rs = (*_E)->NewString(_E, cc, sl);
-                else
-                    ACR_THROW_EX(ACR_EX_EINVAL, ex);
-                AcrFree(cc);
-            }
+            AcrFree(cc);
         }
     }
     return rs;
@@ -833,7 +835,7 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
         }
     }
     sr = (*_E)->GetStringCritical(_E, str, 0);
-    if (!sr) {
+    if (sr == 0) {
         if (rv != b)
             AcrFree(rv);
         return 0;
@@ -914,7 +916,8 @@ jstring
 AcrNewJavaStringA(JNIEnv *_E, const char *str)
 {
     jstring rv = 0;
-    if (!str)
+
+    if (str == 0)
         return 0;
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
@@ -937,7 +940,7 @@ AcrNewJavaStringA(JNIEnv *_E, const char
 jstring
 AcrNewJavaStringU(JNIEnv *_E, const char *str)
 {
-    if (!str)
+    if (str == 0)
         return 0;
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c?rev=1085661&r1=1085660&r2=1085661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Sat Mar 26 07:30:29 2011
@@ -22,6 +22,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
+    0,
     "sun/misc/Unsafe"
 };
 
@@ -77,6 +78,7 @@ ACR_CLASS_CTOR(Unsafe)
     J_LOAD_METHOD(0003);
     J_LOAD_METHOD(0004);
 
+    _clazzn.u = 1;
     return 0;
 }
 
@@ -90,7 +92,7 @@ static jobject _unsafe_instance = 0;
 ACR_INLINE(jobject)
 _get_unsafe(JNI_STDENV)
 {
-    if (_unsafe_instance == 0 && _clazzn.i != 0) {
+    if (_unsafe_instance == 0 && CLAZZ_LOADED) {
         _unsafe_instance = GET_SFIELD_O(0000, _clazzn.i);
     }
     return _unsafe_instance;
@@ -144,6 +146,8 @@ AcrUnsafeObjectFieldIdOffset(JNI_STDENV,
     jobject fld;
     int     off = 0;
 
+    if (!CLAZZ_LOADED)
+        return 0;
     fld = (*_E)->ToReflectedField(_E, cls, fid, JNI_FALSE);
     if (fld != 0) {
         off = AcrUnsafeObjectFieldOffset(_E, fld);
@@ -158,6 +162,8 @@ AcrUnsafeStaticFieldIdOffset(JNI_STDENV,
     jobject fld;
     int     off = 0;
 
+    if (!CLAZZ_LOADED)
+        return 0;
     fld = (*_E)->ToReflectedField(_E, cls, fid, JNI_TRUE);
     if (fld != 0) {
         off = AcrUnsafeStaticFieldOffset(_E, fld);



Mime
View raw message