commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1095920 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/jnidefs.h os/unix/posixapi.c os/unix/shmem.c shared/memory.c shared/pointer.c
Date Fri, 22 Apr 2011 10:45:33 GMT
Author: mturk
Date: Fri Apr 22 10:45:32 2011
New Revision: 1095920

URL: http://svn.apache.org/viewvc?rev=1095920&view=rev
Log:
Use better cast macros

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.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=1095920&r1=1095919&r2=1095920&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 Fri Apr 22 10:45:32
2011
@@ -53,22 +53,19 @@
 #define UNREFERENCED_STDARGS    (void)env; (void)obj
 #define UNREFERENCED_OBJECT     (void)obj
 
-#define IPTR(X)                 ((intptr_t)(X))
 #if CC_SIZEOF_VOIDP == 8
-#define P2J(P)                  ((jlong)IPTR(P))
-#define J2P(P, T)               ((T)IPTR(P))
-#define J2V(P)                  ((void *)IPTR(P))
-#define I2P(P, T)               ((T)(IPTR(P)      & ACR_I64_C(0x00000000FFFFFFFF)))
-#define I2V(P)                  ((void *)(IPTR(P) & ACR_I64_C(0x00000000FFFFFFFF)))
+#define IPTR(X)                 ((intptr_t)(X))
+#define P2J(P)                  ((jlong)(P))
+#define J2P(P, T)               ((T)(intptr_t)(P))
+#define J2V(P)                  ((void *)(intptr_t)(P))
 #else
-#define P2J(P)                  ((jlong)IPTR(P)   & ACR_I64_C(0x00000000FFFFFFFF))
-#define J2P(P, T)               ((T)(IPTR(P)      & ACR_I64_C(0x00000000FFFFFFFF)))
-#define J2V(P)                  ((void *)(IPTR(P) & ACR_I64_C(0x00000000FFFFFFFF)))
-#define I2P(P, T)               ((T)(IPTR(P))
-#define I2V(I)                  ((void *)IPTR(I))
+#define IPTR(X)                 ((intptr_t)(X))
+#define P2J(P)                  (((jlong)(intptr_t)(P)) & ACR_I64_C(0x00000000FFFFFFFF))
+#define J2P(P, T)               ((T)(intptr_t)(P))
+#define J2V(P)                  ((void *)(intptr_t)(P))
 #endif
-#define V2I(P)                  ((int)IPTR(P))
-#define V2U(P)                  ((unsigned int)IPTR(P))
+#define V2I(P)                  ((int)(intptr_t)(P))
+#define V2U(P)                  ((unsigned int)(intptr_t)(P))
 #define V2Z(X)                  ((X) ? JNI_TRUE : JNI_FALSE)
 #define INVALID_FIELD_OFFSET    (-1)
 #define INVALID_FIELD_BASE      (-1)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c?rev=1095920&r1=1095919&r2=1095920&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c Fri Apr 22 10:45:32 2011
@@ -159,7 +159,6 @@ ACR_UNX_EXPORT(jlong, Posix,  mmap)(JNI_
                                     jint prot, jint flags, jint fd, jlong offset)
 {
     void *base = 0;
-    void *mem  = J2P(addr, void *);
     int mflags = 0;
     int mmprot = 0;
 
@@ -183,7 +182,7 @@ ACR_UNX_EXPORT(jlong, Posix,  mmap)(JNI_
     if (flags & 0x08)
         mflags |= MAP_EXECUTABLE;
 
-    base = mmap(mem, (size_t)size, mmprot, mflags, fd, offset);
+    base = mmap(J2V(addr), (size_t)size, mmprot, mflags, fd, offset);
     if (base == MAP_FAILED) {
         ACR_SAVE_OS_ERROR();
         return 0;
@@ -193,12 +192,11 @@ ACR_UNX_EXPORT(jlong, Posix,  mmap)(JNI_
 
 ACR_UNX_EXPORT(jint, Posix,  munmap)(JNI_STDARGS, jlong addr, jlong size)
 {
-    void *mem = J2P(addr, void *);
 
     if (size > SIZE_T_MAX)
         return ACR_EOVERFLOW;
 
-    if (munmap(mem, (size_t)size) == 0)
+    if (munmap(J2V(addr), (size_t)size) == 0)
         return 0;
     else
         return ACR_GET_OS_ERROR();
@@ -206,7 +204,6 @@ ACR_UNX_EXPORT(jint, Posix,  munmap)(JNI
 
 ACR_UNX_EXPORT(jint, Posix,  msync)(JNI_STDARGS, jlong addr, jlong length, jint flags)
 {
-    void *mem = J2P(addr, void *);
     int   mflags = 0;
 
     if (length > SIZE_T_MAX)
@@ -219,7 +216,7 @@ ACR_UNX_EXPORT(jint, Posix,  msync)(JNI_
     if (flags & 0x04)
         mflags |= MS_INVALIDATE;
     
-    if (msync(mem, (size_t)length, mflags) == 0)
+    if (msync(J2V(addr), (size_t)length, mflags) == 0)
         return 0;
     else
         return ACR_GET_OS_ERROR();

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c?rev=1095920&r1=1095919&r2=1095920&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c Fri Apr 22 10:45:32 2011
@@ -166,7 +166,7 @@ cleanup:
 ACR_UNX_EXPORT(jlong, PosixShm, shmat0)(JNI_STDARGS, jlong addr, jint fd,
                                         jboolean ro)
 {
-    void   *sa = J2P(addr, void *);
+    void   *sa = J2V(addr);
     void   *sm;
     int     flags = ro ? SHM_RDONLY : 0;
 
@@ -179,7 +179,7 @@ ACR_UNX_EXPORT(jlong, PosixShm, shmat0)(
 
 ACR_UNX_EXPORT(jint, PosixShm, shmdt0)(JNI_STDARGS, jlong addr)
 {
-    void *sa = J2P(addr, void *);
+    void *sa = J2V(addr);
 
     if (shmdt(sa) == 0)
         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=1095920&r1=1095919&r2=1095920&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Apr 22 10:45:32 2011
@@ -297,7 +297,7 @@ ACR_JNI_EXPORT(jobject, Memory, calloc)(
 
 ACR_JNI_EXPORT(jlong, Memory, realloc0)(JNI_STDARGS, jlong ptr, jlong siz)
 {
-    void   *mem = J2P(ptr, void *);
+    void   *mem = J2V(ptr);
     jlong   sza = ACR_ALIGN_DEFAULT(siz);
 
     if (sza < 1 || sza > SIZE_T_MAX) {
@@ -313,7 +313,7 @@ ACR_JNI_EXPORT(jlong, Memory, realloc0)(
 
 ACR_JNI_EXPORT(void, Memory, free)(JNI_STDARGS, jlong ptr)
 {
-    AcrFree(J2P(ptr, void *));
+    AcrFree(J2V(ptr));
 }
 
 ACR_JNI_EXPORT(jint, Memory, peek0)(JNI_STDARGS, jlong a)

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=1095920&r1=1095919&r2=1095920&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Apr 22 10:45:32 2011
@@ -91,7 +91,7 @@ AcrNewHeapPointer(JNI_STDENV, void *ptr,
 
 ACR_JNI_EXPORT(void, HeapPointer, free0)(JNI_STDARGS, jlong ptr)
 {
-    AcrFree(J2P(ptr, void *));
+    AcrFree(J2V(ptr));
 }
 
 void *
@@ -105,7 +105,7 @@ AcrGetPointer(JNI_STDARGS)
         char *oa = *(char **)obj;
         if (oa != 0) {
             char *pa = oa + UNSAFE_FLD_OFF(0000);
-            return J2P(*((jlong *)pa), void *);
+            return J2V(*((jlong *)pa));
         }
     }
     /* Fallback to a traditional method.
@@ -165,7 +165,7 @@ ACR_UNX_EXPORT(jobject, Posix,  pointer)
 #endif
 (JNI_STDARGS, jlong addr, jlong length, jint type)
 {
-    void *memptr = J2P(addr, void *);
+    void *memptr = J2V(addr);
     size_t size  = (size_t)length;
 
     switch (type) {



Mime
View raw message