diff options
author | Sven Gothel <[email protected]> | 2010-03-19 05:12:40 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-03-19 05:12:40 +0100 |
commit | 58d9dd488cbd7eee530031ef9ea523037be175cd (patch) | |
tree | c47ae5b560b9a935b7789ac1215a25cc8e2c7c4e /src/java | |
parent | 30d3d3a30fed35f23a8189dca3e7b4c92d57e2ad (diff) |
Drop PointerBuffer.wrapNative2Java(..)
in favor of a simple PointerBuffer.wrap(..),
due to the new semantics, ie internal integer/long presentation.
Fixed the javame code in this regard.
Diffstat (limited to 'src/java')
3 files changed, 40 insertions, 64 deletions
diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index a813348..2d7a8b2 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -768,7 +768,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter throw new RuntimeException("While emitting glue code for " + getName() + ": can not legally make pointers opaque to anything but longs"); } - writer.println(" return PointerBuffer.wrapNative2Java(_res, false);"); + writer.println(" return PointerBuffer.wrap(_res);"); } else { String returnTypeName = returnType.getName().substring("java.nio.".length()); writer.println(" return _res.as" + returnTypeName + "();"); diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp index 0ec54d0..7e9142c 100755 --- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp +++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp @@ -47,7 +47,9 @@ public class PointerBuffer { private PointerBuffer(ByteBuffer bb) { this.bb = bb; this.ib = bb.asIntBuffer(); - capacity = bb.capacity()/BufferFactory.SIZEOF_LONG; + + capacity = bb.capacity() / elementSize(); + position=0; backup = new long[capacity]; } @@ -93,11 +95,11 @@ public class PointerBuffer { } public static PointerBuffer allocate(int size) { - return new PointerBuffer(ByteBuffer.wrap(new byte[BufferFactory.SIZEOF_LONG * size])); + return new PointerBuffer(ByteBuffer.wrap(new byte[elementSize()* size])); } public static PointerBuffer allocateDirect(int size) { - return new PointerBuffer(BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_LONG * size)); + return new PointerBuffer(BufferFactory.newDirectByteBuffer(elementSize() * size)); } public static PointerBuffer wrap(ByteBuffer src) { @@ -106,26 +108,6 @@ public class PointerBuffer { return res; } - /** - * Wraps pointer arrays created by native code. - * Note: In case this is not a 64bit system, each pointer is being converted. */ - public static PointerBuffer wrapNative2Java(ByteBuffer src, boolean keepDirect) { - PointerBuffer res; - if (CPU.is32Bit()) { - // Must convert each pointer from 32-bit to 64-bit - IntBuffer buf = src.asIntBuffer(); - int len = buf.capacity(); - res = (src.isDirect() && keepDirect) ? PointerBuffer.allocateDirect(len) : PointerBuffer.allocate(len); - for (int i = 0; i < len; i++) { - res.put(i, buf.get(i)); - } - } else { - res = new PointerBuffer(src); - res.updateBackup(); - } - return res; - } - public ByteBuffer getBuffer() { return bb; } @@ -138,13 +120,17 @@ public class PointerBuffer { if(0>idx || idx>=capacity) { throw new IndexOutOfBoundsException(); } - idx = idx << 1 ; // 8-byte to 4-byte offset - long lo = 0x00000000FFFFFFFFL & ( (long) ib.get(idx) ); - long hi = 0x00000000FFFFFFFFL & ( (long) ib.get(idx+1) ); - if(BufferFactory.isLittleEndian()) { - return hi << 32 | lo ; + if(CPU.is32Bit()) { + return ib.get(idx); + } else { + idx = idx << 1 ; // 8-byte to 4-byte offset + long lo = 0x00000000FFFFFFFFL & ( (long) ib.get(idx) ); + long hi = 0x00000000FFFFFFFFL & ( (long) ib.get(idx+1) ); + if(BufferFactory.isLittleEndian()) { + return hi << 32 | lo ; + } + return lo << 32 | hi ; } - return lo << 32 | hi ; } public long get() { @@ -158,15 +144,19 @@ public class PointerBuffer { throw new IndexOutOfBoundsException(); } backup[idx] = v; - idx = idx << 1 ; // 8-byte to 4-byte offset - int lo = (int) ( ( v ) & 0x00000000FFFFFFFFL ) ; - int hi = (int) ( ( v >> 32 ) & 0x00000000FFFFFFFFL ) ; - if(BufferFactory.isLittleEndian()) { - ib.put(idx, lo); - ib.put(idx+1, hi); + if(CPU.is32Bit()) { + ib.put(idx, (int)v); } else { - ib.put(idx, hi); - ib.put(idx+1, lo); + idx = idx << 1 ; // 8-byte to 4-byte offset + int lo = (int) ( ( v ) & 0x00000000FFFFFFFFL ) ; + int hi = (int) ( ( v >> 32 ) & 0x00000000FFFFFFFFL ) ; + if(BufferFactory.isLittleEndian()) { + ib.put(idx, lo); + ib.put(idx+1, hi); + } else { + ib.put(idx, hi); + ib.put(idx+1, lo); + } } return this; } @@ -182,4 +172,9 @@ public class PointerBuffer { backup[i] = get(i); } } + + public static int elementSize() { + return CPU.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG; + } + } diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase index 57ad05c..851c400 100755 --- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase +++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase @@ -113,26 +113,6 @@ public class PointerBuffer { return res; } - /** - * Wraps pointer arrays created by native code. - * Note: In case this is not a 64bit system, each pointer is being converted. */ - public static PointerBuffer wrapNative2Java(ByteBuffer src, boolean keepDirect) { - PointerBuffer res; - if (CPU.is32Bit()) { - // Must convert each pointer from 32-bit to 64-bit - IntBuffer buf = src.asIntBuffer(); - int len = buf.capacity(); - res = (src.isDirect() && keepDirect) ? PointerBuffer.allocateDirect(len) : PointerBuffer.allocate(len); - for (int i = 0; i < len; i++) { - res.put(i, buf.get(i)); - } - } else { - res = new PointerBuffer(src); - res.updateBackup(); - } - return res; - } - public ByteBuffer getBuffer() { return bb; } @@ -145,10 +125,11 @@ public class PointerBuffer { if(0>idx || idx>=capacity) { throw new IndexOutOfBoundsException(); } - if(CPU.is32Bit()) + if(CPU.is32Bit()) { return ((IntBuffer)pb).get(idx); - else + } else { return ((LongBuffer)pb).get(idx); + } } public long get() { @@ -162,10 +143,11 @@ public class PointerBuffer { throw new IndexOutOfBoundsException(); } backup[idx] = v; - if (CPU.is32Bit()) + if(CPU.is32Bit()) { ((IntBuffer)pb).put(idx, (int)v); - else + } else { ((LongBuffer)pb).put(idx, v); + } return this; } @@ -184,5 +166,4 @@ public class PointerBuffer { public static int elementSize() { return CPU.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG; } - -}
\ No newline at end of file +} |