commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r786407 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/shared/ test/org/apache/commons/runtime/
Date Fri, 19 Jun 2009 08:01:13 GMT
Author: mturk
Date: Fri Jun 19 08:01:13 2009
New Revision: 786407

URL: http://svn.apache.org/viewvc?rev=786407&view=rev
Log:
Add 16 32 and 64 bit peek/poke methods

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
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java

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=786407&r1=786406&r2=786407&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 Fri
Jun 19 08:01:13 2009
@@ -176,7 +176,16 @@
      *          outside the pointer address space.
      * @throws NullPointerException if pointer is {@code null}.
      */
-    public abstract int peek(int index)
+    public abstract int  peek(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract int  peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract int  peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract long peek64(int index)
         throws IndexOutOfBoundsException, NullPointerException;
 
     /**
@@ -191,6 +200,15 @@
     public abstract void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException;
 
+    public abstract void poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
     /**
      * Copy the memory area from {@code this} pointer to {@code dst}.
      * <p>

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=786407&r1=786406&r2=786407&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
Fri Jun 19 08:01:13 2009
@@ -65,6 +65,9 @@
     }
 
     private static native int  peek0(int addr);
+    private static native int  peek1(int addr);
+    private static native int  peek2(int addr);
+    private static native long peek3(int addr);
 
     public int peek(int index)
         throws IndexOutOfBoundsException, NullPointerException
@@ -76,7 +79,40 @@
         return peek0(POINTER + index);
     }
 
-    private static native void  poke0(int addr, int b);
+    public int peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        return peek1(POINTER + index / 2);
+    }
+
+    public int peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek2(POINTER + index / 4);
+    }
+
+    public long peek64(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek3(POINTER + index / 8);
+    }
+
+    private static native void  poke0(int addr, int  v);
+    private static native void  poke1(int addr, int  v);
+    private static native void  poke2(int addr, int  v);
+    private static native void  poke3(int addr, long v);
 
     public void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException
@@ -88,6 +124,36 @@
         poke0(POINTER + index, value);
     }
 
+    public void poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        poke1(POINTER + index / 2, value);
+    }
+
+    public void poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke2(POINTER + index / 4, value);
+    }
+
+    public void poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke3(POINTER + index / 8, value);
+    }
+
     private static native void copy0(int src, int dst, int length);
     private static native void move0(int src, int dst, int length);
 

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=786407&r1=786406&r2=786407&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
Fri Jun 19 08:01:13 2009
@@ -65,6 +65,9 @@
     }
 
     private static native int  peek0(long addr);
+    private static native int  peek1(long addr);
+    private static native int  peek2(long addr);
+    private static native long peek3(long addr);
 
     public int peek(int index)
         throws IndexOutOfBoundsException, NullPointerException
@@ -76,7 +79,40 @@
         return peek0(POINTER + index);
     }
 
-    private static native void  poke0(long addr, int b);
+    public int peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        return peek1(POINTER + index / 2);
+    }
+
+    public int peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek2(POINTER + index / 4);
+    }
+
+    public long peek64(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek3(POINTER + index / 8);
+    }
+
+    private static native void  poke0(long addr, int  v);
+    private static native void  poke1(long addr, int  v);
+    private static native void  poke2(long addr, int  v);
+    private static native void  poke3(long addr, long v);
 
     public void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException
@@ -88,6 +124,36 @@
         poke0(POINTER + index, value);
     }
 
+    public void poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        poke1(POINTER + index / 2, value);
+    }
+
+    public void poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke2(POINTER + index / 4, value);
+    }
+
+    public void poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke3(POINTER + index / 8, value);
+    }
+
     private static native void copy0(long src, long dst, long length);
     private static native void move0(long src, long dst, long length);
 

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=786407&r1=786406&r2=786407&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Jun 19 08:01:13 2009
@@ -182,6 +182,27 @@
     return *(N2P(a, char *));
 }
 
+ACR_PTR_EXPORT_DECLARE(jint, peek1)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, short *));
+}
+
+ACR_PTR_EXPORT_DECLARE(jint, peek2)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jint *));
+}
+
+ACR_PTR_EXPORT_DECLARE(jlong, peek3)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jlong *));
+}
+
 ACR_PTR_EXPORT_DECLARE(void, poke0)(ACR_JNISTDARGS, jniptr a, jint v)
 {
     UNREFERENCED_STDARGS;
@@ -189,6 +210,27 @@
     *(N2P(a, char *)) = (char)v;
 }
 
+ACR_PTR_EXPORT_DECLARE(void, poke1)(ACR_JNISTDARGS, jniptr a, jint v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, short *)) = (short)v;
+}
+
+ACR_PTR_EXPORT_DECLARE(void, poke2)(ACR_JNISTDARGS, jniptr a, jint v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jint *)) = v;
+}
+
+ACR_PTR_EXPORT_DECLARE(void, poke3)(ACR_JNISTDARGS, jniptr a, jlong v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jlong *)) = v;
+}
+
 ACR_PTR_EXPORT_DECLARE(void, copy0)(ACR_JNISTDARGS, jniptr s,
                                     jniptr d, jniptr l)
 {

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=786407&r1=786406&r2=786407&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri
Jun 19 08:01:13 2009
@@ -305,6 +305,39 @@
         p.free();
     }
 
+    public void testPeek16()
+        throws Throwable
+    {
+        Pointer p = Memory.calloc(1000);
+        assertNotNull("Pointer", p);
+        p.poke16(498, 2303);
+        assertEquals("Value", 2303, p.peek16(498));
+
+        p.free();
+    }
+
+    public void testPeek32()
+        throws Throwable
+    {
+        Pointer p = Memory.calloc(1000);
+        assertNotNull("Pointer", p);
+        p.poke32(246, 230364);
+        assertEquals("Value", 230364, p.peek32(246));
+
+        p.free();
+    }
+
+    public void testPeek64()
+        throws Throwable
+    {
+        Pointer p = Memory.calloc(1000);
+        assertNotNull("Pointer", p);
+        p.poke64(117, 23031964L);
+        assertEquals("Value", 23031964L, p.peek64(117));
+
+        p.free();
+    }
+
     public void testPointerNull()
         throws Throwable
     {



Mime
View raw message