aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2008-05-26 18:35:33 +0000
committerKenneth Russel <[email protected]>2008-05-26 18:35:33 +0000
commit040e730115f8a50b598edb448fc29f8917bde392 (patch)
tree9b2a78e5dc09d1c693a523355ad74242750e9eef /src
parentc84a0811ac16ef8c25f257c1bcee4d386e7afcb9 (diff)
Added support for passing outgoing arrays of compound types, including
non-const arrays of compound types and the associated copies back to Java, in support of constructs like eglChooseConfig. Generated code has been compiled but not yet tested. Refactorings to allow generated glue code using StructAccessors to work on Java ME / CDC / FP + JSR-239 NIO, as well as Java SE. Bug fix to ForceProcAddressGen. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/trunk@77 a78bb65f-1512-4460-ba86-f6dc96a7bf27
Diffstat (limited to 'src')
-rw-r--r--src/java/com/sun/gluegen/CMethodBindingEmitter.java96
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java4
-rw-r--r--src/java/com/sun/gluegen/JavaMethodBindingEmitter.java80
-rw-r--r--src/java/com/sun/gluegen/JavaType.java14
-rw-r--r--src/java/com/sun/gluegen/MethodBinding.java19
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java3
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java16
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp7
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/BufferFactory.java.javase7
9 files changed, 193 insertions, 53 deletions
diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
index 243e90f..93a625f 100644
--- a/src/java/com/sun/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
@@ -415,7 +415,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
continue;
}
- if (type.isArray() || type.isNIOBuffer() || type.isCompoundTypeWrapper()) {
+ if (type.isArray() || type.isNIOBuffer() || type.isCompoundTypeWrapper() || type.isArrayOfCompoundTypeWrappers()) {
String convName = pointerConversionArgumentName(i);
// handle array/buffer argument types
boolean needsDataCopy =
@@ -558,7 +558,8 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
if (javaArgType.isArray() ||
- (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation)) {
+ (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation) ||
+ javaArgType.isArrayOfCompoundTypeWrappers()) {
boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType);
// We only defer the emission of GetPrimitiveArrayCritical
@@ -602,7 +603,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
//
// FIXME: should factor out this whole block of code into a separate
// method for clarity and maintenance purposes
- if (!isConstPtrPtr(cArgType)) {
+ //
+ // Note that we properly handle only the case of an array of
+ // compound type wrappers in emitBodyVariablePostCallCleanup below
+ if (!isConstPtrPtr(cArgType) &&
+ !javaArgType.isArrayOfCompoundTypeWrappers()) {
// FIXME: if the arg type is non-const, the sematics might be that
// the function modifies the argument -- we don't yet support
// this.
@@ -680,6 +685,16 @@ public class CMethodBindingEmitter extends FunctionEmitter
convName + "_copy[_copyIndex]",
"_offsetHandle[_copyIndex]",
true);
+ } else if (javaArgType.isArrayOfCompoundTypeWrappers()) {
+ // These come down in similar fashion to an array of NIO
+ // Buffers only we do not pass down any integer byte
+ // offset argument
+ emitGetDirectBufferAddress(writer,
+ "_tmpObj",
+ cArgElementType.getName(),
+ convName + "_copy[_copyIndex]",
+ null,
+ true);
} else {
// Question: do we always need to copy the sub-arrays, or just
// GetPrimitiveArrayCritical on each jobjectarray element and
@@ -734,10 +749,6 @@ public class CMethodBindingEmitter extends FunctionEmitter
if (EMIT_NULL_CHECKS) {
writer.println(" }");
}
- } else if (javaArgType.isArrayOfCompoundTypeWrappers()) {
-
- // FIXME
- throw new RuntimeException("Outgoing arrays of StructAccessors not yet implemented");
}
}
}
@@ -758,7 +769,8 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
if (javaArgType.isArray() ||
- (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation)) {
+ (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation) ||
+ javaArgType.isArrayOfCompoundTypeWrappers()) {
boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType);
if ((!needsDataCopy && !emittingPrimitiveArrayCritical) ||
@@ -796,16 +808,40 @@ public class CMethodBindingEmitter extends FunctionEmitter
// assuming they were treated differently in
// emitBodyVariablePreCallSetup() (see the similar section in that
// method for details).
- throw new RuntimeException(
- "Cannot clean up copied data for ptr-to-ptr arg type \"" + cArgType +
- "\": support for cleaning up non-const ptr-to-ptr types not implemented.");
+ if (javaArgType.isArrayOfCompoundTypeWrappers()) {
+ // This is the only form of cleanup we handle right now
+ String argName = binding.getArgumentName(i);
+ writer.println(" _tmpArrayLen = (*env)->GetArrayLength(env, " + argName + ");");
+ writer.println(" for (_copyIndex = 0; _copyIndex < _tmpArrayLen; ++_copyIndex) {");
+ writer.println(" _tmpObj = (*env)->GetObjectArrayElement(env, " + argName + ", _copyIndex);");
+ // We only skip the copy back in limited situations
+ String copyName = pointerConversionArgumentName(i) + "_copy";
+ writer.println(" if ((" + copyName + "[_copyIndex] == NULL && _tmpObj == NULL) ||");
+ writer.println(" (" + copyName + "[_copyIndex] != NULL && _tmpObj != NULL &&");
+ writer.println(" (*env)->GetDirectBufferAddress(env, _tmpObj) == " + copyName + "[_copyIndex])) {");
+ writer.println(" /* No copy back needed */");
+ writer.println(" } else {");
+ writer.println(" if (" + copyName + "[_copyIndex] == NULL) {");
+ writer.println(" (*env)->SetObjectArrayElement(env, " + argName + ", _copyIndex, NULL);");
+ writer.println(" } else {");
+ writer.println(" _tmpObj = (*env)->NewDirectByteBuffer(env, " + copyName + "[_copyIndex], sizeof(" + cArgType.getName() + "));");
+ writer.println(" (*env)->SetObjectArrayElement(env, " + argName + ", _copyIndex, _tmpObj);");
+ writer.println(" }");
+ writer.println(" }");
+ writer.println(" }");
+ } else {
+ throw new RuntimeException(
+ "Cannot clean up copied data for ptr-to-ptr arg type \"" + cArgType +
+ "\": support for cleaning up most non-const ptr-to-ptr types not implemented.");
+ }
}
writer.println(" /* Clean up " + convName + "_copy */");
// Only need to perform cleanup for individual array
// elements if they are not direct buffers
- if (!javaArgType.isNIOBufferArray()) {
+ if (!javaArgType.isNIOBufferArray() &&
+ !javaArgType.isArrayOfCompoundTypeWrappers()) {
// Re-fetch length of array that was copied
String arrayLenName = "_tmpArrayLen";
writer.print(" ");
@@ -875,11 +911,6 @@ public class CMethodBindingEmitter extends FunctionEmitter
if (EMIT_NULL_CHECKS) {
writer.println(" }");
}
- } else if (javaArgType.isArrayOfCompoundTypeWrappers()) {
-
- // FIXME
- throw new RuntimeException("Outgoing arrays of StructAccessors not yet implemented");
-
}
}
}
@@ -912,7 +943,8 @@ public class CMethodBindingEmitter extends FunctionEmitter
if (binding.getCArgumentType(i).isPointer() && binding.getJavaArgumentType(i).isPrimitive()) {
writer.print("(intptr_t) ");
}
- if (javaArgType.isArray() || javaArgType.isNIOBuffer() || javaArgType.isCompoundTypeWrapper()) {
+ if (javaArgType.isArray() || javaArgType.isNIOBuffer() ||
+ javaArgType.isCompoundTypeWrapper() || javaArgType.isArrayOfCompoundTypeWrappers()) {
writer.print(pointerConversionArgumentName(i));
if (javaArgTypeNeedsDataCopy(javaArgType)) {
writer.print("_copy");
@@ -1115,6 +1147,10 @@ public class CMethodBindingEmitter extends FunctionEmitter
} else if (type.isCompoundTypeWrapper()) {
// Mangle wrappers for C structs as ByteBuffer
jniMangle(java.nio.ByteBuffer.class, buf, true);
+ } else if (type.isArrayOfCompoundTypeWrappers()) {
+ java.nio.Buffer[] tmp = new java.nio.Buffer[0];
+ // Mangle arrays of C structs as Buffer[]
+ jniMangle(tmp.getClass(), buf, true);
} else if (type.isJNIEnv()) {
// These are not exposed at the Java level
} else {
@@ -1258,13 +1294,13 @@ public class CMethodBindingEmitter extends FunctionEmitter
String byteOffsetVarName,
boolean emitElseClause) {
if (EMIT_NULL_CHECKS) {
- writer.print(" if (");
+ writer.print(" if (");
writer.print(sourceVarName);
writer.println(" != NULL) {");
- writer.print(" ");
+ writer.print(" ");
}
- writer.print(" ");
+ writer.print(" ");
writer.print(receivingVarName);
writer.print(" = (");
writer.print(receivingVarTypeString);
@@ -1274,13 +1310,13 @@ public class CMethodBindingEmitter extends FunctionEmitter
writer.println(")) + " + ((byteOffsetVarName != null) ? byteOffsetVarName : "0") + ");");
if (EMIT_NULL_CHECKS) {
- writer.print(" }");
+ writer.print(" }");
if (emitElseClause) {
writer.println(" else {");
- writer.print(" ");
+ writer.print(" ");
writer.print(receivingVarName);
writer.println(" = NULL;");
- writer.println(" }");
+ writer.println(" }");
} else {
writer.println();
}
@@ -1305,10 +1341,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
//
if (javaType.isNIOBuffer()) {
ptrTypeString = cType.getName();
- } else if (javaType.isArray()) {
+ } else if (javaType.isArray() || javaType.isArrayOfCompoundTypeWrappers()) {
needsDataCopy = javaArgTypeNeedsDataCopy(javaType);
if (javaType.isPrimitiveArray() ||
- javaType.isNIOBufferArray()) {
+ javaType.isNIOBufferArray() ||
+ javaType.isArrayOfCompoundTypeWrappers()) {
ptrTypeString = cType.getName();
} else if (!javaType.isStringArray()) {
Class elementType = javaType.getJavaClass().getComponentType();
@@ -1328,9 +1365,6 @@ public class CMethodBindingEmitter extends FunctionEmitter
throw new RuntimeException("Unsupported pointer type: \"" + cType.getName() + "\"");
}
}
- } else if (javaType.isArrayOfCompoundTypeWrappers()) {
- // FIXME
- throw new RuntimeException("Outgoing arrays of StructAccessors not yet implemented");
} else {
ptrTypeString = cType.getName();
}
@@ -1346,7 +1380,6 @@ public class CMethodBindingEmitter extends FunctionEmitter
// Declare a variable to hold a copy of the argument data in which the
// incoming data has been properly laid out in memory to match the C
// memory model
- Class elementType = javaType.getJavaClass().getComponentType();
if (javaType.isStringArray()) {
writer.print(" const char **");
} else {
@@ -1441,6 +1474,9 @@ public class CMethodBindingEmitter extends FunctionEmitter
javaArgType.isStringArray() ||
javaArgType.getJavaClass().getComponentType().isArray());
}
+ if (javaArgType.isArrayOfCompoundTypeWrappers()) {
+ return true;
+ }
return false;
}
}
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index 48964b0..6b51ef0 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -1147,7 +1147,7 @@ public class JavaEmitter implements GlueEmitter {
} else if (targetType.isPointer() && (targetType.pointerDepth() == 1) &&
targetType.asPointer().getTargetType().isCompound()) {
// Array of pointers; convert as array of StructAccessors
- return JavaType.createForCArray(targetType);
+ return JavaType.createForCArray(bottomType);
} else {
throw new RuntimeException(
"Could not convert C type \"" + t + "\" " +
@@ -1456,6 +1456,7 @@ public class JavaEmitter implements GlueEmitter {
protected void emitCHeader(PrintWriter cWriter, String className) {
cWriter.println("#include <jni.h>");
+ cWriter.println("#include <stdlib.h>");
cWriter.println();
if (getConfig().emitImpl()) {
@@ -1557,7 +1558,6 @@ public class JavaEmitter implements GlueEmitter {
return binding;
}
-
private MethodBinding lowerMethodBindingPointerTypes(MethodBinding inputBinding,
boolean convertToArrays,
boolean[] canProduceArrayVariant) {
diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
index 8629371..528a0cb 100644
--- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
@@ -88,6 +88,10 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
// number of elements of the returned array.
private String returnedArrayLengthExpression;
+ // A suffix used to create a temporary outgoing array of Buffers to
+ // represent an array of compound type wrappers
+ private static final String COMPOUND_ARRAY_SUFFIX = "_buf_array_copy";
+
public JavaMethodBindingEmitter(MethodBinding binding,
PrintWriter output,
String runtimeExceptionType,
@@ -231,9 +235,20 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
// Compound type wrappers are unwrapped to ByteBuffer
return "java.nio.ByteBuffer";
} else if (type.isArrayOfCompoundTypeWrappers()) {
- return "java.nio.ByteBuffer";
+ if (skipBuffers) {
+ return "java.nio.ByteBuffer";
+ } else {
+ // In the case where this is called with a false skipBuffers
+ // argument we want to erase the array of compound type
+ // wrappers to ByteBuffer[]
+ return "java.nio.ByteBuffer[]";
+ }
}
}
+ if (type.isArrayOfCompoundTypeWrappers()) {
+ // We don't want to bake the array specification into the type name
+ return type.getName() + "[]";
+ }
return type.getName();
}
@@ -385,6 +400,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) {
emitArrayLengthAndNIOBufferChecks(binding, writer);
+ emitCompoundArrayCopies(binding, writer);
}
protected void emitArrayLengthAndNIOBufferChecks(MethodBinding binding, PrintWriter writer) {
@@ -448,6 +464,26 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
}
+ protected void emitCompoundArrayCopies(MethodBinding binding, PrintWriter writer) {
+ // If the method binding uses outgoing arrays of compound type
+ // wrappers, we need to generate a temporary copy of this array
+ // into a ByteBuffer[] for processing by the native code
+ if (binding.signatureUsesArraysOfCompoundTypeWrappers()) {
+ for (int i = 0; i < binding.getNumArguments(); i++) {
+ JavaType javaType = binding.getJavaArgumentType(i);
+ if (javaType.isArrayOfCompoundTypeWrappers()) {
+ String argName = getArgumentName(i);
+ String tempArrayName = argName + COMPOUND_ARRAY_SUFFIX;
+ writer.println(" ByteBuffer[] " + tempArrayName + " = new ByteBuffer[" + argName + ".length];");
+ writer.println(" for (int _ctr = 0; _ctr < + " + argName + ".length; _ctr++) {");
+ writer.println(" " + javaType.getName() + " _tmp = " + argName + "[_ctr];");
+ writer.println(" " + tempArrayName + "[_ctr] = ((_tmp == null) ? null : _tmp.getBuffer());");
+ writer.println(" }");
+ }
+ }
+ }
+ }
+
protected void emitCall(MethodBinding binding, PrintWriter writer, boolean direct) {
writer.print(getImplMethodName(direct));
writer.print("(");
@@ -469,7 +505,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
} else if (returnType.isArrayOfCompoundTypeWrappers()) {
writer.println("java.nio.ByteBuffer[] _res;");
needsResultAssignment = true;
- } else if ((epilogue != null) && (epilogue.size() > 0)) {
+ } else if (((epilogue != null) && (epilogue.size() > 0)) ||
+ binding.signatureUsesArraysOfCompoundTypeWrappers()) {
emitReturnType(writer);
writer.println(" _res;");
needsResultAssignment = true;
@@ -529,6 +566,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
} else {
writer.println();
}
+ emitPostCallCleanup(binding, writer);
emitPrologueOrEpilogue(epilogue, writer);
if (needsResultAssignment) {
emitCallResultReturn(binding, writer);
@@ -569,9 +607,11 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
if (type.isNIOBuffer() && !direct) {
- writer.print("BufferFactory.getArray(" + getArgumentName(i) + ")");
+ writer.print("BufferFactory.getArray(" + getArgumentName(i) + ")");
+ } else if (type.isArrayOfCompoundTypeWrappers()) {
+ writer.print(getArgumentName(i) + COMPOUND_ARRAY_SUFFIX);
} else {
- writer.print(getArgumentName(i));
+ writer.print(getArgumentName(i));
}
if (type.isCompoundTypeWrapper()) {
@@ -617,6 +657,32 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return numArgsEmitted;
}
+ protected void emitPostCallCleanup(MethodBinding binding, PrintWriter writer) {
+ if (binding.signatureUsesArraysOfCompoundTypeWrappers()) {
+ // For each such array, we need to take the ByteBuffer[] that
+ // came back from the C method invocation and wrap the
+ // ByteBuffers back into the wrapper types
+ for (int i = 0; i < binding.getNumArguments(); i++) {
+ JavaType javaArgType = binding.getJavaArgumentType(i);
+ if (javaArgType.isArrayOfCompoundTypeWrappers()) {
+ String argName = binding.getArgumentName(i);
+ writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {");
+ writer.println(" if ((" + argName + "[_ctr] == null && " + argName + COMPOUND_ARRAY_SUFFIX + "[_ctr] == null) ||");
+ writer.println(" (" + argName + "[_ctr] != null && " + argName + "[_ctr].getBuffer() == " + argName + COMPOUND_ARRAY_SUFFIX + "[_ctr])) {");
+ writer.println(" // No copy back needed");
+ writer.println(" } else {");
+ writer.println(" if (" + argName + COMPOUND_ARRAY_SUFFIX + "[_ctr] == null) {");
+ writer.println(" " + argName + "[_ctr] = null;");
+ writer.println(" } else {");
+ writer.println(" " + argName + "[_ctr] = " + javaArgType.getName() + ".create(" + argName + COMPOUND_ARRAY_SUFFIX + "[_ctr]);");
+ writer.println(" }");
+ writer.println(" }");
+ writer.println(" }");
+ }
+ }
+ }
+ }
+
protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) {
JavaType returnType = binding.getJavaReturnType();
@@ -624,9 +690,9 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
String fmt = getReturnedArrayLengthExpression();
writer.println(" if (_res == null) return null;");
if (fmt == null) {
- writer.print(" return " + returnType.getName() + ".create(_res.order(java.nio.ByteOrder.nativeOrder()))");
+ writer.print(" return " + returnType.getName() + ".create(BufferFactory.nativeOrder(_res))");
} else {
- writer.println(" _res.order(java.nio.ByteOrder.nativeOrder());");
+ writer.println(" BufferFactory.nativeOrder(_res);");
String expr = new MessageFormat(fmt).format(argumentNameArray());
PointerType cReturnTypePointer = binding.getCReturnType().asPointer();
CompoundType cReturnType = null;
@@ -645,7 +711,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
writer.println(" _res.position(_count * " + getReturnTypeString(true) + ".size());");
writer.println(" _res.limit ((1 + _count) * " + getReturnTypeString(true) + ".size());");
writer.println(" java.nio.ByteBuffer _tmp = _res.slice();");
- writer.println(" _tmp.order(java.nio.ByteOrder.nativeOrder());");
+ writer.println(" BufferFactory.nativeOrder(_tmp);");
writer.println(" _res.position(0);");
writer.println(" _res.limit(_res.capacity());");
writer.println(" _retarray[_count] = " + getReturnTypeString(true) + ".create(_tmp);");
diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java
index 496fd69..b520888 100644
--- a/src/java/com/sun/gluegen/JavaType.java
+++ b/src/java/com/sun/gluegen/JavaType.java
@@ -345,31 +345,31 @@ public class JavaType {
}
public boolean isFloatArray() {
- return(clazz.isArray() && clazz.getComponentType() == Float.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Float.TYPE);
}
public boolean isDoubleArray() {
- return(clazz.isArray() && clazz.getComponentType() == Double.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Double.TYPE);
}
public boolean isByteArray() {
- return(clazz.isArray() && clazz.getComponentType() == Byte.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Byte.TYPE);
}
public boolean isIntArray() {
- return(clazz.isArray() && clazz.getComponentType() == Integer.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Integer.TYPE);
}
public boolean isShortArray() {
- return(clazz.isArray() && clazz.getComponentType() == Short.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Short.TYPE);
}
public boolean isLongArray() {
- return(clazz.isArray() && clazz.getComponentType() == Long.TYPE);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == Long.TYPE);
}
public boolean isStringArray() {
- return(clazz.isArray() && clazz.getComponentType() == java.lang.String.class);
+ return (clazz != null && clazz.isArray() && clazz.getComponentType() == java.lang.String.class);
}
diff --git a/src/java/com/sun/gluegen/MethodBinding.java b/src/java/com/sun/gluegen/MethodBinding.java
index f8a4d2c..04b73e2 100644
--- a/src/java/com/sun/gluegen/MethodBinding.java
+++ b/src/java/com/sun/gluegen/MethodBinding.java
@@ -58,6 +58,7 @@ public class MethodBinding {
private boolean signatureUsesNIO;
private boolean signatureCanUseIndirectNIO;
private boolean signatureUsesCompoundTypeWrappers;
+ private boolean signatureUsesArraysOfCompoundTypeWrappers;
private boolean signatureUsesCVoidPointers;
private boolean signatureUsesCPrimitivePointers;
private boolean signatureUsesCArrays;
@@ -84,6 +85,7 @@ public class MethodBinding {
this.signatureUsesNIO = bindingToCopy.signatureUsesNIO;
this.signatureCanUseIndirectNIO = bindingToCopy.signatureCanUseIndirectNIO;
this.signatureUsesCompoundTypeWrappers = bindingToCopy.signatureUsesCompoundTypeWrappers;
+ this.signatureUsesArraysOfCompoundTypeWrappers = bindingToCopy.signatureUsesArraysOfCompoundTypeWrappers;
this.signatureUsesCVoidPointers = bindingToCopy.signatureUsesCVoidPointers;
this.signatureUsesCPrimitivePointers = bindingToCopy.signatureUsesCPrimitivePointers;
this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays;
@@ -233,6 +235,16 @@ public class MethodBinding {
}
/**
+ * Returns true if the return type or any of the outgoing arguments
+ * in the method's signature use arrays of "compound type wrappers",
+ * or NIO-based wrappers for C data structures.
+ */
+ public boolean signatureUsesArraysOfCompoundTypeWrappers() {
+ computeSignatureProperties();
+ return signatureUsesArraysOfCompoundTypeWrappers;
+ }
+
+ /**
* Returns true if the function needs NIO-related
* wrapping/unwrapping or conversion of various arguments. Currently
* this returns the logical OR of signatureUsesNIO() and
@@ -290,6 +302,7 @@ public class MethodBinding {
signatureUsesNIO = false;
signatureCanUseIndirectNIO = false;
signatureUsesCompoundTypeWrappers = false;
+ signatureUsesArraysOfCompoundTypeWrappers = false;
signatureUsesCVoidPointers = false;
signatureUsesCPrimitivePointers = false;
signatureUsesCArrays = false;
@@ -333,6 +346,12 @@ public class MethodBinding {
signatureUsesCompoundTypeWrappers = true;
}
+ if (javaArgType.isArrayOfCompoundTypeWrappers()) {
+ // Needs to be duplicated and this array lowered to an array
+ // of Buffers for code emission
+ signatureUsesArraysOfCompoundTypeWrappers = true;
+ }
+
if (javaArgType.isNIOBuffer() ||
javaArgType.isNIOBufferArray()) {
// Needs checking of direct buffer property
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
index 8dc46ee..84e8132 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
@@ -153,6 +153,9 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
// set the function pointer to the value of the passed-in glProcAddress
FunctionSymbol cSym = getBinding().getCSymbol();
String funcPointerTypedefName = emitter.getFunctionPointerTypedefName(cSym);
+ if (needsLocalTypedef) {
+ funcPointerTypedefName = "_local_" + funcPointerTypedefName;
+ }
String ptrVarName = "ptr_" + cSym.getName();
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
index fe77248..45e0bf4 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
@@ -268,13 +268,15 @@ public class ProcAddressEmitter extends JavaEmitter
if (shouldWrap)
{
// Hoist argument names from function pointer if not supplied in prototype
- FunctionType typedef = typedefDictionary.get(funcPointerTypedefName).asPointer().getTargetType().asFunction();
- FunctionType fun = sym.getType();
- int numarg = typedef.getNumArguments();
- for ( int i =0; i < numarg; i++ )
- {
- if ( fun.getArgumentName(i) == null )
- fun.setArgumentName(i,typedef.getArgumentName(i));
+ Type funcPointerType = typedefDictionary.get(funcPointerTypedefName);
+ if (funcPointerType != null) {
+ FunctionType typedef = funcPointerType.asPointer().getTargetType().asFunction();
+ FunctionType fun = sym.getType();
+ int numarg = typedef.getNumArguments();
+ for (int i =0; i < numarg; i++) {
+ if (fun.getArgumentName(i) == null)
+ fun.setArgumentName(i,typedef.getArgumentName(i));
+ }
}
}
diff --git a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp
index 16c1494..622cc37 100755
--- a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp
+++ b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp
@@ -52,6 +52,13 @@ public class BufferFactory {
return buf;
}
+ /** Helper routine to set a ByteBuffer to the native byte order, if
+ that operation is supported by the underlying NIO
+ implementation. */
+ public static ByteBuffer nativeOrder(ByteBuffer buf) {
+ return buf;
+ }
+
/** Helper routine to tell whether a buffer is direct or not. Null
pointers are considered direct. isDirect() should really be
public in Buffer and not replicated in all subclasses. */
diff --git a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
index e7b7e52..a883316 100755
--- a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
+++ b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
@@ -56,6 +56,13 @@ public class BufferFactory {
return buf;
}
+ /** Helper routine to set a ByteBuffer to the native byte order, if
+ that operation is supported by the underlying NIO
+ implementation. */
+ public static ByteBuffer nativeOrder(ByteBuffer buf) {
+ return buf.order(ByteOrder.nativeOrder());
+ }
+
/** Helper routine to tell whether a buffer is direct or not. Null
pointers are considered direct. isDirect() should really be
public in Buffer and not replicated in all subclasses. */