java-gobject-introspection r100 - in trunk/src/org/gnome/gir: compiler gobject



Author: walters
Date: Tue Oct 21 02:49:49 2008
New Revision: 100
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=100&view=rev

Log:
Write out @Return for no-transfer return values


Modified:
   trunk/src/org/gnome/gir/compiler/CodeFactory.java
   trunk/src/org/gnome/gir/gobject/GObject.java
   trunk/src/org/gnome/gir/gobject/GObjectAPI.java
   trunk/src/org/gnome/gir/gobject/GTypeMapper.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	Tue Oct 21 02:49:49 2008
@@ -78,6 +78,7 @@
 import org.gnome.gir.gobject.GSList;
 import org.gnome.gir.gobject.GType;
 import org.gnome.gir.gobject.UnmappedPointer;
+import org.gnome.gir.gobject.annotation.Return;
 import org.gnome.gir.repository.ArgInfo;
 import org.gnome.gir.repository.BaseInfo;
 import org.gnome.gir.repository.BoxedInfo;
@@ -98,6 +99,7 @@
 import org.gnome.gir.repository.Repository;
 import org.gnome.gir.repository.SignalInfo;
 import org.gnome.gir.repository.StructInfo;
+import org.gnome.gir.repository.Transfer;
 import org.gnome.gir.repository.TypeInfo;
 import org.gnome.gir.repository.TypeTag;
 import org.gnome.gir.repository.UnionInfo;
@@ -1661,7 +1663,7 @@
 		if (fi.isDeprecated()) {
 			AnnotationVisitor av = mv.visitAnnotation(Type.getType(Deprecated.class).getDescriptor(), true);
 			av.visitEnd();
-		}		
+		}
 		
 		String globalInternalsName = getInternals(fi);	
 		String symbol = fi.getSymbol();
@@ -1673,6 +1675,13 @@
 		else
 			returnTypeBox = ctx.returnType;
 		
+		Transfer returnTransfer = fi.getCallerOwns();
+		if (returnBox == null) {
+			AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(Return.class), true);
+			av.visitEnum("transfer", Type.getDescriptor(Transfer.class), returnTransfer.name());
+			av.visitEnd();
+		}
+		
 		mv.visitCode();
 		LocalVariableTable locals = ctx.allocLocals();
 		int functionOffset = locals.allocTmp("function", Type.getType(Function.class));

Modified: trunk/src/org/gnome/gir/gobject/GObject.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObject.java	(original)
+++ trunk/src/org/gnome/gir/gobject/GObject.java	Tue Oct 21 02:49:49 2008
@@ -69,6 +69,13 @@
 
     private final IntPtr objectID = new IntPtr(System.identityHashCode(this));
     
+    private static final boolean debugMemory = false;
+    
+    private static final void debugMemory(String fmt, String... args) {
+    	if (debugMemory)
+    		System.err.println(String.format(fmt, (Object[])args));
+    }
+    
     /* Hold a strong Java reference between this proxy object and any signal
      * handlers installed.  Often this would be done anyways, but if you're
      * just calling System.out.println in a callback, it would otherwise
@@ -98,14 +105,17 @@
     public GObject(Initializer init) { 
         super(init.needRef ? initializer(init.ptr, false, init.ownsHandle) : init);
         if (init.ownsHandle) {
+        	debugMemory("INIT OWNERSHIP " + this);
             strongReferences.put(this, Boolean.TRUE);
             
             /* Floating refs are just a convenience for C; we always want only strong
              * nonfloating refs for objects which have a JVM peer.
              */
             boolean wasFloating = GObjectAPI.gobj.g_object_is_floating(this);
-            if (wasFloating)
+            if (wasFloating) {
+            	debugMemory("Sinking " + this);
             	GObjectAPI.gobj.g_object_ref_sink(this);
+            }
             
             /* The toggle reference is our primary means of memory management between
              * this Proxy object and the GObject.
@@ -189,7 +199,6 @@
         GValue propValue = new GValue(propType);
         propValue.set(data);
         GObjectAPI.gobj.g_object_set_property(this, property, propValue);
-        GValueAPI.gvalue.g_value_unset(propValue); // Release any memory
     }
     
     /**
@@ -207,7 +216,7 @@
         final GType propType = propertySpec.value_type;
         GValue propValue = new GValue(propType);
         GObjectAPI.gobj.g_object_get_property(this, property, propValue);
-        return propValue.toJava();
+        return propValue.unbox();
     }
     
     protected void disposeNativeHandle(Pointer ptr) {
@@ -215,18 +224,22 @@
     }
     @Override
     protected void ref() {
+    	debugMemory("REF " + this);    	
     	GObjectAPI.gobj.g_object_ref(this);
     }
 
     @Override
     protected void unref() {
+    	debugMemory("UNREF " + this);    	
     	GObjectAPI.gobj.g_object_unref(this);
     }
     protected void invalidate() {
         try {
+        	debugMemory("INVALIDATE " + this);        	
             // Need to increase the ref count before removing the toggle ref, so 
             // ensure the native object is not destroyed.
             if (ownsHandle.get()) {
+            	debugMemory("REMOVING TOGGLE " + this);             	
                 ref();
 
                 // Disconnect the callback.
@@ -310,6 +323,7 @@
              * be retained for later retrieval
              */
             GObject o = (GObject) NativeObject.instanceFor(ptr);
+            debugMemory(String.format("TOGGLE o=%s is_last=%s", o, is_last_ref));
             if (o == null) {
                 return;
             }
@@ -325,6 +339,7 @@
 		@Override
 		public void callback(Pointer data, Pointer obj) {
 			GObject o = (GObject) NativeObject.instanceFor(obj);
+            debugMemory(String.format("WEAK o=%s obj=%s", o, obj));			
 			// Clear out the signal handler references
 			if (o == null)
 				return;

Modified: trunk/src/org/gnome/gir/gobject/GObjectAPI.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObjectAPI.java	(original)
+++ trunk/src/org/gnome/gir/gobject/GObjectAPI.java	Tue Oct 21 02:49:49 2008
@@ -108,6 +108,7 @@
     //GQuark                g_type_qname                   (GType            type);
     GType g_type_from_name(String name);
     GType g_type_parent(GType type);
+    GType g_type_fundamental(GType type);
     int g_type_depth(GType type);
     Pointer g_type_create_instance(GType type);
     void g_type_free_instance(Pointer instance);

Modified: trunk/src/org/gnome/gir/gobject/GTypeMapper.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GTypeMapper.java	(original)
+++ trunk/src/org/gnome/gir/gobject/GTypeMapper.java	Tue Oct 21 02:49:49 2008
@@ -54,6 +54,7 @@
 import org.gnome.gir.gobject.annotation.IncRef;
 import org.gnome.gir.gobject.annotation.Invalidate;
 import org.gnome.gir.gobject.annotation.Return;
+import org.gnome.gir.repository.Transfer;
 
 import com.sun.jna.CallbackParameterContext;
 import com.sun.jna.FromNativeContext;
@@ -134,10 +135,17 @@
             }
             if (context instanceof MethodResultContext) {
                 //
-                // By default, gstreamer increments the refcount on objects 
-                // returned from functions, so drop a ref here
+                // By default, we assume objects have incremented reference counts. 
+            	// Otherwise, the code generator should have created an @Return(transfer=NOTHING)
+            	// annotation.
                 //
-                boolean ownsHandle = ((MethodResultContext) context).getMethod().isAnnotationPresent(Return.class);
+                Return anno = ((MethodResultContext) context).getMethod().getAnnotation(Return.class);
+                boolean ownsHandle;
+                if (anno == null || anno.transfer().equals(Transfer.EVERYTHING)) {
+                	ownsHandle = true;
+                } else {
+                	ownsHandle = false;
+                }
                 int refadj = ownsHandle ? -1 : 0;
                 return NativeObject.objectFor((Pointer) result, context.getTargetType(), refadj, ownsHandle);
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]