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/06/19 10:32:39 UTC
svn commit: r786411 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ main/native/shared/
test/org/apache/commons/runtime/
Author: mturk
Date: Fri Jun 19 08:32:39 2009
New Revision: 786411
URL: http://svn.apache.org/viewvc?rev=786411&view=rev
Log:
implement float and double peek/poke
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=786411&r1=786410&r2=786411&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:32:39 2009
@@ -176,16 +176,22 @@
* 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)
+ public abstract int peek16(int index)
throws IndexOutOfBoundsException, NullPointerException;
- public abstract int peek32(int index)
+ public abstract int peek32(int index)
throws IndexOutOfBoundsException, NullPointerException;
- public abstract long peek64(int index)
+ public abstract long peek64(int index)
+ throws IndexOutOfBoundsException, NullPointerException;
+
+ public abstract float peek32f(int index)
+ throws IndexOutOfBoundsException, NullPointerException;
+
+ public abstract double peek64f(int index)
throws IndexOutOfBoundsException, NullPointerException;
/**
@@ -206,9 +212,15 @@
public abstract void poke32(int index, int value)
throws IndexOutOfBoundsException, NullPointerException;
+ public abstract void poke32(int index, float value)
+ throws IndexOutOfBoundsException, NullPointerException;
+
public abstract void poke64(int index, long value)
throws IndexOutOfBoundsException, NullPointerException;
+ public abstract void poke64(int index, double 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=786411&r1=786410&r2=786411&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:32:39 2009
@@ -64,10 +64,12 @@
return new Integer(PLENGTH);
}
- 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);
+ 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);
+ private static native float peek4(int addr);
+ private static native double peek5(int addr);
public int peek(int index)
throws IndexOutOfBoundsException, NullPointerException
@@ -109,10 +111,32 @@
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 float peek32f(int index)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0)
+ throw new NullPointerException();
+ else if (index < 0 || index >= PLENGTH / 4)
+ throw new IndexOutOfBoundsException();
+ return peek4(POINTER + index / 4);
+ }
+
+ public double peek64f(int index)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0)
+ throw new NullPointerException();
+ else if (index < 0 || index >= PLENGTH / 8)
+ throw new IndexOutOfBoundsException();
+ return peek5(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);
+ private static native void poke4(int addr, float v);
+ private static native void poke5(int addr, double v);
public void poke(int index, int value)
throws IndexOutOfBoundsException, NullPointerException
@@ -144,6 +168,16 @@
poke2(POINTER + index / 4, value);
}
+ public void poke32(int index, float value)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0)
+ throw new NullPointerException();
+ else if (index < 0 || index >= PLENGTH / 4)
+ throw new IndexOutOfBoundsException();
+ poke4(POINTER + index / 4, value);
+ }
+
public void poke64(int index, long value)
throws IndexOutOfBoundsException, NullPointerException
{
@@ -154,6 +188,16 @@
poke3(POINTER + index / 8, value);
}
+ public void poke64(int index, double value)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0)
+ throw new NullPointerException();
+ else if (index < 0 || index >= PLENGTH / 8)
+ throw new IndexOutOfBoundsException();
+ poke5(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=786411&r1=786410&r2=786411&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:32:39 2009
@@ -64,10 +64,12 @@
return new Long(PLENGTH);
}
- 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);
+ 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);
+ private static native float peek4(long addr);
+ private static native double peek5(long addr);
public int peek(int index)
throws IndexOutOfBoundsException, NullPointerException
@@ -109,10 +111,32 @@
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 float peek32f(int index)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= PLENGTH / 4)
+ throw new IndexOutOfBoundsException();
+ return peek4(POINTER + index / 4);
+ }
+
+ public double peek64f(int index)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= PLENGTH / 8)
+ throw new IndexOutOfBoundsException();
+ return peek5(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);
+ private static native void poke4(long addr, float v);
+ private static native void poke5(long addr, double v);
public void poke(int index, int value)
throws IndexOutOfBoundsException, NullPointerException
@@ -144,6 +168,16 @@
poke2(POINTER + index / 4, value);
}
+ public void poke32(int index, float value)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= PLENGTH / 4)
+ throw new IndexOutOfBoundsException();
+ poke4(POINTER + index / 4, value);
+ }
+
public void poke64(int index, long value)
throws IndexOutOfBoundsException, NullPointerException
{
@@ -154,6 +188,16 @@
poke3(POINTER + index / 8, value);
}
+ public void poke64(int index, double value)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= PLENGTH / 8)
+ throw new IndexOutOfBoundsException();
+ poke5(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=786411&r1=786410&r2=786411&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:32:39 2009
@@ -203,6 +203,20 @@
return *(N2P(a, jlong *));
}
+ACR_PTR_EXPORT_DECLARE(jfloat, peek4)(ACR_JNISTDARGS, jniptr a)
+{
+ UNREFERENCED_STDARGS;
+
+ return *(N2P(a, jfloat *));
+}
+
+ACR_PTR_EXPORT_DECLARE(jdouble, peek5)(ACR_JNISTDARGS, jniptr a)
+{
+ UNREFERENCED_STDARGS;
+
+ return *(N2P(a, jdouble *));
+}
+
ACR_PTR_EXPORT_DECLARE(void, poke0)(ACR_JNISTDARGS, jniptr a, jint v)
{
UNREFERENCED_STDARGS;
@@ -231,6 +245,20 @@
*(N2P(a, jlong *)) = v;
}
+ACR_PTR_EXPORT_DECLARE(void, poke4)(ACR_JNISTDARGS, jniptr a, jfloat v)
+{
+ UNREFERENCED_STDARGS;
+
+ *(N2P(a, jfloat *)) = v;
+}
+
+ACR_PTR_EXPORT_DECLARE(void, poke5)(ACR_JNISTDARGS, jniptr a, jdouble v)
+{
+ UNREFERENCED_STDARGS;
+
+ *(N2P(a, jdouble *)) = 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=786411&r1=786410&r2=786411&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:32:39 2009
@@ -338,6 +338,28 @@
p.free();
}
+ public void testPeek32f()
+ throws Throwable
+ {
+ Pointer p = Memory.calloc(1000);
+ assertNotNull("Pointer", p);
+ p.poke32(246, 2303.64F);
+ assertEquals("Value", 2303.64F, p.peek32f(246));
+
+ p.free();
+ }
+
+ public void testPeek64f()
+ throws Throwable
+ {
+ Pointer p = Memory.calloc(1000);
+ assertNotNull("Pointer", p);
+ p.poke64(117, 2303.1964);
+ assertEquals("Value", 2303.1964, p.peek64f(117));
+
+ p.free();
+ }
+
public void testPointerNull()
throws Throwable
{