java-gobject-introspection r39 - trunk/src/org/gnome/gir/compiler
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r39 - trunk/src/org/gnome/gir/compiler
- Date: Sun, 7 Sep 2008 03:27:13 +0000 (UTC)
Author: walters
Date: Sun Sep 7 03:27:13 2008
New Revision: 39
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=39&view=rev
Log:
Handle functions using GError but returning void by checking error != NULL
Also add subclass constructors for struct/union.
Modified:
trunk/src/org/gnome/gir/compiler/CodeFactory.java
trunk/src/org/gnome/gir/compiler/Test.java
Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java (original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java Sun Sep 7 03:27:13 2008
@@ -1,7 +1,7 @@
package org.gnome.gir.compiler;
-import static org.objectweb.asm.Opcodes.AASTORE;
import static org.objectweb.asm.Opcodes.AALOAD;
+import static org.objectweb.asm.Opcodes.AASTORE;
import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
import static org.objectweb.asm.Opcodes.ACC_ENUM;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
@@ -24,7 +24,6 @@
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.ICONST_0;
-import static org.objectweb.asm.Opcodes.IFNE;
import static org.objectweb.asm.Opcodes.IFNONNULL;
import static org.objectweb.asm.Opcodes.ILOAD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
@@ -1077,10 +1076,6 @@
ArgInfo[] argInfos = fi.getArgs();
boolean throwsGError = argInfos.length > 0 &&
argInfos[argInfos.length-1].getType().getTag().equals(TypeTag.ERROR);
- if (throwsGError && returnType.equals(Type.VOID_TYPE)) {
- logger.warning("Skipping function which returns Void and uses GError: " + fi.getSymbol());
- return null;
- }
List<Type> args = getCallableArgs(fi, (fi.getFlags() & FunctionInfoFlags.IS_METHOD) > 0,
throwsGError);
if (args == null) {
@@ -1184,16 +1179,16 @@
}
} else {
jtarget = new Label();
- mv.visitTypeInsn(CHECKCAST, ctx.returnType.getInternalName());
- mv.visitInsn(DUP);
- mv.visitVarInsn(ASTORE, resultOffset);
- mv.visitInsn(DUP);
- if (ctx.returnType.equals(Type.getType(Boolean.class))) {
- mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z");
- mv.visitJumpInsn(IFNE, jtarget);
- } else {
- mv.visitJumpInsn(IFNONNULL, jtarget);
+ if (ctx.returnType.equals(Type.VOID_TYPE)) {
+ mv.visitInsn(POP);
+ } else {
+ mv.visitTypeInsn(CHECKCAST, ctx.returnType.getInternalName());
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ASTORE, resultOffset);
}
+ mv.visitVarInsn(ALOAD, errorOffset);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/ptr/PointerByReference", "getPointer", "()Lcom/sun/jna/Pointer;");
+ mv.visitJumpInsn(IFNONNULL, jtarget);
mv.visitTypeInsn(NEW, "org/gnome/gir/gobject/GErrorException");
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, "org/gnome/gir/gobject/GErrorStruct");
@@ -1204,8 +1199,12 @@
mv.visitMethodInsn(INVOKESPECIAL, "org/gnome/gir/gobject/GErrorException", "<init>", "(Lorg/gnome/gir/gobject/GErrorStruct;)V");
mv.visitInsn(ATHROW);
mv.visitLabel(jtarget);
- mv.visitVarInsn(ALOAD, resultOffset);
- mv.visitInsn(ARETURN);
+ if (ctx.returnType.equals(Type.VOID_TYPE)) {
+ mv.visitInsn(RETURN);
+ } else {
+ mv.visitVarInsn(ALOAD, resultOffset);
+ mv.visitInsn(ARETURN);
+ }
}
Label l4 = new Label();
mv.visitLabel(l4);
@@ -1251,6 +1250,22 @@
return;
writeCallable(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, compilation, fi, ctx);
}
+
+ private void writeStructUnionInnerCtor(InnerClassCompilation inner, String parentInternalName) {
+ MethodVisitor mv = inner.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESTATIC, "org/gnome/gir/gobject/GTypeMapper", "getInstance", "()Lorg/gnome/gir/gobject/GTypeMapper;");
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalName, "<init>", "(Lcom/sun/jna/TypeMapper;)V");
+ mv.visitInsn(RETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L" + inner.internalName + ";", null, l0, l1, 0);
+ mv.visitMaxs(2, 1);
+ mv.visitEnd();
+ }
private void writeStructUnion(RegisteredTypeInfo info, StubClassCompilation compilation, String type,
FunctionInfo[] methods,
@@ -1277,14 +1292,16 @@
compilation.internalName, "ByReference", ACC_PUBLIC + ACC_STATIC);
byRef.writer.visit(V1_6, ACC_PUBLIC + ACC_STATIC,
byRef.internalName, null, compilation.internalName, new String[] { "com/sun/jna/Structure$ByReference"});
+ writeStructUnionInnerCtor(byRef, internalName);
InnerClassCompilation byValue = compilation.newInner("ByValue");
compilation.writer.visitInnerClass(compilation.internalName + "$ByValue",
compilation.internalName, "ByValue", ACC_PUBLIC + ACC_STATIC);
byValue.writer.visit(V1_6, ACC_PUBLIC + ACC_STATIC,
byValue.internalName, null, compilation.internalName, new String[] { "com/sun/jna/Structure$ByValue"});
+ writeStructUnionInnerCtor(byValue, internalName);
- /* constructor */
+ /* constructor; public no-args and protected TypeMapper */
MethodVisitor mv = compilation.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
@@ -1299,6 +1316,21 @@
mv.visitMaxs(2, 1);
mv.visitEnd();
+ mv = compilation.writer.visitMethod(ACC_PROTECTED, "<init>", "(Lcom/sun/jna/TypeMapper;)V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, "com/sun/jna/" + type, "<init>", "(Lcom/sun/jna/TypeMapper;)V");
+ mv.visitInsn(RETURN);
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L" + compilation.internalName + ";", null, l0, l1, 0);
+ mv.visitLocalVariable("mapper", "Lcom/sun/jna/TypeMapper;", null, l0, l1, 0);
+ mv.visitMaxs(2, 2);
+ mv.visitEnd();
+
Set<String> sigs = new HashSet<String>();
for (FunctionInfo fi : methods) {
CallableCompilationContext ctx = tryCompileCallable(fi, sigs);
Modified: trunk/src/org/gnome/gir/compiler/Test.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/Test.java (original)
+++ trunk/src/org/gnome/gir/compiler/Test.java Sun Sep 7 03:27:13 2008
@@ -36,7 +36,7 @@
Function target = Internals.library.getFunction("glib_baz");
Object[] args = new Object[] { x, z };
Pointer result = (Pointer) target.invoke(Pointer.class, args, Internals.invocationOptions);
- if (result == null) {
+ if (error.getPointer() == null) {
throw new GErrorException(new GErrorStruct(error.getValue()));
}
return (Test) objectFor(result, Test.class);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]