diff options
Diffstat (limited to 'src/java/com')
-rw-r--r-- | src/java/com/jogamp/gluegen/runtime/Int64Buffer.java | 14 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/runtime/PointerBuffer.java | 14 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/CMethodBindingEmitter.java | 7 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaEmitter.java | 62 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaMethodBindingEmitter.java | 12 |
5 files changed, 96 insertions, 13 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java index 5f7cc33..98d0834 100644 --- a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java +++ b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java @@ -152,4 +152,18 @@ public abstract class Int64Buffer { public abstract Int64Buffer put(long value); + public Int64Buffer put(Int64Buffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + while (src.hasRemaining()) { + put(src.get()); + } + return this; + } + + public String toString() { + return "Int64Buffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + } + } diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java index a89dace..0adbb36 100644 --- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java @@ -156,4 +156,18 @@ public abstract class PointerBuffer { public abstract PointerBuffer put(long value); + public PointerBuffer put(PointerBuffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + while (src.hasRemaining()) { + put(src.get()); + } + return this; + } + + public String toString() { + return "PointerBuffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + } + } diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java index c91e992..022df39 100644 --- a/src/java/com/sun/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/CMethodBindingEmitter.java @@ -1009,7 +1009,12 @@ public class CMethodBindingEmitter extends FunctionEmitter System.err.println( "WARNING: No capacity specified for java.nio.Buffer return " + "value for function \"" + binding + "\";" + - " assuming size of equivalent C return type (sizeof(" + cReturnType.getName() + ")): " + binding); + " assuming size of equivalent C return type (sizeof(" + cReturnType.getName() + ")): " + binding); + /** + throw new RuntimeException( + "WARNING: No capacity specified for java.nio.Buffer return " + + "value for function \"" + binding + "\";" + + " C return type is " + cReturnType.getName() + ": " + binding); */ } writer.println(");"); } else if (javaReturnType.isString()) { diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 0a92735..25aeb16 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -1215,13 +1215,40 @@ public class JavaEmitter implements GlueEmitter { (opt.getTargetType().getName().equals("JNIEnv"))) { return JavaType.createForJNIEnv(); } + Type t = cType; // Opaque specifications override automatic conversions - TypeInfo info = cfg.typeInfo(cType, typedefDictionary); + // in case the identity is being used .. not if ptr-ptr + TypeInfo info = cfg.typeInfo(t, typedefDictionary); if (info != null) { - return info.javaType(); + boolean isPointerPointer = false; + if (t.pointerDepth() > 0 || t.arrayDimension() > 0) { + Type targetType; // target type + if (t.isPointer()) { + // t is <type>*, we need to get <type> + targetType = t.asPointer().getTargetType(); + } else { + // t is <type>[], we need to get <type> + targetType = t.asArray().getElementType(); + } + if (t.pointerDepth() == 2 || t.arrayDimension() == 2) { + // Get the target type of the target type (targetType was computer earlier + // as to be a pointer to the target type, so now we need to get its + // target type) + if (targetType.isPointer()) { + isPointerPointer = true; + + // t is<type>**, targetType is <type>*, we need to get <type> + Type bottomType = targetType.asPointer().getTargetType(); + System.out.println("INFO: Opaque Type: "+t+", targetType: "+targetType+", bottomType: "+bottomType+" is ptr-ptr"); + } + } + } + if(!isPointerPointer) { + return info.javaType(); + } } - Type t = cType; + if (t.isInt() || t.isEnum()) { switch ((int) t.getSize(curMachDesc)) { case 1: return javaType(Byte.TYPE); @@ -1302,11 +1329,16 @@ public class JavaEmitter implements GlueEmitter { if (targetType.isPointer()) { // t is<type>**, targetType is <type>*, we need to get <type> bottomType = targetType.asPointer().getTargetType(); + return JavaType.forNIOPointerBufferClass(); } else { // t is<type>[][], targetType is <type>[], we need to get <type> bottomType = targetType.asArray().getElementType(); + System.out.println("WARNING: typeToJavaType(ptr-ptr): "+t+", targetType: "+targetType+", bottomType: "+bottomType+" -> Unhandled!"); } + // Warning: The below code is not backed up by an implementation, + // the only working variant is a ptr-ptr type which results in a PointerBuffer. + // if (bottomType.isPrimitive()) { if (bottomType.isInt()) { switch ((int) bottomType.getSize(curMachDesc)) { @@ -1700,6 +1732,8 @@ public class JavaEmitter implements GlueEmitter { binding.renameMethodName(cfg.getJavaSymbolRename(sym.getName())); + // System.out.println("bindFunction(0) "+sym.getReturnType()); + if (cfg.returnsString(binding.getName())) { PointerType prt = sym.getReturnType().asPointer(); if (prt == null || @@ -1714,6 +1748,8 @@ public class JavaEmitter implements GlueEmitter { binding.setJavaReturnType(typeToJavaType(sym.getReturnType(), false, curMachDesc)); } + // System.out.println("bindFunction(1) "+binding.getJavaReturnType()); + // List of the indices of the arguments in this function that should be // converted from byte[] or short[] to String List<Integer> stringArgIndices = cfg.stringArguments(binding.getName()); @@ -1721,22 +1757,23 @@ public class JavaEmitter implements GlueEmitter { for (int i = 0; i < sym.getNumArguments(); i++) { Type cArgType = sym.getArgumentType(i); JavaType mappedType = typeToJavaType(cArgType, true, curMachDesc); - //System.out.println("C arg type -> \"" + cArgType + "\"" ); - //System.out.println(" Java -> \"" + mappedType + "\"" ); + // System.out.println("C arg type -> \"" + cArgType + "\"" ); + // System.out.println(" Java -> \"" + mappedType + "\"" ); // Take into account any ArgumentIsString configuration directives that apply if (stringArgIndices != null && stringArgIndices.contains(i)) { - //System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String "); + // System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String "); if (mappedType.isCVoidPointerType() || mappedType.isCCharPointerType() || mappedType.isCShortPointerType() || + mappedType.isNIOPointerBuffer() || (mappedType.isArray() && (mappedType.getJavaClass() == ArrayTypes.byteBufferArrayClass) || (mappedType.getJavaClass() == ArrayTypes.shortBufferArrayClass))) { // convert mapped type from: // void*, byte[], and short[] to String // ByteBuffer[] and ShortBuffer[] to String[] - if (mappedType.isArray()) { + if (mappedType.isArray() || mappedType.isNIOPointerBuffer()) { mappedType = javaType(ArrayTypes.stringArrayClass); } else { mappedType = javaType(String.class); @@ -1753,8 +1790,9 @@ public class JavaEmitter implements GlueEmitter { //System.out.println("During binding of [" + sym + "], added mapping from C type: " + cArgType + " to Java type: " + mappedType); } - //System.err.println("---> " + binding); - //System.err.println(" ---> " + binding.getCSymbol()); + // System.out.println("---> " + binding); + // System.out.println(" ---> " + binding.getCSymbol()); + // System.out.println("bindFunction(3) "+binding); return binding; } @@ -1764,6 +1802,8 @@ public class JavaEmitter implements GlueEmitter { MethodBinding result = inputBinding; boolean arrayPossible = false; + // System.out.println("lowerMethodBindingPointerTypes(0): "+result); + for (int i = 0; i < inputBinding.getNumArguments(); i++) { JavaType t = inputBinding.getJavaArgumentType(i); if (t.isCPrimitivePointerType()) { @@ -1818,6 +1858,8 @@ public class JavaEmitter implements GlueEmitter { } } + // System.out.println("lowerMethodBindingPointerTypes(1): "+result); + // Always return primitive pointer types as NIO buffers JavaType t = result.getJavaReturnType(); if (t.isCPrimitivePointerType()) { @@ -1840,6 +1882,8 @@ public class JavaEmitter implements GlueEmitter { } } + // System.out.println("lowerMethodBindingPointerTypes(2): "+result); + if (canProduceArrayVariant != null) { canProduceArrayVariant[0] = arrayPossible; } diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index b5b5b9c..4153e32 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -730,11 +730,17 @@ public class JavaMethodBindingEmitter extends FunctionEmitter if (!returnType.isNIOByteBuffer()) { // See whether we have to expand pointers to longs if (getBinding().getCReturnType().pointerDepth() >= 2) { - if (!returnType.isNIOPointerBuffer()) { + if (returnType.isNIOPointerBuffer()) { + writer.println(" return PointerBuffer.wrap(_res);"); + } else if (returnType.isNIOInt64Buffer()) { + writer.println(" return Int64Buffer.wrap(_res);"); + } else { throw new RuntimeException("While emitting glue code for " + getName() + - ": can not legally make pointers opaque to anything but longs"); + ": can not legally make pointers opaque to anything but PointerBuffer or Int64Buffer/long"); } - writer.println(" return PointerBuffer.wrap(_res);"); + } else if (getBinding().getCReturnType().pointerDepth() == 1 && + returnType.isNIOInt64Buffer()) { + writer.println(" return Int64Buffer.wrap(_res);"); } else { String returnTypeName = returnType.getName().substring("java.nio.".length()); writer.println(" return _res.as" + returnTypeName + "();"); |