diff options
author | Kenneth Russel <[email protected]> | 2008-12-20 09:41:40 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-12-20 09:41:40 +0000 |
commit | 93b0bbc573fe1aaaac0eee1c471c09cc05e4d64c (patch) | |
tree | 45332f3093835d4a4b709c81db6bc31a6067eac9 /src/java | |
parent | be28001c09aa922b0a7b07ebb51d50e8d41578c0 (diff) |
Fixed more bugs in glue code generation related to using opaque long
type for pointers returned in arrays: specifically, the return value
of glXChooseFBConfig. However, this fix contains an inherent memory
leak for certain C APIs because the original Buffer is not necessarily
available to be manually freed. Still, fixes remaining problems with
pbuffer support on X11 platforms.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/branches/JOGL_2_SANDBOX@119 a78bb65f-1512-4460-ba86-f6dc96a7bf27
Diffstat (limited to 'src/java')
-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(); + } + } } |