From 86f5e7eac7544d2511b70c2142634c89c69d0594 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 13 Apr 2013 23:04:01 +0200 Subject: Fix Bug 715: Don't modify 'carray' pointer returned from GetPrimitiveArrayCritical(..) The 'carray' pointer returned from GetPrimitiveArrayCritical(..) was moved about the array offset and used in ReleasePrimitiveArrayCritical(..) to release the pinpointed memory. Even though this 'is' a bug by violating the _sparse_ specification, Hotspot impl. doesn't use the value at all (NOP) and hence this code didn't produce an error since .. (Same w/ Dalvik). Now the array offset is added while passing the carray pointer to the native function call and hence is no more modified and the orig. value is passed to ReleasePrimitiveArrayCritical(..). Tested w/ GlueGen unit tests and all JOGL unit tests (on Linux x64 w/ 'a' hotspot VM). --- .../com/jogamp/gluegen/CMethodBindingEmitter.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index eecd29d..022cf53 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -600,10 +600,9 @@ public class CMethodBindingEmitter extends FunctionEmitter { cArgTypeName = "jstring *"; } writer.print(cArgTypeName); - writer.print(") (((char*) ( JNI_TRUE == " + isNIOArgName(i) + " ? "); + writer.print(") ( JNI_TRUE == " + isNIOArgName(i) + " ? "); writer.print(" (*env)->GetDirectBufferAddress(env, " + javaArgName + ") : "); - writer.print(" (*env)->GetPrimitiveArrayCritical(env, " + javaArgName + ", NULL) ) ) + "); - writer.println(byteOffsetArgName(i) + ");"); + writer.print(" (*env)->GetPrimitiveArrayCritical(env, " + javaArgName + ", NULL) );"); } else { // Handle the case where the array elements are of a type that needs a // data copy operation to convert from the java memory model to the C @@ -912,7 +911,12 @@ public class CMethodBindingEmitter extends FunctionEmitter { writer.print(CMethodBindingEmitter.cThisArgumentName()); } else { writer.print("("); - Type cArgType = binding.getCSymbol().getArgumentType(i); + Type cArgType = binding.getCArgumentType(i); + boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); + boolean needsArrayOffset = !needsDataCopy && ( + javaArgType.isArray() || + javaArgType.isArrayOfCompoundTypeWrappers() || + ( javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation ) ); if (isConstPtrPtr(cArgType)) { writer.print("const "); } @@ -923,10 +927,16 @@ public class CMethodBindingEmitter extends FunctionEmitter { } if (javaArgType.isArray() || javaArgType.isNIOBuffer() || javaArgType.isCompoundTypeWrapper() || javaArgType.isArrayOfCompoundTypeWrappers()) { + if( needsArrayOffset ) { + writer.print("(((char *) "); + } writer.print(pointerConversionArgumentName(binding.getArgumentName(i))); - if (javaArgTypeNeedsDataCopy(javaArgType)) { + if ( needsDataCopy ) { writer.print("_copy"); } + if( needsArrayOffset ) { + writer.print(") + " + byteOffsetArgName(i) + ")"); + } } else { if (javaArgType.isString()) { writer.print(STRING_CHARS_PREFIX); } writer.print(binding.getArgumentName(i)); -- cgit v1.2.3