From 86c868fcb78b53f02ad2bae1770e4db61b892678 Mon Sep 17 00:00:00 2001 From: Wade Walker Date: Tue, 4 Mar 2014 15:21:35 -0600 Subject: Remove warnings in emitted C code. Fix 1: Only emit "int * _offsetHandle = NULL" if it will be used, to avoid unused variable warning. Fix 2: Add "unsigned" to typecasts in C function calls when needed to avoid implicit typecast warning. This commit also adds a unit test for a method that uses an "unsigned char **" parameter, to mimic the JOCL clCreateProgramWithBinary() function that caused the typecast warnings. --- src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 12 +++++++++++- src/java/com/jogamp/gluegen/cgram/types/IntType.java | 5 +++++ src/java/com/jogamp/gluegen/cgram/types/PointerType.java | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/java/com') diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index d856767..39141f2 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -427,7 +427,8 @@ public class CMethodBindingEmitter extends FunctionEmitter { writer.println(" jsize _tmpArrayLen;"); // Pointer to the data in the Buffer, taking the offset into account - writer.println(" int * _offsetHandle = NULL;"); + if(type.isNIOBufferArray()) + writer.println(" int * _offsetHandle = NULL;"); emittedDataCopyTemps = true; } @@ -925,6 +926,15 @@ public class CMethodBindingEmitter extends FunctionEmitter { if (isConstPtrPtr(cArgType)) { writer.print("const "); } + + // if this is a pointer to an unsigned type, add unsigned to the name to avoid compiler warnings + if(cArgType.isPointer()) { + Type typeLast = ((PointerType)cArgType).getLastTargetType(); + if(typeLast.isInt() && (((IntType)typeLast).isPrimitiveUnsigned())) { + writer.print("unsigned "); + } + } + writer.print(cArgType.getName()); writer.print(") "); if (binding.getCArgumentType(i).isPointer() && javaArgType.isPrimitive()) { diff --git a/src/java/com/jogamp/gluegen/cgram/types/IntType.java b/src/java/com/jogamp/gluegen/cgram/types/IntType.java index ffc5696..6eeb997 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/IntType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/IntType.java @@ -82,6 +82,11 @@ public class IntType extends PrimitiveType implements Cloneable { return unsigned; } + /** Indicates whether this type is an unsigned primitive type, as opposed to a typedef type that's unsigned. */ + public boolean isPrimitiveUnsigned() { + return unsigned && !typedefedUnsigned; + } + @Override public String toString() { return getCVAttributesString() + ((isUnsigned() & (!typedefedUnsigned)) ? "unsigned " : "") + getName(); diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java index 4922d28..f4811c7 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java @@ -120,6 +120,13 @@ public class PointerType extends Type implements Cloneable { return targetType; } + public Type getLastTargetType() { + if(targetType.isPointer()) + return ((PointerType)targetType).getLastTargetType(); + else + return targetType; + } + @Override public boolean isFunctionPointer() { return targetType.isFunction(); -- cgit v1.2.3 From 0b2b05c25b5072ccbce0f92e66f29b45bde762cd Mon Sep 17 00:00:00 2001 From: Wade Walker Date: Tue, 4 Mar 2014 15:37:38 -0600 Subject: Fix accidental tabs. --- src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 14 +++++++------- .../com/jogamp/gluegen/cgram/types/PointerType.java | 8 ++++---- .../gluegen/test/junit/generation/BaseClass.java | 10 +++++----- .../com/jogamp/gluegen/test/junit/generation/test1.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 39141f2..d18ea3d 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -929,10 +929,10 @@ public class CMethodBindingEmitter extends FunctionEmitter { // if this is a pointer to an unsigned type, add unsigned to the name to avoid compiler warnings if(cArgType.isPointer()) { - Type typeLast = ((PointerType)cArgType).getLastTargetType(); - if(typeLast.isInt() && (((IntType)typeLast).isPrimitiveUnsigned())) { - writer.print("unsigned "); - } + Type typeLast = ((PointerType)cArgType).getLastTargetType(); + if(typeLast.isInt() && (((IntType)typeLast).isPrimitiveUnsigned())) { + writer.print("unsigned "); + } } writer.print(cArgType.getName()); @@ -1058,11 +1058,11 @@ public class CMethodBindingEmitter extends FunctionEmitter { writer.println(" " + arrayRes + " = (*env)->NewObjectArray(env, " + arrayResLength + ", (*env)->FindClass(env, \"java/nio/ByteBuffer\"), NULL);"); writer.println(" for (" + arrayIdx + " = 0; " + arrayIdx + " < " + arrayResLength + "; " + arrayIdx + "++) {"); Type retType = binding.getCSymbol().getReturnType(); - Type pointerType; + Type pointerType; if (retType.isPointer()) { - pointerType = retType.asPointer().getTargetType(); + pointerType = retType.asPointer().getTargetType(); } else { - pointerType = retType.asArray().getElementType(); + pointerType = retType.asArray().getElementType(); } writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx + ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], sizeof(" + pointerType.getName() + ")));"); diff --git a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java index f4811c7..af33f41 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/PointerType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/PointerType.java @@ -121,10 +121,10 @@ public class PointerType extends Type implements Cloneable { } public Type getLastTargetType() { - if(targetType.isPointer()) - return ((PointerType)targetType).getLastTargetType(); - else - return targetType; + if(targetType.isPointer()) + return ((PointerType)targetType).getLastTargetType(); + else + return targetType; } @Override 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 f0db24b..a97430a 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java @@ -560,10 +560,10 @@ public class BaseClass extends JunitTracer { Assert.assertTrue("Wrong result: "+i, 0==i); { - // one 0xff in each byte array + // one 0xff in each byte array // the referenced buffer must be direct, non direct is not supported - ByteBuffer bbB = Buffers.newDirectByteBuffer(new byte [] {(byte)0xaa, (byte)0xff, (byte)0xba, (byte)0xbe}); - bbB.rewind(); + ByteBuffer bbB = Buffers.newDirectByteBuffer(new byte [] {(byte)0xaa, (byte)0xff, (byte)0xba, (byte)0xbe}); + bbB.rewind(); PointerBuffer pbB = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct); PointerBuffer pbL = newPointerBuffer(Bindingtest1.ARRAY_SIZE, direct); for(int j=0; j