aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-13 23:04:01 +0200
committerSven Gothel <[email protected]>2013-04-13 23:04:01 +0200
commit86f5e7eac7544d2511b70c2142634c89c69d0594 (patch)
treed08a924d21039be71b1ca45d5dfea3a6df024687
parent47333929fd4e563d61996654d2a435b52b904ef0 (diff)
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).
-rw-r--r--src/java/com/jogamp/gluegen/CMethodBindingEmitter.java20
1 files changed, 15 insertions, 5 deletions
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));