diff options
author | Sven Gothel <[email protected]> | 2010-03-30 01:53:58 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-03-30 01:53:58 +0200 |
commit | 7220416bcef3140883d3966d921442feae3107c4 (patch) | |
tree | 89355f1f5cd3256b3cb721a924d585de9acea672 /src/java/com/sun/gluegen/JavaEmitter.java | |
parent | 69fe372b874d913e2d1c27f1d103e1fced668ecf (diff) |
http://www.jogamp.org/bugzilla/show_bug.cgi?id=389
32bit/64bit values and arrays are misrepresented
- PointerBuffer is used to map 64bit integer values,
which is illegal due to the latest PointerBuffer changes,
where the underlying ByteBuffer is either 32bit wide
or 64bit wide (in respect to the pointer size).
The PointerBuffer semantic itself is correct,
but no more suitable to represent 64bit values and arrays.
A Int64Buffer (LongBuffer does not exist in CDC/CVM patch)
should be used instead.
- Determine use of Int64Buffer and PointerBuffer
Assuming the 1st step being solved, it has to determined
for which cases gluegen shall map a type to a PointerBuffer.
All pointer pointer types, regardless of a Opaque mapping, ie:
+++
typedef struct __MYAPIConfig * MYAPIConfig;
Opaque long MYAPIConfig
void foo(MYAPIConfig * ptrarray);
+++
The argument 'ptrarray' must be represented as a PointerBuffer
otherwise data is misrepresented in case:
- 32bit machines _and_
- array semantics - more than one value is being used
Impl:
java/com/sun/gluegen/JavaEmitter.java:
- Checks ptr-ptr for Opaque values
- Returns PointerBuffer mapping for ptr-ptr types
- Allow PointerBuffer being mapped as String[]
Very elaborated tests .. :)
++++++++++++
Misc Changes:
- Added <Type>.put(<Type>Buffer src) for Int64Buffer/PointerBuffer
Diffstat (limited to 'src/java/com/sun/gluegen/JavaEmitter.java')
-rw-r--r-- | src/java/com/sun/gluegen/JavaEmitter.java | 62 |
1 files changed, 53 insertions, 9 deletions
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; } |