Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 23810 invoked from network); 15 Apr 2011 05:58:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Apr 2011 05:58:04 -0000 Received: (qmail 28511 invoked by uid 500); 15 Apr 2011 05:58:04 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 28452 invoked by uid 500); 15 Apr 2011 05:58:02 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 28438 invoked by uid 99); 15 Apr 2011 05:58:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Apr 2011 05:58:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Apr 2011 05:57:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8D7B023889C5; Fri, 15 Apr 2011 05:57:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1092593 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/NioByteBuffer.java native/shared/nbb.c Date: Fri, 15 Apr 2011 05:57:37 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110415055737.8D7B023889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri Apr 15 05:57:37 2011 New Revision: 1092593 URL: http://svn.apache.org/viewvc?rev=1092593&view=rev Log: Typecheck if ByteBuffer isDirect Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java?rev=1092593&r1=1092592&r2=1092593&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java Fri Apr 15 05:57:37 2011 @@ -46,6 +46,8 @@ public final class NioByteBuffer throws OutOfMemoryError, IllegalArgumentException; private static native ByteBuffer attach0(long ptr, int len) throws OutOfMemoryError; + private static native void free0(ByteBuffer buf) + throws NullPointerException; private static native long addr0(ByteBuffer buf); private static native void copy0(ByteBuffer src, int srcPos, ByteBuffer dst, @@ -107,7 +109,7 @@ public final class NioByteBuffer return attach0(ptr.POINTER, (int)ptr.PLENGTH); } - public static native void set0(ByteBuffer buf, int c, int count) + private static native void set0(ByteBuffer buf, int c, int count) throws NullPointerException; /** * Set ByteBuffer to specified character. @@ -124,8 +126,8 @@ public final class NioByteBuffer throws NullPointerException, IllegalArgumentException, IndexOutOfBoundsException { - if (buf == null) - throw new NullPointerException(); + if (!buf.isDirect()) + throw new IllegalArgumentException(); int ss = buf.capacity(); if (ss < 1) throw new IllegalArgumentException(); @@ -149,8 +151,10 @@ public final class NioByteBuffer throws NullPointerException, IllegalArgumentException, IndexOutOfBoundsException { - if (src == null || dst == null) - throw new NullPointerException(); + if (!src.isDirect()) + throw new IllegalArgumentException(); + if (!dst.isDirect()) + throw new IllegalArgumentException(); int ss = src.capacity(); int ds = dst.capacity(); if (ss < 1 || ds < 1) @@ -180,8 +184,10 @@ public final class NioByteBuffer throws NullPointerException, IllegalArgumentException, IndexOutOfBoundsException { - if (src == null || dst == null) - throw new NullPointerException(); + if (!src.isDirect()) + throw new IllegalArgumentException(); + if (!dst.isDirect()) + throw new IllegalArgumentException(); int ss = src.capacity(); int ds = dst.capacity(); if (ss < 1 || ds < 1) @@ -240,8 +246,8 @@ public final class NioByteBuffer public static ByteBuffer allocate(ByteBuffer buf, int offset, int size) throws NullPointerException, IllegalArgumentException { - if (buf == null) - throw new NullPointerException(); + if (!buf.isDirect()) + throw new IllegalArgumentException(); long mem = addr0(buf); if (mem == 0L) throw new NullPointerException(); @@ -272,7 +278,11 @@ public final class NioByteBuffer * * @throws NullPointerException if {@code buf} is null */ - public static native void free(ByteBuffer buf) - throws NullPointerException; - + public static void free(ByteBuffer buf) + throws NullPointerException, IllegalArgumentException + { + if (!buf.isDirect()) + throw new IllegalArgumentException(); + free0(buf); + } } Modified: commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c?rev=1092593&r1=1092592&r2=1092593&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c Fri Apr 15 05:57:37 2011 @@ -71,7 +71,7 @@ ACR_JNI_EXPORT(jobject, NioByteBuffer, a return (*env)->NewDirectByteBuffer(env, J2P(src, char *), len); } -ACR_JNI_EXPORT(void, NioByteBuffer, free)(JNI_STDARGS, jobject bb) +ACR_JNI_EXPORT(void, NioByteBuffer, free0)(JNI_STDARGS, jobject bb) { void *mem;