commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r791081 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Memory.java native/shared/memory.c
Date Sat, 04 Jul 2009 08:20:57 GMT
Author: mturk
Date: Sat Jul  4 08:20:57 2009
New Revision: 791081

URL: http://svn.apache.org/viewvc?rev=791081&view=rev
Log:
Throw exception when writing to ConstPointer

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java?rev=791081&r1=791080&r2=791081&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Sat
Jul  4 08:20:57 2009
@@ -185,6 +185,8 @@
 
     private static native Pointer slice0(Pointer src, long offset, long size)
         throws IndexOutOfBoundsException;
+    private static native Pointer slice1(Pointer src, long offset, long size)
+        throws IndexOutOfBoundsException;
     /**
      * Creates a new {@link Pointer} object whose content is a shared
      * subsequence of a {@code src} memory address.
@@ -213,8 +215,10 @@
     {
         if (offset < 0L || size < 1L)
             throw new IllegalArgumentException();
-
-        return slice0(src, offset, size);
+        if (src instanceof ConstPointer)
+            return slice1(src, offset, size);
+        else
+            return slice0(src, offset, size);
     }
 
     private static native Pointer dup0(Pointer src, long offset, long size)
@@ -273,16 +277,21 @@
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
      * @throws RuntimeException if memory is corrupted.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(Pointer src, long srcPos, Pointer dst,
                             long dstPos, long length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, RuntimeException
+               NullPointerException, RuntimeException,
+               UnsupportedOperationException
     {
         if (srcPos < 0L || dstPos < 0L)
             throw new IllegalArgumentException();
         if (length < 1L)
             throw new IllegalArgumentException();
+        if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
 
         copy0(src, srcPos, dst, dstPos, length);
     }
@@ -312,16 +321,21 @@
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
      * @throws RuntimeException if memory is corrupted.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void move(Pointer src, long srcPos, Pointer dst,
                             long dstPos, long length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, RuntimeException
+               NullPointerException, RuntimeException,
+               UnsupportedOperationException
     {
         if (srcPos < 0L || dstPos < 0L)
             throw new IllegalArgumentException();
         if (length < 1L)
             throw new IllegalArgumentException();
+        if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
 
         move0(src, srcPos, dst, dstPos, length);
     }
@@ -342,13 +356,18 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code ptr} is {@code null}.
      * @throws RuntimeException if memory is corrupted.
+     * @throws UnsupportedOperationException if {@code ptr} is
+     *          instance of {@code ConstPointer}.
      */
     public static void clear(Pointer ptr, long offset, long length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, RuntimeException
+               NullPointerException, RuntimeException,
+               UnsupportedOperationException
     {
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
+        if (ptr instanceof ConstPointer)
+            throw new UnsupportedOperationException();
 
         clear0(ptr, offset, length);
     }
@@ -370,13 +389,18 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code ptr} is {@code null}.
      * @throws RuntimeException if memory is corrupted.
+     * @throws UnsupportedOperationException if {@code ptr} is
+     *          instance of {@code ConstPointer}.
      */
     public static void set(Pointer ptr, long offset, long length, int val)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, RuntimeException
+               NullPointerException, RuntimeException,
+               UnsupportedOperationException
     {
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
+        if (ptr instanceof ConstPointer)
+            throw new UnsupportedOperationException();
 
         set0(ptr, offset, length, val);
     }
@@ -831,16 +855,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(byte[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy0(src, srcPos, dst, dstPos, length);
     }
 
@@ -864,16 +892,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(char[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy1(src, srcPos, dst, dstPos, length);
     }
 
@@ -897,16 +929,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(short[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy2(src, srcPos, dst, dstPos, length);
     }
 
@@ -930,16 +966,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(int[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy3(src, srcPos, dst, dstPos, length);
     }
 
@@ -963,16 +1003,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(long[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy4(src, srcPos, dst, dstPos, length);
     }
 
@@ -996,16 +1040,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(float[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy5(src, srcPos, dst, dstPos, length);
     }
 
@@ -1029,16 +1077,20 @@
      *          access of data outside allocated memory bounds.
      * @throws NullPointerException if {@code src} or {@code dst} is
      *          {@code null}.
+     * @throws UnsupportedOperationException if {@code dst} is
+     *          instance of {@code ConstPointer}.
      */
     public static void copy(double[] src, int srcPos, Pointer dst,
                             long dstPos, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
+               NullPointerException, UnsupportedOperationException
     {
         if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
+        else if (dst instanceof ConstPointer)
+            throw new UnsupportedOperationException();
         pcpy6(src, srcPos, dst, dstPos, length);
     }
 

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=791081&r1=791080&r2=791081&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Sat Jul  4 08:20:57 2009
@@ -349,6 +349,31 @@
     return ACR_NewPointer(_E, sp + so, ss, NULL);
 }
 
+ACR_JNI_EXPORT_DECLARE(jobject, Memory, slice1)(ACR_JNISTDARGS,
+                                                jobject src, jlong off,
+                                                jlong siz)
+{
+    size_t  so  = (size_t)off;
+    size_t  ss  = (size_t)siz;
+    size_t  sl;
+    char   *sp = (char *)ACR_PointerGet(_E, src, &sl);
+
+    UNREFERENCED_O;
+
+    if (!sp) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
+    if ((so + ss) > sl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return NULL;
+    }
+
+    /* Create the ConstPointer class.
+     */
+    return ACR_NewConstPointer(_E, sp + so, ss);
+}
+
 ACR_JNI_EXPORT_DECLARE(jobject, Memory, dup0)(ACR_JNISTDARGS,
                                               jobject src, jlong off,
                                               jlong siz)



Mime
View raw message