From 93b0bbc573fe1aaaac0eee1c471c09cc05e4d64c Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sat, 20 Dec 2008 09:41:40 +0000 Subject: 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 --- src/java/com/sun/gluegen/JavaMethodBindingEmitter.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/java/com/sun/gluegen/JavaMethodBindingEmitter.java') 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];"); -- cgit v1.2.3