From be28001c09aa922b0a7b07ebb51d50e8d41578c0 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 14 Dec 2008 01:57:13 +0000 Subject: Fixed code generation bug when a non-ByteBuffer type (e.g., LongBuffer) is returned from a native method, which was occurring with glXChooseFBConfig with the new Opaque directive of GLXFBConfig to long git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/branches/JOGL_2_SANDBOX@118 a78bb65f-1512-4460-ba86-f6dc96a7bf27 --- .../com/sun/gluegen/JavaMethodBindingEmitter.java | 22 ++++++++++++++++++---- src/java/com/sun/gluegen/MethodBinding.java | 7 ++++--- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/java') diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index 525ff52..f7680c8 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -235,8 +235,17 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected String erasedTypeString(JavaType type, boolean skipBuffers) { if (eraseBufferAndArrayTypes) { - if (type.isNIOBuffer() || - type.isPrimitiveArray()) { + if (type.isNIOBuffer()) { + if (!skipBuffers) { + // Direct buffers and arrays sent down as Object (but + // returned as e.g. ByteBuffer) + return "Object"; + } + if (!type.isNIOByteBuffer()) { + // Return buffer requiring change of view from ByteBuffer to e.g. LongBuffer + return "java.nio.ByteBuffer"; + } + } else if (type.isPrimitiveArray()) { if (!skipBuffers) { // Direct buffers and arrays sent down as Object (but // returned as e.g. ByteBuffer) @@ -514,7 +523,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter if (!returnType.isVoid()) { if (returnType.isCompoundTypeWrapper() || - returnType.isNIOByteBuffer()) { + returnType.isNIOBuffer()) { writer.println("java.nio.ByteBuffer _res;"); needsResultAssignment = true; } else if (returnType.isArrayOfCompoundTypeWrappers()) { @@ -736,7 +745,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter writer.println(";"); } else if (returnType.isNIOBuffer()) { writer.println(" if (_res == null) return null;"); - writer.println(" return _res.order(java.nio.ByteOrder.nativeOrder());"); + writer.print(" return BufferFactory.nativeOrder(_res)"); + if (!returnType.isNIOByteBuffer()) { + String returnTypeName = returnType.getName().substring("java.nio.".length()); + writer.print(".as" + returnTypeName + "()"); + } + 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/MethodBinding.java b/src/java/com/sun/gluegen/MethodBinding.java index 04b73e2..5431874 100644 --- a/src/java/com/sun/gluegen/MethodBinding.java +++ b/src/java/com/sun/gluegen/MethodBinding.java @@ -314,10 +314,11 @@ public class MethodBinding { signatureUsesCompoundTypeWrappers = true; } - if (javaReturnType.isNIOByteBuffer() || + if (javaReturnType.isNIOBuffer() || javaReturnType.isArrayOfCompoundTypeWrappers()) { - // Needs setting of byte order which can't be done easily from - // native code + // Needs setting of byte order and possibly viewing as a + // different buffer type which can't be done easily from native + // code signatureUsesNIO = true; } -- cgit v1.2.3