From b138169c1f85a7914304ae793efb9cabfbfd5da2 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 12 Jan 2010 17:57:27 +0100 Subject: fixed emitted code for buffer-array mixing. removed workaround in BufferFactory since it is no longer needed. small code cleanup (generator java 5 migration). --- src/java/com/sun/gluegen/JavaEmitter.java | 20 ++++++++------------ .../com/sun/gluegen/JavaMethodBindingEmitter.java | 20 +++++++++++++++++--- .../gluegen/runtime/BufferFactory.java.javame_cdc_fp | 2 +- .../sun/gluegen/runtime/BufferFactory.java.javase | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) (limited to 'src') 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 funcsToBind = new ArrayList(funcsToBindSet.size()); - funcsToBind.addAll(funcsToBindSet); + ArrayList funcsToBind = new ArrayList(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 methodBindingEmitters = new ArrayList(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 expandMethodBinding(MethodBinding binding) { + List result = new ArrayList(); // 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(); -- cgit v1.2.3