diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/sun/gluegen/JavaMethodBindingEmitter.java | 18 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaType.java | 4 | ||||
-rwxr-xr-x | src/java/com/sun/gluegen/runtime/BufferFactory.java.javase | 15 |
3 files changed, 33 insertions, 4 deletions
diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index f7680c8..ecd83ac 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -745,12 +745,22 @@ public class JavaMethodBindingEmitter extends FunctionEmitter writer.println(";"); } else if (returnType.isNIOBuffer()) { writer.println(" if (_res == null) return null;"); - writer.print(" return BufferFactory.nativeOrder(_res)"); + writer.println(" BufferFactory.nativeOrder(_res);"); if (!returnType.isNIOByteBuffer()) { - String returnTypeName = returnType.getName().substring("java.nio.".length()); - writer.print(".as" + returnTypeName + "()"); + // See whether we have to expand pointers to longs + if (getBinding().getCReturnType().pointerDepth() >= 2) { + if (!returnType.isNIOLongBuffer()) { + throw new RuntimeException("While emitting glue code for " + getName() + + ": can not legally make pointers opaque to anything but longs"); + } + writer.println(" return BufferFactory.asPointerBuffer(_res);"); + } else { + String returnTypeName = returnType.getName().substring("java.nio.".length()); + writer.println(" return _res.as" + returnTypeName + "()"); + } + } else { + writer.println(" return _res;"); } - writer.println(";"); } else if (returnType.isArrayOfCompoundTypeWrappers()) { writer.println(" if (_res == null) return null;"); writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java index 800c16f..1f795ef 100644 --- a/src/java/com/sun/gluegen/JavaType.java +++ b/src/java/com/sun/gluegen/JavaType.java @@ -339,6 +339,10 @@ public class JavaType { (java.nio.Buffer.class.isAssignableFrom(clazz.getComponentType()))); } + public boolean isNIOLongBuffer() { + return (clazz == java.nio.LongBuffer.class); + } + public boolean isString() { return (clazz == java.lang.String.class); } diff --git a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase index a883316..3986bf6 100755 --- a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase +++ b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase @@ -281,4 +281,19 @@ public class BufferFactory { throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining); } } + + public static LongBuffer asPointerBuffer(ByteBuffer src) { + if (CPU.is32Bit()) { + // Must convert each pointer from 32-bit to 64-bit + IntBuffer buf = src.asIntBuffer(); + int len = buf.capacity(); + LongBuffer res = LongBuffer.wrap(new long[len]); + for (int i = 0; i < len; i++) { + res.put(i, buf.get(i)); + } + return res; + } else { + return src.asLongBuffer(); + } + } } |