summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Bien <mbien@fh-landshut.de>2010-01-12 17:57:27 +0100
committerMichael Bien <mbien@fh-landshut.de>2010-01-12 17:57:27 +0100
commitb138169c1f85a7914304ae793efb9cabfbfd5da2 (patch)
tree065d968fe603a9a55c33208cdac8183bde8336a8 /src
parent266ab5707d5f6b9e1cf935e6258badd6ba9f2639 (diff)
fixed emitted code for buffer-array mixing.
removed workaround in BufferFactory since it is no longer needed. small code cleanup (generator java 5 migration).
Diffstat (limited to 'src')
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java20
-rw-r--r--src/java/com/sun/gluegen/JavaMethodBindingEmitter.java20
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/BufferFactory.java.javame_cdc_fp2
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/BufferFactory.java.javase2
4 files changed, 27 insertions, 17 deletions
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index 0d118cf..79f2b4d 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -388,8 +388,7 @@ public class JavaEmitter implements GlueEmitter {
// validateFunctionsToBind(funcsToBindSet);
- ArrayList<FunctionSymbol> funcsToBind = new ArrayList<FunctionSymbol>(funcsToBindSet.size());
- funcsToBind.addAll(funcsToBindSet);
+ ArrayList<FunctionSymbol> funcsToBind = new ArrayList<FunctionSymbol>(funcsToBindSet);
// sort functions to make them easier to find in native code
Collections.sort(
funcsToBind,
@@ -408,16 +407,14 @@ public class JavaEmitter implements GlueEmitter {
ArrayList<FunctionEmitter> methodBindingEmitters = new ArrayList<FunctionEmitter>(2*funcsToBind.size());
for (FunctionSymbol cFunc : funcsToBind) {
// Check to see whether this function should be ignored
- if (cfg.shouldIgnoreInImpl(cFunc.getName())) {
- continue; // don't generate bindings for this symbol
+ if (!cfg.shouldIgnoreInImpl(cFunc.getName())) {
+ methodBindingEmitters.addAll(generateMethodBindingEmitters(methodBindingSet, cFunc));
}
- methodBindingEmitters.addAll(generateMethodBindingEmitters(methodBindingSet, cFunc));
}
// Emit all the methods
- for (int i = 0; i < methodBindingEmitters.size(); ++i) {
- FunctionEmitter emitter = methodBindingEmitters.get(i);
+ for (FunctionEmitter emitter : methodBindingEmitters) {
try {
if (!emitter.isInterface() || !cfg.shouldIgnoreInInterface(emitter.getName())) {
emitter.emit();
@@ -1845,6 +1842,7 @@ public class JavaEmitter implements GlueEmitter {
// multiple variants taking Java primitive arrays and NIO buffers, subject
// to the per-function "NIO only" rule in the configuration file
protected List<MethodBinding> expandMethodBinding(MethodBinding binding) {
+
List<MethodBinding> result = new ArrayList<MethodBinding>();
// Indicates whether it is possible to produce an array variant
// Prevents e.g. char* -> String conversions from emitting two entry points
@@ -1853,14 +1851,12 @@ public class JavaEmitter implements GlueEmitter {
if (binding.signatureUsesCPrimitivePointers() ||
binding.signatureUsesCVoidPointers() ||
binding.signatureUsesCArrays()) {
+
result.add(lowerMethodBindingPointerTypes(binding, false, canProduceArrayVariant));
// FIXME: should add new configuration flag for this
- if (canProduceArrayVariant[0] &&
- (binding.signatureUsesCPrimitivePointers() ||
- binding.signatureUsesCArrays()) &&
- !cfg.nioDirectOnly(binding.getName()) &&
- !cfg.nioOnly(binding.getName())) {
+ if (canProduceArrayVariant[0] && (binding.signatureUsesCPrimitivePointers() || binding.signatureUsesCArrays()) &&
+ !cfg.nioDirectOnly(binding.getName()) && !cfg.nioOnly(binding.getName())) {
result.add(lowerMethodBindingPointerTypes(binding, true, null));
}
} else {
diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
index bf9d3ae..a813348 100644
--- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
@@ -392,8 +392,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
writer.println(';');
} else {
MethodBinding mBinding = getBinding();
- writer.println();
writer.println(" {");
+ writer.println();
if (isUnimplemented) {
writer.println(" throw new " + getUnsupportedExceptionType() + "(\"Unimplemented\");");
} else {
@@ -449,7 +449,21 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
} else {
if(firstBuffer) {
firstBuffer = false;
- writer.println(" boolean _direct = BufferFactory.isDirect(" + getArgumentName(i) + ");");
+ writer.print(" boolean _direct = ");
+ for (int j = i; j < binding.getNumArguments(); j++) {
+ JavaType buff = binding.getJavaArgumentType(j);
+
+ if(buff.isNIOBuffer()) {
+ if(i!=j) { // not the first one
+ writer.println();
+ writer.print(" ||");
+ }
+ writer.print(getArgumentName(j)+" != null && BufferFactory.isDirect(" + getArgumentName(j) + ")");
+ }
+
+ }
+ writer.println(";");
+
} else {
writer.println(" if (" + getArgumentName(i) + " != null && _direct != BufferFactory.isDirect(" + getArgumentName(i) + "))");
writer.println(" throw new " + getRuntimeExceptionType() +
@@ -634,7 +648,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
} else if (type.isArrayOfCompoundTypeWrappers()) {
writer.print(getArgumentName(i) + COMPOUND_ARRAY_SUFFIX);
} else if(type.isNIOPointerBuffer()) {
- writer.print(getArgumentName(i) + ".getBuffer()");
+ writer.print(getArgumentName(i)+"!=null?"+getArgumentName(i) + ".getBuffer():null");
} else {
writer.print(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 dacdd03..822d62d 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
@@ -82,7 +82,7 @@ public class BufferFactory {
public in Buffer and not replicated in all subclasses. */
public static boolean isDirect(Object buf) {
if (buf == null) {
- return false;
+ return true;
}
if (buf instanceof ByteBuffer) {
return ((ByteBuffer) buf).isDirect();
diff --git a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
index 1e660c1..cb8c770 100755
--- a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
+++ b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
@@ -81,7 +81,7 @@ public class BufferFactory {
public in Buffer and not replicated in all subclasses. */
public static boolean isDirect(Object buf) {
if (buf == null) {
- return false;
+ return true;
}
if (buf instanceof ByteBuffer) {
return ((ByteBuffer) buf).isDirect();