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/05/25 13:52:10 UTC

svn commit: r778397 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_private.h shared/descriptor.c

Author: mturk
Date: Mon May 25 11:52:10 2009
New Revision: 778397

URL: http://svn.apache.org/viewvc?rev=778397&view=rev
Log:
Test the provided jobject for NULL with GET and SET macros

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.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=778397&r1=778396&r2=778397&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 Mon May 25 11:52:10 2009
@@ -334,70 +334,73 @@
 
 
 #define GET_IFIELD_J(I, O)  \
-    _f##I##n.i ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+    (_f##I##n.i && (O)) ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
 
 #define GET_IFIELD_I(I, O)  \
-    _f##I##n.i ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : 0
+    (_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)
 
 #define GET_IFIELD_O(I, O)  \
-    _f##I##n.i ? (*_E)->GetObjectField(_E, (O), _f##I##n.i) : NULL
+    (_f##I##n.i && (O)) ? (*_E)->GetObjectField(_E, (O), _f##I##n.i) : NULL
 
 #define SET_IFIELD_J(I, O, V)  \
-    if (_f##I##n.i) {                                                       \
+    if (_f##I##n.i && (O)) {                                                \
         (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)(V));               \
     } else (void)(0)
 
 #define SET_IFIELD_I(I, O, V)  \
-    if (_f##I##n.i) {                                                       \
+    if (_f##I##n.i && (O)) {                                                \
         (*_E)->SetIntField(_E, (O), _f##I##n.i, (jint)(V));                 \
     } else (void)(0)
 
 #define SET_IFIELD_D(I, O, V)  \
-    if (_f##I##n.i) {                                                       \
+    if (_f##I##n.i && (O)) {                                                \
         (*_E)->SetDoubleField(_E, (O), _f##I##n.i, (jdouble)(V));           \
     } else (void)(0)
 
 #define SET_IFIELD_Z(I, O, V)  \
-    if (_f##I##n.i) {                                                       \
+    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)
 
 #define SET_IFIELD_S(I, O, V)  \
-    if (_f##I##n.i && (V)) {                                                \
+    if (_f##I##n.i && (V) && (O)) {                                         \
         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)) {                                        \
+    if (_f##I##n.i && (V) && *(V) && (O)) {                                 \
         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)) {                                                \
+    if (_f##I##n.i && (V) && (O)) {                                         \
         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)) {                                        \
+    if (_f##I##n.i && (V) && *(V) && (O)) {                                 \
         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) {                                                       \
+    if (_f##I##n.i && (O)) {                                                \
         (*_E)->SetObjectField(_E, (O), _f##I##n.i, (jobject)(V));           \
     } else (void)(0)
 
 #define SET_SFIELD_Z(I, V)  \
-    if (_f##I##n.i) {                                                                   \
+    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)
@@ -406,12 +409,13 @@
 
 #define IFIELD_PTR  "J"
 #define GET_IFIELD_P(I, O)  \
-    _f##I##n.i ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+    (_f##I##n.i && (O)) ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
 #define GET_IFIELD_V(I, O, T)  \
-    _f##I##n.i ? (T)((acr_ssize_t)(*_E)->GetLongField(_E, (O), _f##I##n.i)) : NULL
+    (_f##I##n.i && (O)) ? (T)((acr_ssize_t)(*_E)->GetLongField(_E, (O),      \
+                              _f##I##n.i)) : NULL
 
 #define SET_IFIELD_P(I, O, V)  \
-    if (_f##I##n.i) {                                                        \
+    if (_f##I##n.i && (O)) {                                                 \
         (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)((acr_ssize_t)(V))); \
     } else (void)(0)
 
@@ -419,12 +423,13 @@
 
 #define IFIELD_PTR  "I"
 #define GET_IFIELD_P(I, O)  \
-    _f##I##n.i ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : 0
+    (_f##I##n.i && (O)) ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : 0
 #define GET_IFIELD_V(I, O, T)  \
-    _f##I##n.i ? (T)((acr_ssize_t)(*_E)->GetIntField(_E, (O), _f##I##n.i)) : NULL
+    (_f##I##n.i && (O)) ? (T)((acr_ssize_t)(*_E)->GetIntField(_E, (O),      \
+                              _f##I##n.i)) : NULL
 
 #define SET_IFIELD_P(I, O, V)  \
-    if (_f##I##n.i) {                                                       \
+    if (_f##I##n.i && (O)) {                                                \
         (*_E)->SetIntField(_E, (O), _f##I##n.i, (jint)((acr_ssize_t)(V)));  \
     } else (void)(0)
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=778397&r1=778396&r2=778397&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Mon May 25 11:52:10 2009
@@ -260,8 +260,6 @@
 
 ACR_DECLARE(void *) ACR_DescriptorGetPtr(ACR_JNISTDARGS)
 {
-    if (_O == NULL)
-        return NULL;
     if (_clazzn.i && J4MID(0000)) {
         return GET_IFIELD_V(0001, _O, void *);
     }
@@ -273,10 +271,8 @@
 
 ACR_DECLARE(int) ACR_DescriptorGetInt(ACR_JNISTDARGS)
 {
-    if (_O == NULL)
-        return -1;
     if (_clazzn.i && J4MID(0000)) {
-        return GET_IFIELD_I(0000, _O);
+        return GET_DFIELD_I(0000, _O, -1);
     }
     else {
         ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
@@ -302,13 +298,13 @@
     }
     else {
         ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
-        return -1;
+        return 0;
     }
 }
 
 ACR_DECLARE(int) ACR_DescriptorSetPtr(ACR_JNISTDARGS, void *p)
 {
-    if (_clazzn.i && J4MID(0000)) {
+    if (_clazzn.i && J4MID(0000) && _O) {
         if ((*_E)->MonitorEnter(_E, _O)) {
             /* Object locking failed */
             return ACR_ENOLOCK;
@@ -324,7 +320,7 @@
 
 ACR_DECLARE(int) ACR_DescriptorSetInt(ACR_JNISTDARGS, int i)
 {
-    if (_clazzn.i && J4MID(0000)) {
+    if (_clazzn.i && J4MID(0000) && _O) {
         if ((*_E)->MonitorEnter(_E, _O)) {
             /* Object locking failed */
             return ACR_ENOLOCK;