Author: mturk
Date: Wed Aug 17 06:06:42 2011
New Revision: 1158533
URL: http://svn.apache.org/viewvc?rev=1158533&view=rev
Log:
Do not use long for Pointer length
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/io/Streamable.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Deflater.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Inflater.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Deflater.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Impl.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Inflater.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c
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=1158533&r1=1158532&r2=1158533&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
Wed Aug 17 06:06:42 2011
@@ -99,7 +99,6 @@ public abstract class Pointer implements
return PLENGTH;
}
-
/**
* Check if the pointer is valid
* @return true if the internal pointer is not {@code NULL}.
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Streamable.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Streamable.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Streamable.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Streamable.java
Wed Aug 17 06:06:42 2011
@@ -27,7 +27,7 @@ public interface Streamable extends Devi
{
/**
- * Test if this stream supports read operations.
+ * Test whether this stream supports read operations.
*
* @return {@code true} if the read operations are
* supported, {@code false} otherwise.
@@ -35,7 +35,7 @@ public interface Streamable extends Devi
public boolean canRead();
/**
- * Test if this stream supports write operations.
+ * Test whether this stream supports write operations.
*
* @return {@code true} if the write operations are
* supported, {@code false} otherwise.
@@ -43,7 +43,7 @@ public interface Streamable extends Devi
public boolean canWrite();
/**
- * Test if this stream supports seek operations.
+ * Test whether this stream supports seek operations.
*
* @return {@code true} if the seek operations are
* supported, {@code false} otherwise.
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Deflater.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Deflater.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Deflater.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Deflater.java
Wed Aug 17 06:06:42 2011
@@ -176,7 +176,7 @@ public abstract class Deflater implement
* @param len the length of the input data
* @throws InvalidArgumentException if the provided parameters are invalid
*/
- public abstract void setInput(Pointer b, long off, long len)
+ public abstract void setInput(Pointer b, long off, int len)
throws InvalidArgumentException;
/**
@@ -190,9 +190,10 @@ public abstract class Deflater implement
public void setInput(Pointer b)
throws InvalidArgumentException
{
- if (b == null)
- throw new NullPointerException();
- setInput(b, 0L, b.sizeof());
+ int len = Utils.unsignedInteger(b.sizeof());
+ if (len < 1)
+ throw new InvalidArgumentException();
+ setInput(b, 0L, len);
}
/**
@@ -223,6 +224,8 @@ public abstract class Deflater implement
* @return the actual number of bytes of compressed data
* @throws InvalidDataException if the provided data was invalid
* @throws OutOfMemoryError if the memory allocation failed
+ * @throws NullPointerException if the inflater does not have internal
+ * buffer.
*/
public abstract int deflate()
throws InvalidDataException,
@@ -298,7 +301,7 @@ public abstract class Deflater implement
* @throws InvalidDataException if the input data was invalid or corrupt.
* @throws OutOfMemoryError if the memory allocation failed
*/
- public abstract long deflate(Pointer b, long off, long len)
+ public abstract int deflate(Pointer b, long off, int len)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError;
@@ -315,16 +318,17 @@ public abstract class Deflater implement
* @throws InvalidDataException if the provided data was invalid
* @throws OutOfMemoryError if the memory allocation failed
*/
- public long deflate(Pointer b)
+ public int deflate(Pointer b)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError
{
if (b == null)
throw new NullPointerException();
- if (b.sizeof() < 1)
+ int len = Utils.unsignedInteger(b.sizeof());
+ if (len < 1)
throw new InvalidArgumentException();
- return deflate(b, 0, b.sizeof());
+ return deflate(b, 0, len);
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Inflater.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Inflater.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Inflater.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Inflater.java
Wed Aug 17 06:06:42 2011
@@ -120,8 +120,6 @@ public abstract class Inflater implement
public void setInput(byte[] b)
throws InvalidArgumentException
{
- if (b == null)
- throw new NullPointerException();
if (b.length < 1)
throw new InvalidArgumentException();
setInput(b, 0, b.length);
@@ -150,7 +148,7 @@ public abstract class Inflater implement
*
* @throws InvalidArgumentException if the provided parameters are invalid
*/
- public abstract void setInput(Pointer b, long off, long len)
+ public abstract void setInput(Pointer b, long off, int len)
throws InvalidArgumentException;
/**
@@ -165,9 +163,10 @@ public abstract class Inflater implement
public void setInput(Pointer b)
throws InvalidArgumentException
{
- if (b == null)
- throw new NullPointerException();
- setInput(b, 0L, b.sizeof());
+ int len = Utils.unsignedInteger(b.sizeof());
+ if (len < 1)
+ throw new InvalidArgumentException();
+ setInput(b, 0L, len);
}
/**
@@ -198,6 +197,8 @@ public abstract class Inflater implement
*
* @throws InvalidDataException if the provided data was invalid
* @throws OutOfMemoryError if the memory allocation failed
+ * @throws NullPointerException if the inflater does not have internal
+ * buffer.
*/
public abstract int inflate()
throws InvalidDataException,
@@ -245,8 +246,6 @@ public abstract class Inflater implement
InvalidDataException,
OutOfMemoryError
{
- if (b == null)
- throw new NullPointerException();
if (b.length < 1)
throw new InvalidArgumentException();
return inflate(b, 0, b.length);
@@ -289,7 +288,7 @@ public abstract class Inflater implement
* @throws InvalidDataException if the input data was invalid or corrupt.
* @throws OutOfMemoryError if the memory allocation failed
*/
- public abstract long inflate(Pointer b, long off, long len)
+ public abstract int inflate(Pointer b, long off, int len)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError;
@@ -309,16 +308,15 @@ public abstract class Inflater implement
* @throws InvalidDataException if the provided data was invalid
* @throws OutOfMemoryError if the memory allocation failed
*/
- public long inflate(Pointer b)
+ public int inflate(Pointer b)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError
{
- if (b == null)
- throw new NullPointerException();
- if (b.sizeof() < 1)
+ int len = Utils.unsignedInteger(b.sizeof());
+ if (len < 1)
throw new InvalidArgumentException();
- return inflate(b, 0, b.sizeof());
+ return inflate(b, 0L, len);
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
Wed Aug 17 06:06:42 2011
@@ -401,5 +401,24 @@ public final class Utils
return sa;
}
+ /**
+ * Safely cast long to integer.
+ * <p>
+ * If the {@code val} is larger then {@code Integer.MAX_VALUE} returned
+ * value is {@code Integer.MAX_VALUE}.
+ *</p>
+ *
+ * @param val value to cast.
+ * @return integer in range {@code 0 to Integer.MAX_VALUE}.
+ */
+ public static int unsignedInteger(long val)
+ {
+ if (val < 0L)
+ return 0;
+ else if (val > Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ else
+ return (int)val;
+ }
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2.java
Wed Aug 17 06:06:42 2011
@@ -25,6 +25,7 @@ import org.apache.commons.runtime.Operat
import org.apache.commons.runtime.OverflowException;
import org.apache.commons.runtime.Pointer;
import org.apache.commons.runtime.util.StringManager;
+import org.apache.commons.runtime.util.Utils;
/**
* Primitive array helper routines.
@@ -107,31 +108,31 @@ public final class Bzip2
throws InvalidArgumentException,
OverflowException;
private static native int deflate1(ByteBuffer src, int spos,
- ByteBuffer dst, int dpos, int dlen,
- int len, int blockSize100k,
- int workFactor)
+ ByteBuffer dst, int dpos, int dlen,
+ int len, int blockSize100k,
+ int workFactor)
throws InvalidArgumentException,
OverflowException;
- private static native long deflate2(long src, long dst, long dlen,
- long len, int blockSize100k,
- int workFactor)
+ private static native int deflate2(long src, long dst, int dlen,
+ int len, int blockSize100k,
+ int workFactor)
throws InvalidArgumentException,
InvalidRangeException,
OverflowException;
private static native int inflate0(byte[] src, int spos,
- byte[] dst, int dpos, int dlen,
- int len, boolean small)
+ byte[] dst, int dpos, int dlen,
+ int len, boolean small)
throws InvalidArgumentException,
InvalidDataException,
OverflowException;
private static native int inflate1(ByteBuffer src, int spos,
- ByteBuffer dst, int dpos, int dlen,
- int len, boolean small)
+ ByteBuffer dst, int dpos, int dlen,
+ int len, boolean small)
throws InvalidArgumentException,
InvalidDataException,
OverflowException;
- private static native long inflate2(long src,long dst, long dlen,
- long len, boolean small)
+ private static native int inflate2(long src,long dst, int dlen,
+ int len, boolean small)
throws InvalidArgumentException,
InvalidDataException,
OverflowException;
@@ -215,8 +216,8 @@ public final class Bzip2
{
if (blockSize100k < 1 || blockSize100k > 9 || workFactor < 0 ||
workFactor > 250)
throw new InvalidArgumentException();
- int dstLen = dst.limit() - dst.position();
- int length = src.limit() - src.position();
+ int dstLen = dst.remaining();
+ int length = src.remaining();
if (dstLen < 1 || length < 1)
throw new ArrayIndexOutOfBoundsException();
int s = deflate1(src, src.position(), dst, dst.position(),
@@ -254,7 +255,7 @@ public final class Bzip2
long srcPos,
Pointer dst,
long dstPos,
- long length,
+ int length,
int blockSize100k,
int workFactor)
throws InvalidArgumentException,
@@ -265,10 +266,10 @@ public final class Bzip2
throw new InvalidArgumentException();
long srca = src.address() + srcPos;
long dsta = dst.address() + dstPos;
- long dlen = dst.sizeof() - dstPos;
- if (dlen < 1L || srcPos < 0L || dstPos < 0L)
+ int dlen = Utils.unsignedInteger(dst.sizeof() - dstPos);
+ if (dlen < 1 || srcPos < 0L || dstPos < 0L)
throw new IndexOutOfBoundsException();
- return deflate2(srca, dsta, dlen, length, blockSize100k, workFactor);
+ return deflate2(srca, dsta, (int)dlen, length, blockSize100k,
workFactor);
}
/**
@@ -343,8 +344,8 @@ public final class Bzip2
InvalidDataException,
OverflowException
{
- int dstLen = dst.limit() - dst.position();
- int length = src.limit() - src.position();
+ int dstLen = dst.remaining();
+ int length = src.remaining();
if (dstLen < 1 || length < 1)
throw new ArrayIndexOutOfBoundsException();
int p = inflate1(src, src.position(), dst, dst.position(),
@@ -382,7 +383,7 @@ public final class Bzip2
long srcPos,
Pointer dst,
long dstPos,
- long length,
+ int length,
boolean small)
throws InvalidArgumentException,
InvalidDataException,
@@ -390,8 +391,8 @@ public final class Bzip2
{
long srca = src.address() + srcPos;
long dsta = dst.address() + dstPos;
- long dlen = dst.sizeof() - dstPos;
- if (dlen < 1L || srcPos < 0L || dstPos < 0L)
+ int dlen = Utils.unsignedInteger(dst.sizeof() - dstPos);
+ if (dlen < 1 || srcPos < 0L || dstPos < 0L)
throw new IndexOutOfBoundsException();
/* TODO: Check for param validity */
return inflate2(srca, dsta, dlen, length, small);
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Deflater.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Deflater.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Deflater.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Deflater.java
Wed Aug 17 06:06:42 2011
@@ -37,6 +37,7 @@ public class Bzip2Deflater extends Defla
{
private long handle;
+ private int bufferSize;
private static native int deflate0(long stream)
throws InvalidDataException,
@@ -47,7 +48,7 @@ public class Bzip2Deflater extends Defla
private static native int deflate2(long stream, ByteBuffer buf, int
off, int len)
throws InvalidDataException,
OutOfMemoryError;
- private static native long deflate3(long stream, long buf, long len)
+ private static native int deflate3(long stream, long buf, int len)
throws InvalidDataException,
OutOfMemoryError;
@@ -58,7 +59,7 @@ public class Bzip2Deflater extends Defla
*/
public Bzip2Deflater()
{
- this(9, 30);
+ this(9, Bzip2Impl.DEFAULT_WORK_FACTOR);
}
/**
@@ -95,10 +96,13 @@ public class Bzip2Deflater extends Defla
throw new InvalidArgumentException();
if (workFactor == 0)
workFactor = Bzip2Impl.DEFAULT_WORK_FACTOR;
- handle = Bzip2Impl.newStream(bufferSize);
+ handle = Bzip2Impl.newHandle(bufferSize);
int rc = Bzip2Impl.compressInit(handle, blockSize100k, workFactor);
- if (rc != 0)
+ if (rc != 0) {
+ close0(handle);
throw new OutOfMemoryError();
+ }
+ this.bufferSize = bufferSize;
}
@Override
@@ -144,7 +148,7 @@ public class Bzip2Deflater extends Defla
public synchronized void setInput(ByteBuffer b)
throws InvalidArgumentException
{
- int len = b.limit() - b.position();
+ int len = b.remaining();
if (len < 1)
throw new InvalidArgumentException();
if (handle == 0L)
@@ -153,10 +157,10 @@ public class Bzip2Deflater extends Defla
}
@Override
- public synchronized void setInput(Pointer b, long off, long len)
+ public synchronized void setInput(Pointer b, long off, int len)
throws InvalidArgumentException
{
- if (len < 1L)
+ if (len < 1)
throw new InvalidArgumentException();
if (off < 0L || off + len > b.sizeof())
throw new IndexOutOfBoundsException();
@@ -206,6 +210,8 @@ public class Bzip2Deflater extends Defla
throws InvalidDataException,
OutOfMemoryError
{
+ if (bufferSize == 0)
+ throw new NullPointerException();
if (handle == 0L)
throw new IllegalStateException();
return deflate0(handle);
@@ -228,26 +234,26 @@ public class Bzip2Deflater extends Defla
InvalidDataException,
OutOfMemoryError
{
+ int len = b.remaining();
+ if (len < 1)
+ throw new InvalidArgumentException();
if (handle == 0L)
throw new IllegalStateException();
- int len = b.limit() - b.position();
return deflate2(handle, b, b.position(), len);
}
@Override
- public long deflate(Pointer b, long off, long len)
+ public int deflate(Pointer b, long off, int len)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError
{
- if (len < 1L)
+ if (len < 1)
throw new InvalidArgumentException();
if (off < 0L || off + len > b.sizeof())
throw new IndexOutOfBoundsException();
if (handle == 0L)
throw new IllegalStateException();
- if (handle == 0L)
- throw new IllegalStateException();
return deflate3(handle, b.address() + off, len);
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Impl.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Impl.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Impl.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Impl.java
Wed Aug 17 06:06:42 2011
@@ -49,15 +49,15 @@ final class Bzip2Impl
*/
public static final byte BZ_FINISH = 2;
- private static native int bzsize0();
- public static native long newStream(int bufferSize)
+ private static native int init0();
+ public static native long newHandle(int bufferSize)
throws OutOfMemoryError;
public static native int compressInit(long handle, int blockSize100k,
int workFactor);
public static native int decompressInit(long handle, boolean small);
public static native int setInput0(long handle, byte[] buf, int off,
int len);
public static native int setInput1(long handle, ByteBuffer buf, int
off, int len);
- public static native int setInput2(long handle, long buf, long len);
+ public static native int setInput2(long handle, long buf, int len);
public static native void setInput3(long handle);
public static native int getAvailIn(long handle);
@@ -73,9 +73,8 @@ final class Bzip2Impl
public static final int DEFAULT_WORK_FACTOR = 30;
public static final int SIZEOF_BZ_STREAM;
-
static {
- SIZEOF_BZ_STREAM = bzsize0();
+ SIZEOF_BZ_STREAM = init0();
}
private Bzip2Impl()
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Inflater.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Inflater.java?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Inflater.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/bzip2/Bzip2Inflater.java
Wed Aug 17 06:06:42 2011
@@ -37,6 +37,7 @@ public final class Bzip2Inflater extends
{
private long handle;
+ private int bufferSize;
private static native int inflate0(long stream)
throws InvalidDataException,
@@ -47,7 +48,7 @@ public final class Bzip2Inflater extends
private static native int inflate2(long stream, ByteBuffer buf, int
off, int len)
throws InvalidDataException,
OutOfMemoryError;
- private static native long inflate3(long stream, long buf, long len)
+ private static native int inflate3(long stream, long buf, int len)
throws InvalidDataException,
OutOfMemoryError;
@@ -85,8 +86,13 @@ public final class Bzip2Inflater extends
{
if (bufferSize < 0)
throw new InvalidArgumentException();
- handle = Bzip2Impl.newStream(bufferSize);
+ handle = Bzip2Impl.newHandle(bufferSize);
int rc = Bzip2Impl.decompressInit(handle, small);
+ if (rc != 0) {
+ close0(handle);
+ throw new OutOfMemoryError();
+ }
+ this.bufferSize = bufferSize;
}
@Override
@@ -126,17 +132,17 @@ public final class Bzip2Inflater extends
public synchronized void setInput(ByteBuffer b)
throws InvalidArgumentException
{
- int len = b.limit() - b.position();
+ int len = b.remaining();
if (len < 1)
throw new InvalidArgumentException();
Bzip2Impl.setInput1(handle, b, b.position(), len);
}
@Override
- public synchronized void setInput(Pointer b, long off, long len)
+ public synchronized void setInput(Pointer b, long off, int len)
throws InvalidArgumentException
{
- if (len < 1L)
+ if (len < 1)
throw new InvalidArgumentException();
if (off < 0L || off + len > b.sizeof())
throw new IndexOutOfBoundsException();
@@ -160,6 +166,10 @@ public final class Bzip2Inflater extends
throws InvalidDataException,
OutOfMemoryError
{
+ if (bufferSize == 0)
+ throw new NullPointerException();
+ if (handle == 0L)
+ throw new IllegalStateException();
return inflate0(handle);
}
@@ -169,6 +179,8 @@ public final class Bzip2Inflater extends
InvalidDataException,
OutOfMemoryError
{
+ if (handle == 0L)
+ throw new IllegalStateException();
return inflate1(handle, b, off, len);
}
@@ -178,26 +190,26 @@ public final class Bzip2Inflater extends
InvalidDataException,
OutOfMemoryError
{
+ int len = b.remaining();
+ if (len < 1)
+ throw new InvalidArgumentException();
if (handle == 0L)
throw new IllegalStateException();
- int len = b.limit() - b.position();
return inflate2(handle, b, b.position(), len);
}
@Override
- public long inflate(Pointer b, long off, long len)
+ public int inflate(Pointer b, long off, int len)
throws InvalidArgumentException,
InvalidDataException,
OutOfMemoryError
{
- if (len < 1L)
+ if (len < 1)
throw new InvalidArgumentException();
if (off < 0L || off + len > b.sizeof())
throw new IndexOutOfBoundsException();
if (handle == 0L)
throw new IllegalStateException();
- if (handle == 0L)
- throw new IllegalStateException();
return inflate3(handle, b.address() + off, len);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h Wed Aug
17 06:06:42 2011
@@ -51,6 +51,8 @@ int
AcrSetPointer(JNI_STDARGS, void *val);
int
AcrSetPointerEx(JNI_STDARGS, void *val, size_t len);
+int
+AcrSetPointerSz(JNI_STDARGS, size_t len);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c?rev=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/bzip2.c Wed Aug 17
06:06:42 2011
@@ -131,24 +131,20 @@ ACR_BZIP2_EXPORT(jint, Bzip2, deflate1)(
return 0;
}
-ACR_BZIP2_EXPORT(jlong, Bzip2, deflate2)(JNI_STDARGS, jlong src, jlong dst,
- jlong dlen, jlong len, jint
blockSize100k,
- jint workFactor)
+ACR_BZIP2_EXPORT(jint, Bzip2, deflate2)(JNI_STDARGS, jlong src, jlong dst,
+ jint dlen, jint len, jint
blockSize100k,
+ jint workFactor)
{
unsigned int dstLen;
char *scp = J2P(src, char *);
char *dcp = J2P(dst, char *);
int rc;
- if (dlen > UINT_MAX || len > UINT_MAX) {
- ACR_THROW(ACR_EX_ERANGE, 0);
- return 0;
- }
- dstLen = (unsigned int)dlen;
+ dstLen = dlen;
rc = BZ2_bzBuffToBuffCompress(dcp, &dstLen, scp, (unsigned int)len,
blockSize100k, 0, workFactor);
if (rc == BZ_OK)
- return (jlong)dstLen;
+ return dstLen;
else if (rc == BZ_OUTBUFF_FULL)
ACR_THROW(ACR_EX_EOVERFLOW, 0);
else if (rc == BZ_MEM_ERROR)
@@ -229,22 +225,16 @@ ACR_BZIP2_EXPORT(jint, Bzip2, inflate1)(
}
ACR_BZIP2_EXPORT(jlong, Bzip2, inflate2)(JNI_STDARGS, jlong src,
- jlong dst, jlong dlen,
- jlong len, jboolean small)
+ jlong dst, jint dlen,
+ jint len, jboolean small)
{
unsigned int dstLen;
char *scp = J2P(src, char *);
char *dcp = J2P(dst, char *);
int rc;
- if (dlen > UINT_MAX || len > UINT_MAX) {
- ACR_THROW(ACR_EX_ERANGE, 0);
- return 0;
- }
- dstLen = (unsigned int)dlen;
-
- rc = BZ2_bzBuffToBuffDecompress(dcp, &dstLen, scp, (unsigned int)len,
- small, 0);
+ dstLen = dlen;
+ rc = BZ2_bzBuffToBuffDecompress(dcp, &dstLen, scp, len, small, 0);
if (rc == BZ_OK)
return (jlong)dstLen;
else if (rc == BZ_OUTBUFF_FULL)
@@ -258,14 +248,14 @@ ACR_BZIP2_EXPORT(jlong, Bzip2, inflate2)
return 0;
}
-ACR_BZIP2_EXPORT(jint, Bzip2Impl, bzsize0)(JNI_STDARGS)
+ACR_BZIP2_EXPORT(jint, Bzip2Impl, init0)(JNI_STDARGS)
{
int ssize = ISIZEOF(acr_bzstream);
ACR_BZSIZE = ACR_ALIGN_DEFAULT(ssize);
return ACR_BZSIZE;
}
-ACR_BZIP2_EXPORT(jlong, Bzip2Impl, newStream)(JNI_STDARGS, jint bsize)
+ACR_BZIP2_EXPORT(jlong, Bzip2Impl, newHandle)(JNI_STDARGS, jint bsize)
{
acr_bzstream *s;
s = ACR_EALLOC(acr_bzstream, bsize);
@@ -333,7 +323,7 @@ ACR_BZIP2_EXPORT(jint, Bzip2Impl, setInp
}
ACR_BZIP2_EXPORT(jint, Bzip2Impl, setInput2)(JNI_STDARGS, jlong stream,
- jlong src, jlong len)
+ jlong src, jint len)
{
int rc = BZ_PARAM_ERROR;
acr_bzstream *s = J2P(stream, acr_bzstream *);
@@ -342,7 +332,7 @@ ACR_BZIP2_EXPORT(jint, Bzip2Impl, setInp
s->next_data = J2P(src, char *);
if (s->next_data != 0) {
s->bz.next_in = s->next_data;
- s->bz.avail_in = (unsigned int)len;
+ s->bz.avail_in = len;
rc = BZ_OK;
}
return rc;
@@ -518,8 +508,8 @@ ACR_BZIP2_EXPORT(jint, Bzip2Deflater, de
return len - s->bz.avail_out;
}
-ACR_BZIP2_EXPORT(jlong, Bzip2Deflater, deflate3)(JNI_STDARGS, jlong stream,
- jlong buf, jlong len)
+ACR_BZIP2_EXPORT(jint, Bzip2Deflater, deflate3)(JNI_STDARGS, jlong stream,
+ jlong buf, jint len)
{
int rc;
char *next_out = J2P(buf, char *);
@@ -529,7 +519,7 @@ ACR_BZIP2_EXPORT(jlong, Bzip2Deflater, d
return -1;
s->bz.next_out = next_out;
- s->bz.avail_out = (unsigned int)len;
+ s->bz.avail_out = len;
rc = BZ2_bzCompress((bz_stream *)s, s->state);
if (rc == BZ_SEQUENCE_ERROR || rc == BZ_PARAM_ERROR) {
/* Report both errors as illegal */
@@ -629,8 +619,8 @@ ACR_BZIP2_EXPORT(jint, Bzip2Inflater, in
return len - s->bz.avail_out;
}
-ACR_BZIP2_EXPORT(jlong, Bzip2Inflater, inflate3)(JNI_STDARGS, jlong stream,
- jlong buf, jlong len)
+ACR_BZIP2_EXPORT(jint, Bzip2Inflater, inflate3)(JNI_STDARGS, jlong stream,
+ jlong buf, jint len)
{
int rc = BZ_PARAM_ERROR;
char *next_out = J2P(buf, char *);
@@ -639,7 +629,7 @@ ACR_BZIP2_EXPORT(jlong, Bzip2Inflater, i
if (s->eos)
return -1;
s->bz.next_out = next_out;
- s->bz.avail_out = (unsigned int)len;
+ s->bz.avail_out = len;
rc = BZ2_bzDecompress((bz_stream *)s);
if (rc == BZ_STREAM_END)
s->eos = JNI_TRUE;
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=1158533&r1=1158532&r2=1158533&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Wed Aug 17
06:06:42 2011
@@ -148,6 +148,26 @@ AcrSetPointerEx(JNI_STDARGS, void *val,
return 0;
}
+int
+AcrSetPointerSz(JNI_STDARGS, size_t len)
+{
+ if (!CLAZZ_LOADED) {
+ return -1;
+ }
+ if (UNSAFE_HAS_OFF(0000) && UNSAFE_HAS_OFF(0001)) {
+ char *oa = *(char **)obj;
+ if (oa != 0) {
+ char *pa = oa + UNSAFE_FLD_OFF(0001);
+ *((jlong *)pa) = P2J(len);
+ return 0;
+ }
+ }
+ /* Fallback to a traditional method.
+ */
+ SET_IFIELD_P(0001, obj, len);
+ return 0;
+}
+
#if defined(WINDOWS)
ACR_WIN_EXPORT(jobject, Win32, pointer)
#else
@@ -160,7 +180,7 @@ ACR_UNX_EXPORT(jobject, Posix, pointer)
switch (type) {
case 1:
- return AcrNewHeapPointer(env, memptr, size);
+ return AcrNewHeapPointer(env, memptr, size);
break;
case 2:
return AcrNewSlicePointer(env, memptr, size);