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/04/23 18:19:04 UTC

svn commit: r767957 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Pointer.java java/org/apache/commons/runtime/Pointer32.java java/org/apache/commons/runtime/Pointer64.java native/shared/pointer.c

Author: mturk
Date: Thu Apr 23 16:19:03 2009
New Revision: 767957

URL: http://svn.apache.org/viewvc?rev=767957&view=rev
Log:
Some optimisations

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=767957&r1=767956&r2=767957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Thu Apr 23 16:19:03 2009
@@ -101,9 +101,10 @@
      * @return a {@code byte} at {@code index}.
      * @throws IndexOutOfBoundsException if {@code index} would cause access
      *          outside the pointer address space.
+     * @thrown NullPointerException if pointer is {@code null}.
      */
     public abstract int peek(int index)
-        throws IndexOutOfBoundsException;
+        throws IndexOutOfBoundsException, NullPointerException;
 
     /**
      * Set a {@code byte} value to this {@code pointer} at the
@@ -112,9 +113,10 @@
      * @param value Value to set at {@code index}.
      * @throws IndexOutOfBoundsException if {@code index} would cause access
      *          outside the pointer address space.
+     * @thrown NullPointerException if pointer is {@code null}.
      */
     public abstract void poke(int index, int value)
-        throws IndexOutOfBoundsException;
+        throws IndexOutOfBoundsException, NullPointerException;
 
     /**
      * Returns a string representation of the Pointer.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=767957&r1=767956&r2=767957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Thu Apr 23 16:19:03 2009
@@ -62,9 +62,11 @@
     private static native int  peek0(int addr);
 
     public int peek(int index)
-        throws IndexOutOfBoundsException
+        throws IndexOutOfBoundsException, NullPointerException
     {
-        if (index < 0 || index >= PLENGTH)
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
         return peek0(POINTER + index);
     }
@@ -72,9 +74,11 @@
     private static native void  poke0(int addr, int b);
 
     public void poke(int index, int value)
-        throws IndexOutOfBoundsException
+        throws IndexOutOfBoundsException, NullPointerException
     {
-        if (index < 0 || index >= PLENGTH)
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
         poke0(POINTER + index, value);
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=767957&r1=767956&r2=767957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java Thu Apr 23 16:19:03 2009
@@ -62,9 +62,11 @@
     private static native int  peek0(long addr);
 
     public int peek(int index)
-        throws IndexOutOfBoundsException
+        throws IndexOutOfBoundsException, NullPointerException
     {
-        if (index < 0 || index >= PLENGTH)
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
         return peek0(POINTER + index);
     }
@@ -72,9 +74,11 @@
     private static native void  poke0(long addr, int b);
 
     public void poke(int index, int value)
-        throws IndexOutOfBoundsException
+        throws IndexOutOfBoundsException, NullPointerException
     {
-        if (index < 0 || index >= PLENGTH)
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
         poke0(POINTER + index, value);
     }

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=767957&r1=767956&r2=767957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Thu Apr 23 16:19:03 2009
@@ -151,18 +151,16 @@
 
 ACR_PTR_EXPORT_DECLARE(jint, peek0)(ACR_JNISTDARGS, jniptr a)
 {
-    char *b = (char *)((acr_ptr_t)a);
     UNREFERENCED_STDARGS;
 
-    return *b;
+    return *((char *)((acr_ptr_t)a));
 }
 
 ACR_PTR_EXPORT_DECLARE(void, poke0)(ACR_JNISTDARGS, jniptr a, jint v)
 {
-    char *b = (char *)((acr_ptr_t)a);
     UNREFERENCED_STDARGS;
 
-    *b = v;
+    *((char *)((acr_ptr_t)a)) = v;
 }
 
 ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *_E, void *p, size_t len,