commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r766294 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_private.h shared/descriptor.c shared/pointer.c
Date Sat, 18 Apr 2009 10:51:20 GMT
Author: mturk
Date: Sat Apr 18 10:51:19 2009
New Revision: 766294

URL: http://svn.apache.org/viewvc?rev=766294&view=rev
Log:
Use field pointer macros instead duplicating jint/jlong code

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.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=766294&r1=766293&r2=766294&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 Sat Apr 18 10:51:19
2009
@@ -128,7 +128,7 @@
 /* Presume utf32 fits into utf16.
  * TODO: Figure out more optimised way of doing this.
  */
-#define RETURN_JWSTR(V)  ACR_NewJavaStringW(_E, (V))
+#define RETURN_JWSTR(V)  return ACR_NewJavaStringW(_E, (V))
 
 #endif
 
@@ -379,6 +379,29 @@
         else     (*_E)->SetStaticBooleanField(_E, _clazzn.i, _f##I##n.i, JNI_FALSE); 
  \
     } else (void)(0)
 
+#if CC_SIZEOF_VOIDP == 8
+
+#define IFIELD_PTR  "J"
+#define GET_IFIELD_P(I, O)  \
+    _f##I##n.i ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+
+#define SET_IFIELD_P(I, O, V)  \
+    if (_f##I##n.i) {                                                       \
+        (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)(V));               \
+    } else (void)(0)
+
+#else  /* CC_SIZEOF_VOIDP == 4 */
+
+#define IFIELD_PTR  "I"
+#define GET_IFIELD_P(I, O)  \
+    _f##I##n.i ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : 0
+
+#define SET_IFIELD_P(I, O, V)  \
+    if (_f##I##n.i) {                                                       \
+        (*_E)->SetIntField(_E, (O), _f##I##n.i, (jint)(V));                 \
+    } else (void)(0)
+
+#endif /* CC_SIZEOF_VOIDP == 8 */
 
 #define CALL_METHOD1(I, O, V)  \
     if (_m##I##n.i) {                                                       \

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=766294&r1=766293&r2=766294&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Sat Apr 18 10:51:19
2009
@@ -36,24 +36,6 @@
     ACR_CLASS_PATH "Descriptor64"
 };
 
-J_DECLARE_F_ID(0000) = {
-    NULL,
-    "IHANDLE",
-    "I"
-};
-
-J_DECLARE_F_ID(0001) = {
-    NULL,
-    "PHANDLE",
-    "J"
-};
-
-J_DECLARE_F_ID(0002) = {
-    NULL,
-    "CLEANUP",
-    "J"
-};
-
 J_DECLARE_M_ID(0000) = {
     NULL,
     "<init>",
@@ -68,6 +50,14 @@
     ACR_CLASS_PATH "Descriptor32"
 };
 
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(III)V"
+};
+
+#endif
+
 J_DECLARE_F_ID(0000) = {
     NULL,
     "IHANDLE",
@@ -77,23 +67,15 @@
 J_DECLARE_F_ID(0001) = {
     NULL,
     "PHANDLE",
-    "I"
+    IFIELD_PTR
 };
 
 J_DECLARE_F_ID(0002) = {
     NULL,
     "CLEANUP",
-    "I"
+    IFIELD_PTR
 };
 
-J_DECLARE_M_ID(0000) = {
-    NULL,
-    "<init>",
-    "(III)V"
-};
-
-#endif
-
 ACR_CLASS_LDEF(Descriptor)
 {
     int rv;
@@ -125,22 +107,13 @@
 {
     if (_clazzn.i && _m0000n.i) {
         acr_descriptor_callback_fn_t *callback;
-        jint  i = GET_IFIELD_I(0000, _O);
-#if CC_SIZEOF_VOIDP == 8
-        jlong p = GET_IFIELD_J(0001, _O);
-        jlong c = GET_IFIELD_J(0002, _O);
+        jint  i  = GET_IFIELD_I(0000, _O);
+        jniptr p = GET_IFIELD_P(0001, _O);
+        jniptr c = GET_IFIELD_P(0002, _O);
 
         if (p) {
-            SET_IFIELD_J(0001, _O, 0);
+            SET_IFIELD_P(0001, _O, 0);
         }
-#else
-        jint p  = GET_IFIELD_I(0001, _O);
-        jint c  = GET_IFIELD_I(0002, _O);
-
-        if (p) {
-            SET_IFIELD_I(0001, _O, 0);
-        }
-#endif
         if (i >= 0) {
             SET_IFIELD_I(0000, _O, -1);
         }
@@ -162,16 +135,10 @@
 {
     if (_clazzn.i && _m0000n.i) {
         acr_descriptor_callback_fn_t *callback;
-        jint  i = GET_IFIELD_I(0000, _O);
-#if CC_SIZEOF_VOIDP == 8
-        jlong p = GET_IFIELD_J(0001, _O);
-        jlong c = GET_IFIELD_J(0002, _O);
-
-#else
-        jint  p = GET_IFIELD_I(0001, _O);
-        jint  c = GET_IFIELD_I(0002, _O);
+        jint  i  = GET_IFIELD_I(0000, _O);
+        jniptr p = GET_IFIELD_P(0001, _O);
+        jniptr c = GET_IFIELD_P(0002, _O);
 
-#endif
         callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
         if (callback) {
             int rc = (*callback)(ACR_DESC_SYNC, i, (void *)((acr_ptr_t)p));
@@ -204,28 +171,16 @@
 {
     if (_clazzn.i && _m0000n.i) {
         acr_descriptor_callback_fn_t *callback;
-        jint  i = GET_IFIELD_I(0000, _O);
-#if CC_SIZEOF_VOIDP == 8
-        jlong p = GET_IFIELD_J(0001, _O);
-        jlong c = GET_IFIELD_J(0002, _O);
+        jint   i = GET_IFIELD_I(0000, _O);
+        jniptr p = GET_IFIELD_P(0001, _O);
+        jniptr c = GET_IFIELD_P(0002, _O);
 
         if (p) {
-            SET_IFIELD_J(0001, _O, 0);
+            SET_IFIELD_P(0001, _O, 0);
         }
         if (c) {
-            SET_IFIELD_J(0002, _O, 0);
+            SET_IFIELD_P(0002, _O, 0);
         }
-#else
-        jint  p = GET_IFIELD_I(0001, _O);
-        jint  c = GET_IFIELD_I(0002, _O);
-
-        if (p) {
-            SET_IFIELD_I(0001, _O, 0);
-        }
-        if (c) {
-            SET_IFIELD_I(0002, _O, 0);
-        }
-#endif
         if (i >= 0) {
             SET_IFIELD_I(0000, _O, -1);
         }
@@ -251,11 +206,7 @@
 ACR_DECLARE(void *) ACR_DescriptorGetPtr(ACR_JNISTDARGS)
 {
     if (_clazzn.i && _m0000n.i) {
-#if CC_SIZEOF_VOIDP == 8
-        jlong p = GET_IFIELD_J(0001, _O);
-#else
-        jint  p = GET_IFIELD_I(0001, _O);
-#endif
+        jniptr p = GET_IFIELD_P(0001, _O);
         return (void *)((acr_ptr_t)p);
     }
     else {
@@ -278,11 +229,7 @@
 ACR_DECLARE(int) ACR_DescriptorSetPtr(ACR_JNISTDARGS, void *p)
 {
     if (_clazzn.i && _m0000n.i) {
-#if CC_SIZEOF_VOIDP == 8
-        SET_IFIELD_J(0001, _O, (jlong)((acr_ptr_t)p));
-#else
-        SET_IFIELD_I(0001, _O, (jint)((acr_ptr_t)p));
-#endif
+        SET_IFIELD_P(0001, _O, (jniptr)((acr_ptr_t)p));
         if ((*_E)->ExceptionCheck(_E)) {
             return ACR_EGENERAL;
         }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=766294&r1=766293&r2=766294&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Sat Apr 18 10:51:19 2009
@@ -36,18 +36,6 @@
     ACR_CLASS_PATH "Pointer64"
 };
 
-J_DECLARE_F_ID(0000) = {
-    NULL,
-    "POINTER",
-    "J"
-};
-
-J_DECLARE_F_ID(0001) = {
-    NULL,
-    "CLEANUP",
-    "J"
-};
-
 J_DECLARE_M_ID(0000) = {
     NULL,
     "<init>",
@@ -62,25 +50,26 @@
     ACR_CLASS_PATH "Pointer32"
 };
 
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(II)V"
+};
+
+#endif
+
 J_DECLARE_F_ID(0000) = {
     NULL,
     "POINTER",
-    "I"
+    IFIELD_PTR
 };
 
 J_DECLARE_F_ID(0001) = {
     NULL,
     "CLEANUP",
-    "I"
+    IFIELD_PTR
 };
 
-J_DECLARE_M_ID(0000) = {
-    NULL,
-    "<init>",
-    "(II)V"
-};
-
-#endif
 
 ACR_CLASS_LDEF(Pointer)
 {
@@ -112,21 +101,12 @@
 {
     if (_clazzn.i && _m0000n.i) {
         acr_pointer_cleanup_fn_t *cleanup;
-#if CC_SIZEOF_VOIDP == 8
-        jlong h = GET_IFIELD_J(0000, _O);
-        jlong c = GET_IFIELD_J(0001, _O);
-
-        if (h) {
-            SET_IFIELD_J(0000, _O, 0);
-        }
-#else
-        jint h  = GET_IFIELD_I(0000, _O);
-        jint c  = GET_IFIELD_I(0001, _O);
+        jniptr h = GET_IFIELD_P(0000, _O);
+        jniptr c = GET_IFIELD_P(0001, _O);
 
         if (h) {
-            SET_IFIELD_I(0000, _O, 0);
+            SET_IFIELD_P(0000, _O, 0);
         }
-#endif
         cleanup = (acr_pointer_cleanup_fn_t *)((acr_ptr_t)c);
         if (cleanup) {
             int rc = (*cleanup)((void *)((acr_ptr_t)h));
@@ -157,27 +137,15 @@
 {
     if (_clazzn.i && _m0000n.i) {
         acr_pointer_cleanup_fn_t *cleanup;
-#if CC_SIZEOF_VOIDP == 8
-        jlong h = GET_IFIELD_J(0000, _O);
-        jlong c = GET_IFIELD_J(0001, _O);
-
-        if (h) {
-            SET_IFIELD_J(0000, _O, 0);
-        }
-        if (c) {
-            SET_IFIELD_J(0001, _O, 0);
-        }
-#else
-        jint h  = GET_IFIELD_I(0000, _O);
-        jint c  = GET_IFIELD_I(0001, _O);
+        jniptr h = GET_IFIELD_P(0000, _O);
+        jniptr c = GET_IFIELD_P(0001, _O);
 
         if (h) {
-            SET_IFIELD_I(0000, _O, 0);
+            SET_IFIELD_P(0000, _O, 0);
         }
         if (c) {
-            SET_IFIELD_I(0001, _O, 0);
+            SET_IFIELD_P(0001, _O, 0);
         }
-#endif
         cleanup = (acr_pointer_cleanup_fn_t *)((acr_ptr_t)c);
         if (cleanup) {
             int rc = (*cleanup)((void *)((acr_ptr_t)h));
@@ -199,11 +167,7 @@
 ACR_DECLARE(void *) ACR_PointerGet(ACR_JNISTDARGS)
 {
     if (_clazzn.i && _m0000n.i) {
-#if CC_SIZEOF_VOIDP == 8
-        jlong h = GET_IFIELD_J(0000, _O);
-#else
-        jint h  = GET_IFIELD_I(0000, _O);
-#endif
+        jniptr h = GET_IFIELD_P(0000, _O);
         return (void *)((acr_ptr_t)h);
     }
     else {
@@ -215,11 +179,7 @@
 ACR_DECLARE(int) ACR_PointerSet(ACR_JNISTDARGS, void *p)
 {
     if (_clazzn.i && _m0000n.i) {
-#if CC_SIZEOF_VOIDP == 8
-        SET_IFIELD_J(0000, _O, (jlong)((acr_ptr_t)p));
-#else
-        SET_IFIELD_I(0000, _O, (jint)((acr_ptr_t)p));
-#endif
+        SET_IFIELD_P(0000, _O, (jniptr)((acr_ptr_t)p));
         if ((*_E)->ExceptionCheck(_E)) {
             return ACR_EGENERAL;
         }



Mime
View raw message