From e388426759e02e15ccc93b9df2e5c0400590d057 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 02:05:22 +0200 Subject: 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 --- .../com/jogamp/gluegen/CMethodBindingEmitter.java | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/java/com/jogamp/gluegen/CMethodBindingEmitter.java') 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); -- cgit v1.2.3