summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-03-22 17:00:26 +0100
committerSven Gothel <[email protected]>2012-03-22 17:00:26 +0100
commit3d527ea538c9e9897f86a0f6bdae0cab44d239c3 (patch)
tree7500881a0bff25538e69d4a4f6c5fab3ee228d71 /src
parentcda1f9f66528cd7e16dc807840d927fd452e1dd6 (diff)
Fix 'NIOOnly' impl ; Use 'final' in gen. Java stubs ;
- Fix 'NIOOnly' impl - Use 'final' in gen. Java stubs ; - No null check for Buffers.isDirect(arrayArg) [required] - Clarify Buffer arg API doc (NIOOnly or NIODirectOnly) - cleaned up loop / branch (CMethodBindingEmitter) - remove unsued vars/code - Tests: - covers normal/NIOOnly/NIODirectOnly - covers passing null for array and NIO
Diffstat (limited to 'src')
-rw-r--r--src/java/com/jogamp/gluegen/CMethodBindingEmitter.java34
-rw-r--r--src/java/com/jogamp/gluegen/JavaConfiguration.java51
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java31
-rw-r--r--src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java62
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java30
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg9
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c9
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h7
8 files changed, 124 insertions, 109 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
index 114f091..23c2b95 100644
--- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
@@ -444,7 +444,6 @@ public class CMethodBindingEmitter extends FunctionEmitter {
Type cReturnType = binding.getCReturnType();
JavaType javaReturnType = binding.getJavaReturnType();
- String capitalizedComponentType = null;
if (!cReturnType.isVoid()) {
writer.print(" ");
// Note we must respect const/volatile for return argument
@@ -472,8 +471,6 @@ public class CMethodBindingEmitter extends FunctionEmitter {
}
String javaTypeName = componentType.getName();
- capitalizedComponentType =
- "" + Character.toUpperCase(javaTypeName.charAt(0)) + javaTypeName.substring(1);
String javaArrayTypeName = "j" + javaTypeName + "Array";
writer.print(" ");
writer.print(javaArrayTypeName);
@@ -567,22 +564,6 @@ public class CMethodBindingEmitter extends FunctionEmitter {
null);
}
- for (int i = 0; i < binding.getNumArguments(); i++) {
- JavaType type = binding.getJavaArgumentType(i);
- if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) {
- continue;
- }
-
- if (type.isCompoundTypeWrapper() ||
- (type.isNIOBuffer() && !forIndirectBufferAndArrayImplementation)) {
- String javaArgName = binding.getArgumentName(i);
- emitPointerConversion(writer, binding, type,
- binding.getCArgumentType(i), javaArgName,
- pointerConversionArgumentName(javaArgName),
- byteOffsetArgName(i));
- }
- }
-
// Convert all arrays to pointers, and get UTF-8 versions of jstring args
for (int i = 0; i < binding.getNumArguments(); i++) {
JavaType javaArgType = binding.getJavaArgumentType(i);
@@ -592,9 +573,15 @@ public class CMethodBindingEmitter extends FunctionEmitter {
}
String javaArgName = binding.getArgumentName(i);
- if (javaArgType.isArray() ||
- (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation) ||
- javaArgType.isArrayOfCompoundTypeWrappers()) {
+ if (javaArgType.isCompoundTypeWrapper() ||
+ (javaArgType.isNIOBuffer() && !forIndirectBufferAndArrayImplementation ) ) {
+ emitPointerConversion(writer, binding, javaArgType,
+ binding.getCArgumentType(i), javaArgName,
+ pointerConversionArgumentName(javaArgName),
+ byteOffsetArgName(i));
+ } else if (javaArgType.isArray() ||
+ javaArgType.isArrayOfCompoundTypeWrappers() ||
+ ( javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation ) ) {
boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType);
writer.println(" if ( NULL != " + javaArgName + " ) {");
@@ -786,7 +773,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
String convName = pointerConversionArgumentName(javaArgName);
if (!needsDataCopy) {
- writer.println(" if ( NULL != " + javaArgName + " && JNI_FALSE == " + isNIOArgName(i) + " ) {");
+ writer.println(" if ( JNI_FALSE == " + isNIOArgName(i) + " && NULL != " + javaArgName + " ) {");
// Release array
final String modeFlag = isConstPtr(cArgType) || isConstPtrPtr(cArgType) ? "JNI_ABORT" : "0" ;
@@ -1052,7 +1039,6 @@ public class CMethodBindingEmitter extends FunctionEmitter {
} else {
pointerType = retType.asArray().getElementType();
}
- Type baseType = pointerType.asPointer().getTargetType();
writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx +
", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], sizeof(" + pointerType.getName() + ")));");
writer.println(" }");
diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java
index 87d8978..d1cb46a 100644
--- a/src/java/com/jogamp/gluegen/JavaConfiguration.java
+++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java
@@ -147,10 +147,10 @@ public class JavaConfiguration {
private Set<Pattern> ignoreNots = new HashSet<Pattern>();
private Set<Pattern> unignores = new HashSet<Pattern>();
private Set<Pattern> unimplemented = new HashSet<Pattern>();
- private boolean forceNioOnly4All = false;
- private Set<String> nioOnly = new HashSet<String>();
- private boolean forceNioDirectOnly4All = false;
- private Set<String> nioDirectOnly = new HashSet<String>();
+ private boolean forceUseNIOOnly4All = false;
+ private Set<String> useNIOOnly = new HashSet<String>();
+ private boolean forceUseNIODirectOnly4All = false;
+ private Set<String> useNIODirectOnly = new HashSet<String>();
private Set<String> manuallyImplement = new HashSet<String>();
private Map<String, List<String>> customJavaCode = new HashMap<String, List<String>>();
private Map<String, List<String>> classJavadoc = new HashMap<String, List<String>>();
@@ -502,25 +502,28 @@ public class JavaConfiguration {
return argumentsAreString.get(functionName);
}
- public boolean isForceNioOnly4All() { return forceNioOnly4All; }
+ public boolean isForceUsingNIOOnly4All() { return forceUseNIOOnly4All; }
- public void addNioOnly(String fname ) {
- nioOnly.add(fname);
+ public void addUseNIOOnly(String fname ) {
+ useNIOOnly.add(fname);
}
- public boolean nioOnly(String functionName) {
- return forceNioOnly4All || nioOnly.contains(functionName);
+ /** Returns true if the given function should only create a java.nio
+ variant, and no array variants, for <code>void*</code> and other
+ C primitive pointers. NIO only still allows usage of array backed not direct Buffers. */
+ public boolean useNIOOnly(String functionName) {
+ return useNIODirectOnly(functionName) || forceUseNIOOnly4All || useNIOOnly.contains(functionName);
}
- public boolean isForceNioDirectOnly4All() { return forceNioDirectOnly4All; }
-
- public void addNioDirectOnly(String fname ) {
- nioDirectOnly.add(fname);
+ public void addUseNIODirectOnly(String fname ) {
+ useNIODirectOnly.add(fname);
}
/** Returns true if the given function should only create a java.nio
variant, and no array variants, for <code>void*</code> and other
- C primitive pointers. */
- public boolean nioDirectOnly(String functionName) {
- return forceNioDirectOnly4All || nioDirectOnly.contains(functionName);
+ C primitive pointers. NIO direct only does only allow direct Buffers.
+ Implies useNIOOnly !
+ */
+ public boolean useNIODirectOnly(String functionName) {
+ return forceUseNIODirectOnly4All || useNIODirectOnly.contains(functionName);
}
/** Returns true if the glue code for the given function will be
@@ -961,19 +964,19 @@ public class JavaConfiguration {
readClassJavadoc(tok, filename, lineNo);
// Warning: make sure delimiters are reset at the top of this loop
// because readClassJavadoc changes them.
- } else if (cmd.equalsIgnoreCase("NioOnly")) {
- String funcName = readString("NioOnly", tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("NIOOnly")) {
+ String funcName = readString("NIOOnly", tok, filename, lineNo);
if(funcName.equals("__ALL__")) {
- forceNioOnly4All=true;
+ forceUseNIOOnly4All=true;
} else {
- addNioOnly( funcName );
+ addUseNIOOnly( funcName );
}
- } else if (cmd.equalsIgnoreCase("NioDirectOnly")) {
- String funcName = readString("NioDirectOnly", tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("NIODirectOnly")) {
+ String funcName = readString("NIODirectOnly", tok, filename, lineNo);
if(funcName.equals("__ALL__")) {
- forceNioDirectOnly4All=true;
+ forceUseNIODirectOnly4All=true;
} else {
- addNioDirectOnly( funcName );
+ addUseNIODirectOnly( funcName );
}
} else if (cmd.equalsIgnoreCase("EmitStruct")) {
forcedStructs.add(readString("EmitStruct", tok, filename, lineNo));
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 7ab3aca..99a5796 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -72,7 +72,6 @@ public class JavaEmitter implements GlueEmitter {
private StructLayout layout;
private TypeDictionary typedefDictionary;
- private TypeDictionary structDictionary;
private Map<Type, Type> canonMap;
protected JavaConfiguration cfg;
@@ -196,12 +195,12 @@ public class JavaEmitter implements GlueEmitter {
parseValue = value;
}
//System.err.println("parsing " + value + " as long w/ radix " + radix);
- long longVal = Long.parseLong(parseValue, radix);
+ Long.parseLong(parseValue, radix);
return radix;
} catch (NumberFormatException e) {
try {
// see if it's a double or float
- double dVal = Double.parseDouble(value);
+ Double.parseDouble(value);
return 10;
} catch (NumberFormatException e2) {
throw new RuntimeException(
@@ -376,7 +375,6 @@ public class JavaEmitter implements GlueEmitter {
Map<Type, Type> canonMap) throws Exception {
this.typedefDictionary = typedefDictionary;
- this.structDictionary = structDictionary;
this.canonMap = canonMap;
if ((cfg.allStatic() || cfg.emitInterface()) && !cfg.structsOnly()) {
@@ -498,7 +496,8 @@ public class JavaEmitter implements GlueEmitter {
!signatureOnly && needsBody,
cfg.tagNativeBinding(),
false,
- cfg.nioDirectOnly(binding.getName()),
+ cfg.useNIOOnly(binding.getName()),
+ cfg.useNIODirectOnly(binding.getName()),
false,
false,
false,
@@ -564,7 +563,8 @@ public class JavaEmitter implements GlueEmitter {
false,
cfg.tagNativeBinding(),
true,
- cfg.nioDirectOnly(binding.getName()),
+ cfg.useNIOOnly(binding.getName()),
+ cfg.useNIODirectOnly(binding.getName()),
true,
true,
false,
@@ -599,7 +599,7 @@ public class JavaEmitter implements GlueEmitter {
true, // NOTE: we always disambiguate with a suffix now, so this is optional
cfg.allStatic(),
(binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue),
- !cfg.nioDirectOnly(binding.getName()),
+ !cfg.useNIODirectOnly(binding.getName()),
machDescJava);
prepCEmitter(binding, cEmitter);
allEmitters.add(cEmitter);
@@ -751,7 +751,6 @@ public class JavaEmitter implements GlueEmitter {
TypeDictionary structDictionary,
Map<Type, Type> canonMap) throws Exception {
this.typedefDictionary = typedefDictionary;
- this.structDictionary = structDictionary;
this.canonMap = canonMap;
}
@@ -964,6 +963,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.tagNativeBinding(),
false,
true, // FIXME: should unify this with the general emission code
+ true, // FIXME: should unify this with the general emission code
false,
false, // FIXME: should unify this with the general emission code
false, // FIXME: should unify this with the general emission code
@@ -983,6 +983,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.tagNativeBinding(),
true,
true, // FIXME: should unify this with the general emission code
+ true, // FIXME: should unify this with the general emission code
true,
true, // FIXME: should unify this with the general emission code
false, // FIXME: should unify this with the general emission code
@@ -1560,8 +1561,8 @@ public class JavaEmitter implements GlueEmitter {
CodeGenUtils.EmissionCallback docEmitter =
new CodeGenUtils.EmissionCallback() {
public void emit(PrintWriter w) {
- for (Iterator iter = intfDocs.iterator(); iter.hasNext(); ) {
- w.println((String) iter.next());
+ for (Iterator<String> iter = intfDocs.iterator(); iter.hasNext(); ) {
+ w.println(iter.next());
}
}
};
@@ -1590,8 +1591,8 @@ public class JavaEmitter implements GlueEmitter {
CodeGenUtils.EmissionCallback docEmitter =
new CodeGenUtils.EmissionCallback() {
public void emit(PrintWriter w) {
- for (Iterator iter = implDocs.iterator(); iter.hasNext(); ) {
- w.println((String) iter.next());
+ for (Iterator<String> iter = implDocs.iterator(); iter.hasNext(); ) {
+ w.println(iter.next());
}
}
};
@@ -1867,7 +1868,7 @@ public class JavaEmitter implements GlueEmitter {
// FIXME: should add new configuration flag for this
if (canProduceArrayVariant[0] && (binding.signatureUsesCPrimitivePointers() || binding.signatureUsesCArrays()) &&
- !cfg.nioDirectOnly(binding.getName()) && !cfg.nioOnly(binding.getName())) {
+ !cfg.useNIOOnly(binding.getName()) ) {
result.add(lowerMethodBindingPointerTypes(binding, true, null));
}
} else {
@@ -1877,10 +1878,6 @@ public class JavaEmitter implements GlueEmitter {
return result;
}
- private String resultName() {
- return "_res";
- }
-
private Type canonicalize(Type t) {
Type res = canonMap.get(t);
if (res != null) {
diff --git a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java
index f7b1466..bd99486 100644
--- a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java
@@ -72,7 +72,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
protected boolean emitBody;
protected boolean eraseBufferAndArrayTypes;
- protected boolean directNIOOnly;
+ protected boolean useNIOOnly;
+ protected boolean useNIODirectOnly;
protected boolean forImplementingMethodCall;
protected boolean forDirectBufferImplementation;
protected boolean forIndirectBufferAndArrayImplementation;
@@ -106,7 +107,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
boolean emitBody,
boolean tagNativeBinding,
boolean eraseBufferAndArrayTypes,
- boolean directNIOOnly,
+ boolean useNIOOnly,
+ boolean useNIODirectOnly,
boolean forImplementingMethodCall,
boolean forDirectBufferImplementation,
boolean forIndirectBufferAndArrayImplementation,
@@ -120,7 +122,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
this.emitBody = emitBody;
this.tagNativeBinding = tagNativeBinding;
this.eraseBufferAndArrayTypes = eraseBufferAndArrayTypes;
- this.directNIOOnly = directNIOOnly;
+ this.useNIOOnly = useNIOOnly;
+ this.useNIODirectOnly = useNIODirectOnly;
this.forImplementingMethodCall = forImplementingMethodCall;
this.forDirectBufferImplementation = forDirectBufferImplementation;
this.forIndirectBufferAndArrayImplementation = forIndirectBufferAndArrayImplementation;
@@ -141,7 +144,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
emitBody = arg.emitBody;
tagNativeBinding = arg.tagNativeBinding;
eraseBufferAndArrayTypes = arg.eraseBufferAndArrayTypes;
- directNIOOnly = arg.directNIOOnly;
+ useNIOOnly = arg.useNIOOnly;
+ useNIODirectOnly = arg.useNIODirectOnly;
forImplementingMethodCall = arg.forImplementingMethodCall;
forDirectBufferImplementation = arg.forDirectBufferImplementation;
forIndirectBufferAndArrayImplementation = arg.forIndirectBufferAndArrayImplementation;
@@ -352,7 +356,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
if (forDirectBufferImplementation || forIndirectBufferAndArrayImplementation) {
if (type.isNIOBuffer()) {
writer.print(", int " + byteOffsetArgName(i));
- if(!directNIOOnly) {
+ if(!useNIODirectOnly) {
writer.print(", boolean " + isNIOArgName(i));
}
} else if (type.isNIOBufferArray()) {
@@ -362,8 +366,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
// Add offset argument after each primitive array
if (type.isPrimitiveArray()) {
- if(directNIOOnly) {
- throw new RuntimeException("NIODirectOnly "+binding+" is set, but "+getArgumentName(i)+" is a primitive array");
+ if(useNIOOnly) {
+ throw new RuntimeException("NIO[Direct]Only "+binding+" is set, but "+getArgumentName(i)+" is a primitive array");
}
writer.print(", int " + offsetArgName(i));
}
@@ -373,7 +377,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
protected String getImplMethodName() {
- return binding.getName() + ( directNIOOnly ? "0" : "1" );
+ return binding.getName() + ( useNIODirectOnly ? "0" : "1" );
}
protected String byteOffsetArgName(int i) {
@@ -456,19 +460,18 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
} else {
JavaType javaType = binding.getJavaArgumentType(i);
if (javaType.isNIOBuffer()) {
- if (directNIOOnly) {
+ if (useNIODirectOnly) {
writer.println(" if (!Buffers.isDirect(" + getArgumentName(i) + "))");
writer.println(" throw new " + getRuntimeExceptionType() + "(\"Argument \\\"" +
- getArgumentName(i) + "\\\" was not a direct buffer\");");
+ getArgumentName(i) + "\\\" is not a direct buffer\");");
} else {
- writer.print(" boolean " + isNIOArgName(i) + " = ");
- writer.println(getArgumentName(i) + " != null && Buffers.isDirect(" + getArgumentName(i) + ");");
+ writer.println(" final boolean " + isNIOArgName(i) + " = Buffers.isDirect(" + getArgumentName(i) + ");");
}
} else if (javaType.isNIOBufferArray()) {
// All buffers passed down in an array of NIO buffers must be direct
String argName = getArgumentName(i);
String arrayName = byteOffsetArrayArgName(i);
- writer.println(" int[] " + arrayName + " = new int[" + argName + ".length];");
+ writer.println(" final int[] " + arrayName + " = new int[" + argName + ".length];");
// Check direct buffer properties of all buffers within
writer.println(" if (" + argName + " != null) {");
writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {");
@@ -504,7 +507,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
if (javaType.isArrayOfCompoundTypeWrappers()) {
String argName = getArgumentName(i);
String tempArrayName = argName + COMPOUND_ARRAY_SUFFIX;
- writer.println(" ByteBuffer[] " + tempArrayName + " = new ByteBuffer[" + argName + ".length];");
+ writer.println(" final ByteBuffer[] " + tempArrayName + " = new ByteBuffer[" + argName + ".length];");
writer.println(" for (int _ctr = 0; _ctr < + " + argName + ".length; _ctr++) {");
writer.println(" " + javaType.getName() + " _tmp = " + argName + "[_ctr];");
writer.println(" " + tempArrayName + "[_ctr] = ((_tmp == null) ? null : _tmp.getBuffer());");
@@ -530,13 +533,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
if (!returnType.isVoid()) {
if (returnType.isCompoundTypeWrapper() ||
returnType.isNIOBuffer()) {
- writer.println("ByteBuffer _res;");
+ writer.println("final ByteBuffer _res;");
needsResultAssignment = true;
} else if (returnType.isArrayOfCompoundTypeWrappers()) {
- writer.println("ByteBuffer[] _res;");
+ writer.println("final ByteBuffer[] _res;");
needsResultAssignment = true;
} else if (((epilogue != null) && (epilogue.size() > 0)) ||
binding.signatureUsesArraysOfCompoundTypeWrappers()) {
+ writer.print("final ");
emitReturnType(writer);
writer.println(" _res;");
needsResultAssignment = true;
@@ -597,14 +601,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
if (type.isNIOBuffer()) {
if(type.isNIOPointerBuffer()) {
- if (directNIOOnly) {
+ if (useNIODirectOnly) {
writer.print( getArgumentName(i)+ " != null ? " + getArgumentName(i) + ".getBuffer() : null");
} else {
writer.print( isNIOArgName(i) + " ? ( " + getArgumentName(i)+ " != null ? " + getArgumentName(i) + ".getBuffer() : null )");
writer.print( " : Buffers.getArray(" + getArgumentName(i) + ")" );
}
} else {
- if (directNIOOnly) {
+ if (useNIODirectOnly) {
writer.print( getArgumentName(i) );
} else {
writer.print( isNIOArgName(i) + " ? " + getArgumentName(i) + " : Buffers.getArray(" + getArgumentName(i) + ")" );
@@ -623,7 +627,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
}
if (type.isNIOBuffer()) {
- if (directNIOOnly) {
+ if (useNIODirectOnly) {
writer.print( ", Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")");
} else {
writer.print( ", " + isNIOArgName(i) + " ? Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")");
@@ -653,12 +657,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
}
if (type.isNIOBuffer()) {
- if (!directNIOOnly) {
+ if (!useNIODirectOnly) {
writer.print( ", " + isNIOArgName(i) );
}
} else if (type.isPrimitiveArray()) {
- if (directNIOOnly) {
- throw new RuntimeException("NIODirectOnly "+binding+" is set, but "+getArgumentName(i)+" is a primitive array");
+ if (useNIOOnly) {
+ throw new RuntimeException("NIO[Direct]Only "+binding+" is set, but "+getArgumentName(i)+" is a primitive array");
}
writer.print( ", false");
}
@@ -715,14 +719,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
throw new RuntimeException("ReturnedArrayLength directive currently only supported for pointers to compound types " +
"(error occurred while generating Java glue code for " + getName() + ")");
}
- writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];");
+ writer.println(" final " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];");
writer.println(" for (int _count = 0; _count < " + expr + "; _count++) {");
// Create temporary ByteBuffer slice
// FIXME: probably need Type.getAlignedSize() for arrays of
// compound types (rounding up to machine-dependent alignment)
writer.println(" _res.position(_count * " + getReturnTypeString(true) + ".size());");
writer.println(" _res.limit ((1 + _count) * " + getReturnTypeString(true) + ".size());");
- writer.println(" ByteBuffer _tmp = _res.slice();");
+ writer.println(" final ByteBuffer _tmp = _res.slice();");
writer.println(" Buffers.nativeOrder(_tmp);");
writer.println(" _res.position(0);");
writer.println(" _res.limit(_res.capacity());");
@@ -756,7 +760,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
}
} else if (returnType.isArrayOfCompoundTypeWrappers()) {
writer.println(" if (_res == null) return null;");
- writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];");
+ writer.println(" final " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];");
writer.println(" for (int _count = 0; _count < _res.length; _count++) {");
writer.println(" _retarray[_count] = " + getReturnTypeString(true) + ".create(_res[_count]);");
writer.println(" }");
@@ -838,13 +842,17 @@ public class JavaMethodBindingEmitter extends FunctionEmitter {
writer.print(enumType.getEnumName(j));
}
writer.println("</code>");
- } else if (directNIOOnly && javaType.isNIOBuffer()) {
+ } else if (javaType.isNIOBuffer()) {
writer.println();
writer.print(emitter.getBaseIndentString());
writer.print(" ");
writer.print("@param ");
writer.print(getArgumentName(i));
- writer.print(" a direct {@link " + javaType.getName() + "}");
+ if (useNIODirectOnly) {
+ writer.print(" a direct only {@link " + javaType.getName() + "}");
+ } else {
+ writer.print(" a direct or array-backed {@link " + javaType.getName() + "}");
+ }
}
}
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
index 8d9c73a..8dff4be 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -466,29 +466,30 @@ public class BaseClass extends JunitTracer {
result = binding.bufferTest(lb);
Assert.assertTrue("Wrong result: "+result, 10==result);
+ result = binding.bufferTestNioOnly(lb);
+ Assert.assertTrue("Wrong result: "+result, 10==result);
+
if(direct) {
- result = binding.bufferTestNioOnly(lb);
+ result = binding.bufferTestNioDirectOnly(lb);
Assert.assertTrue("Wrong result: "+result, 10==result);
} else {
Exception e = null;
try {
- binding.bufferTestNioOnly(lb);
+ binding.bufferTestNioDirectOnly(lb);
} catch (RuntimeException re) {
e = re;
}
Assert.assertNotNull(e);
}
-
+
result = binding.doubleTest(context, lb, lb1, bb2, lb2);
Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
result = binding.doubleTest(context, lb, larray1, larray1_offset, bb2, larray2, larray2_offset);
Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
- if(direct) {
- result = binding.doubleTestNioOnly(context, lb, lb1, bb2, lb2);
- Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
- }
+ result = binding.doubleTestNioOnly(context, lb, lb1, bb2, lb2);
+ Assert.assertTrue("Wrong result: "+result, 1+10+8000+100+80000==result);
result = binding.mixedTest(context, lb, lb1);
Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
@@ -496,10 +497,8 @@ public class BaseClass extends JunitTracer {
result = binding.mixedTest(context, lb, larray1, larray1_offset);
Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
- if(direct) {
- result = binding.mixedTestNioOnly(context, lb, lb1);
- Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
- }
+ result = binding.mixedTestNioOnly(context, lb, lb1);
+ Assert.assertTrue("Wrong result: "+result, 1+10+8000==result);
result = binding.nopTest();
Assert.assertTrue("Wrong result: "+result, 42==result);
@@ -513,6 +512,9 @@ public class BaseClass extends JunitTracer {
i = binding.stringArrayRead(new String[] { "1234", "5678", "9a" }, 3);
Assert.assertTrue("Wrong result: "+i, 10==i);
+ i = binding.stringArrayRead(null, 0);
+ Assert.assertTrue("Wrong result: "+i, 0==i);
+
IntBuffer ib = newIntBuffer(3, direct);
ib.put(0, 1);
ib.put(1, 2);
@@ -523,9 +525,15 @@ public class BaseClass extends JunitTracer {
i = binding.intArrayRead(ib, 3);
Assert.assertTrue("Wrong result: "+i, 6==i);
+ i = binding.intArrayRead(null, 0);
+ Assert.assertTrue("Wrong result: "+i, 0==i);
+
i = binding.intArrayRead(iarray, 0, 3);
Assert.assertTrue("Wrong result: "+i, 6==i);
+ i = binding.intArrayRead(null, 0, 0);
+ Assert.assertTrue("Wrong result: "+i, 0==i);
+
{
long cfg_base = 0xAABBCCDD11223344L;
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
index 17890eb..490bf2d 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg
@@ -1,8 +1,9 @@
-NIODirectOnly arrayTestNioOnly
-NIODirectOnly bufferTestNioOnly
-NIODirectOnly mixedTestNioOnly
-NIODirectOnly doubleTestNioOnly
+NIOOnly arrayTestFooNioOnly
+NIOOnly bufferTestNioOnly
+NIODirectOnly bufferTestNioDirectOnly
+NIOOnly mixedTestNioOnly
+NIOOnly doubleTestNioOnly
ReturnsString intToStr
ArgumentIsString strToInt 0
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
index ebb1e08..1adf824 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -59,6 +59,7 @@ MYAPI void MYAPIENTRY arrayTestFoo3( foo * array ) {
MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(const foo * array) {
int j;
foo * * result = calloc(ARRAY_SIZE, sizeof(foo *));
+ assert(NULL!=array);
for(j=0; j<ARRAY_SIZE; j++) {
result[j] = (foo *) ( array + ARRAY_SIZE * j ) ;
}
@@ -143,6 +144,10 @@ MYAPI foo MYAPIENTRY bufferTestNioOnly(void * object) {
return bufferTest(object);
}
+MYAPI foo MYAPIENTRY bufferTestNioDirectOnly(void * object) {
+ return bufferTest(object);
+}
+
MYAPI foo MYAPIENTRY mixedTestNioOnly(int64_t context, void * object, foo * array ) {
return mixedTest(context, object, array);
}
@@ -286,12 +291,14 @@ MYAPI TK_Surface * MYAPIENTRY createSurface() {
}
MYAPI void MYAPIENTRY destroySurface(TK_Surface * surface) {
+ assert(NULL!=surface);
free(surface->clips);
// free(surface->engine);
free(surface);
}
static void dumpTK_ComplicatedSuperSet(TK_ComplicatedSuperSet * s) {
+ assert(NULL!=s);
fprintf(stderr, "TK_ComplicatedSuperSet [\n");
fprintf(stderr, " cs.b1 0x%X\n", s->bits1);
@@ -382,6 +389,7 @@ MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() {
}
MYAPI Bool MYAPIENTRY hasInitValues(TK_ComplicatedSuperSet * s) {
+ assert(NULL!=s);
Bool b = s->bits1 == 0xA0U &&
s->sub1.bits1 == 0xA1U &&
s->sub1.id == 0x12345678U &&
@@ -415,6 +423,7 @@ MYAPI Bool MYAPIENTRY hasInitValues(TK_ComplicatedSuperSet * s) {
}
MYAPI void MYAPIENTRY destroyComplicatedSuperSet(TK_ComplicatedSuperSet * s) {
+ assert(NULL!=s);
free(s);
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
index 76a15f2..de57b66 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -74,6 +74,9 @@ MYAPI foo MYAPIENTRY arrayTestFooNioOnly(int64_t context, foo * array );
/** Returns *((foo *)object) */
MYAPI foo MYAPIENTRY bufferTestNioOnly(void * object);
+/** Returns *((foo *)object) */
+MYAPI foo MYAPIENTRY bufferTestNioDirectOnly(void * object);
+
/** Returns Sum(array) + context + *((foo *)object) */
MYAPI foo MYAPIENTRY mixedTestNioOnly(int64_t context, void * object, foo * array );
@@ -86,10 +89,10 @@ MYAPI int MYAPIENTRY strToInt(const char* str);
/** Returns itoa(i) - not thread safe */
MYAPI const char * MYAPIENTRY intToStr(int i);
-/** Returns the length of all strings */
+/** Returns the length of all strings, strings maybe NULL. */
MYAPI int MYAPIENTRY stringArrayRead(const char * * strings, int num);
-/** Returns the sum of all integers */
+/** Returns the sum of all integers, ints maybe NULL. */
MYAPI int MYAPIENTRY intArrayRead(const int * ints, int num);
/** Increases the elements by 1, and returns the sum