diff options
author | Sven Gothel <[email protected]> | 2011-10-06 02:05:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-06 02:05:22 +0200 |
commit | e388426759e02e15ccc93b9df2e5c0400590d057 (patch) | |
tree | 2b37cc94003ecc76e3a1cc250d6745b746cf6a28 /src/java/com/jogamp | |
parent | 2fdff368a5e77c31fff242f286c61edabae2669e (diff) |
Enhance ReleasePrimitiveArrayCritical: Use mode-flag JNI_ABORT if array is const, ie no write-back
We shall consider the C header declaration as being correct
and no modification shall happen on const arrays.
Tested w/ unit tests and JOGL
+++
Cleanup JavaType: final immutable fields, proper CVoidPointer name
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r-- | src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 30 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 2 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaType.java | 38 |
3 files changed, 46 insertions, 24 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 5d0124c..114f091 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -48,8 +48,6 @@ import com.jogamp.gluegen.cgram.types.*; import java.util.logging.Logger; -import static java.util.logging.Level.*; - /** Emits the C-side component of the Java<->C JNI binding. */ public class CMethodBindingEmitter extends FunctionEmitter { @@ -528,6 +526,17 @@ public class CMethodBindingEmitter extends FunctionEmitter { return (type.getSize(machDesc) == 1); } + /** Checks a type (expected to be pointer) for const-ness */ + protected boolean isConstPtr(Type type) { + if (type.pointerDepth() != 1) { + return false; + } + if (type.asPointer().getTargetType().isConst()) { + return true; + } + return false; + } + /** Checks a type (expected to be pointer-to-pointer) for const-ness */ protected boolean isConstPtrPtr(Type type) { if (type.pointerDepth() != 2) { @@ -779,8 +788,9 @@ public class CMethodBindingEmitter extends FunctionEmitter { if (!needsDataCopy) { writer.println(" if ( NULL != " + javaArgName + " && JNI_FALSE == " + isNIOArgName(i) + " ) {"); - // Release array - writer.print(" (*env)->ReleasePrimitiveArrayCritical(env, " + javaArgName + ", " + convName + ", 0);"); + // Release array + final String modeFlag = isConstPtr(cArgType) || isConstPtrPtr(cArgType) ? "JNI_ABORT" : "0" ; + writer.print(" (*env)->ReleasePrimitiveArrayCritical(env, " + javaArgName + ", " + convName + ", "+modeFlag+");"); } else { writer.println(" if ( NULL != " + javaArgName + " ) {"); @@ -1373,9 +1383,9 @@ public class CMethodBindingEmitter extends FunctionEmitter { ptrTypeString = cType.getName(); } + writer.print(" "); if (!needsDataCopy) { // declare the pointer variable - writer.print(" "); writer.print(ptrTypeString); writer.print(" "); writer.print(cVariableName); @@ -1391,16 +1401,14 @@ public class CMethodBindingEmitter extends FunctionEmitter { cElementTypeName = cPtrType.getTargetType().asPointer().getName(); } if (isConstPtrPtr(cType)) { - writer.print(" const "+cElementTypeName+" *"); - } else { - writer.print(" "+cElementTypeName+" *"); + writer.print("const "); } + writer.print(cElementTypeName+" *"); } else { if (isConstPtrPtr(cType)) { - writer.print(" const " + ptrTypeString); - } else { - writer.print(" " + ptrTypeString); + writer.print("const "); } + writer.print(ptrTypeString); } writer.print(" "); writer.print(cVariableName); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index c7c6cc8..d768858 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -1241,7 +1241,7 @@ public class JavaEmitter implements GlueEmitter { // arrays, NIO buffers, or both in expandMethodBinding if (t.pointerDepth() == 1 || t.arrayDimension() == 1) { if (targetType.isVoid()) { - return JavaType.createForVoidPointer(); + return JavaType.createForCVoidPointer(); } else if (targetType.isInt()) { // size_t and intptr_t is always a PointerBuffer since size is arch dependent if ("size_t".equals(targetType.getName()) || "intptr_t".equals(targetType.getName())) { diff --git a/src/java/com/jogamp/gluegen/JavaType.java b/src/java/com/jogamp/gluegen/JavaType.java index 04d14de..a6cf890 100644 --- a/src/java/com/jogamp/gluegen/JavaType.java +++ b/src/java/com/jogamp/gluegen/JavaType.java @@ -59,10 +59,10 @@ public class JavaType { VOID, CHAR, SHORT, INT32, INT64, FLOAT, DOUBLE; } - private Class<?> clazz; // Primitive types and other types representable as Class objects - private String name; // Types we're generating glue code for (i.e., C structs) - private Type elementType; // Element type if this JavaType represents a C array - private C_PTR primitivePointerType; + private final Class<?> clazz; // Primitive types and other types representable as Class objects + private final String name; // Types we're generating glue code for (i.e., C structs) + private final Type elementType; // Element type if this JavaType represents a C array + private final C_PTR primitivePointerType; private static JavaType nioBufferType; private static JavaType nioByteBufferType; @@ -126,7 +126,7 @@ public class JavaType { return new JavaType(elementType); } - public static JavaType createForVoidPointer() { + public static JavaType createForCVoidPointer() { return new JavaType(C_PTR.VOID); } @@ -436,6 +436,7 @@ public class JavaType { return elementType != null; } + public boolean isCPrimitivePointerType() { return primitivePointerType != null; } @@ -474,13 +475,7 @@ public class JavaType { @Override public Object clone() { - JavaType clone = new JavaType(primitivePointerType); - - clone.clazz = this.clazz; - clone.name = this.name; - clone.elementType = this.elementType; - - return clone; + return new JavaType(primitivePointerType, clazz, name, elementType); } @Override @@ -505,16 +500,25 @@ public class JavaType { * argument. */ private JavaType(Class<?> clazz) { + this.primitivePointerType = null; this.clazz = clazz; + this.name = null; + this.elementType = null; } /** Constructs a type representing a named C struct. */ private JavaType(String name) { + this.primitivePointerType = null; + this.clazz = null; this.name = name; + this.elementType = null; } /** Constructs a type representing an array of C pointers. */ private JavaType(Type elementType) { + this.primitivePointerType = null; + this.clazz = null; + this.name = null; this.elementType = elementType; } @@ -522,8 +526,18 @@ public class JavaType { (integer, floating-point, or void pointer) type. */ private JavaType(C_PTR primitivePointerType) { this.primitivePointerType = primitivePointerType; + this.clazz = null; + this.name = null; + this.elementType = null; } + private JavaType(C_PTR primitivePointerType, Class<?> clazz, String name, Type elementType) { + this.primitivePointerType = primitivePointerType; + this.clazz = clazz; + this.name = name; + this.elementType = elementType; + } + private String arrayName(Class<?> clazz) { StringBuilder buf = new StringBuilder(); int arrayCount = 0; |