java-gobject-introspection r110 - trunk/src/org/gnome/gir/gobject



Author: walters
Date: Sat Oct 25 15:01:14 2008
New Revision: 110
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=110&view=rev

Log:
A bit more boxed memmgt; try to call boxed_free in same thread

Modified:
   trunk/src/org/gnome/gir/gobject/BoxedStructure.java
   trunk/src/org/gnome/gir/gobject/GBoxed.java
   trunk/src/org/gnome/gir/gobject/GObject.java
   trunk/src/org/gnome/gir/gobject/GValue.java

Modified: trunk/src/org/gnome/gir/gobject/BoxedStructure.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/BoxedStructure.java	(original)
+++ trunk/src/org/gnome/gir/gobject/BoxedStructure.java	Sat Oct 25 15:01:14 2008
@@ -18,7 +18,7 @@
 	
 	protected BoxedStructure(GType gtype, Pointer pointer, TypeMapper mapper) {
 		super(mapper);
-		useMemory(pointer);		
+		useMemory(pointer);
 		this.gtype = gtype;
 		isNative = true;
 	}

Modified: trunk/src/org/gnome/gir/gobject/GBoxed.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GBoxed.java	(original)
+++ trunk/src/org/gnome/gir/gobject/GBoxed.java	Sat Oct 25 15:01:14 2008
@@ -9,7 +9,7 @@
 
 public abstract class GBoxed extends PointerType implements RegisteredType {
 	
-	protected GType gtype;
+	protected GType gtype = GType.INVALID;
 	
 	public GBoxed(GType gtype, Pointer ptr) {
 		super(ptr);
@@ -36,9 +36,6 @@
 	
 	public static Pointer getPointerFor(Object data) {
 		Pointer ptr;
-		/* Since we're denaturing it here, we need to ensure that the structure
-		 * is written to native memory.
-		 */
 		if (data instanceof BoxedStructure) {
 			ptr = ((BoxedStructure) data).getPointer();
 		} else if (data instanceof BoxedUnion) {
@@ -48,6 +45,9 @@
 		} else {	
 			throw new RuntimeException("Invalid unboxed object " + data);
 		}
+		/* Since we're denaturing it here, we need to ensure that the structure
+		 * is written to native memory.
+		 */		
 		if (data instanceof Structure)
 			((Structure) data).write();		
 		return ptr;

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	Sat Oct 25 15:01:14 2008
@@ -214,7 +214,7 @@
         final GType propType = propertySpec.value_type;
         GValue propValue = new GValue(propType);
         GObjectAPI.gobj.g_object_get_property(this, property, propValue);
-        return propValue.unbox();
+        return propValue.unboxAndUnset();
     }
     
     protected void disposeNativeHandle(Pointer ptr) {

Modified: trunk/src/org/gnome/gir/gobject/GValue.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GValue.java	(original)
+++ trunk/src/org/gnome/gir/gobject/GValue.java	Sat Oct 25 15:01:14 2008
@@ -68,12 +68,16 @@
         GValueAPI.gvalue.g_value_init(this, type);
 	}
 	
-	@Override
-	public void finalize() throws Throwable {
+	protected void free() {
 		if (ownsHandle) {
 			GValueAPI.gvalue.g_value_unset(this.getPointer());
 			ownsHandle = false;
-		}
+		}		
+	}
+	
+	@Override
+	public void finalize() throws Throwable {
+		free();
 		super.finalize();
 	}
 	
@@ -182,6 +186,12 @@
         }
         throw new IllegalArgumentException("Expected double value, not " + value.getClass());
     }    
+    
+    public Object unboxAndUnset() {
+    	Object ret = unbox();
+    	free();
+    	return ret;
+    }
 	
 	public Object unbox() {
 		GType fundamental = g_type.getFundamental();		



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