seed r375 - in trunk: examples extensions libseed tests



Author: racarr
Date: Sun Nov 30 22:39:20 2008
New Revision: 375
URL: http://svn.gnome.org/viewvc/seed?rev=375&view=rev

Log:
Offline changes from train ride.
Add closure finalization test.
Add Gst video example.
Fix memory leak of GIBaseInfo in closures.
Fix leak of property name array in object/struct constructors when exceptions
are thrown.
Add SEED_DEBUG_CONSTRUCTION and struct constructor logging.
Add SEED_DEBUG_GTYPE
Add SEED_NOTE for property installation
Add SEED_NOTE for class init closure.
Fix extra newline in struct finalization.
Add SEED_NOTE for instance init closure
Add SEED_NOTE for type registration.
Make union/struct/boxed ref their infos. Will make leaks until reviewed a bit
more.
Import GIRepository namespace automatically.
Set .info property on functions to be their GIBaseInfo. (Note, any use of
GIBaseInfos will have to be manually memory managed for now...).
Add test for .info and GIRepository GIR.
Add support for GI_TYPE_TAG_GTYPE in argument_make_js and make_argument.
Add test for GIObjectInfo, prints out interfaces of object.
Define constructor.prototype on constructors, i.e. Gtk.Window.prototype.
Update tests to use .prototype.
Update Gio.js and Gtk.js to use .prototype.
Update introspect.js to use .prototype
Add a test which verifies .prototype is the prototype of an instantiated
object.
Update n-oscillator to track GI changes.


Added:
   trunk/examples/video.js   (contents, props changed)
   trunk/tests/closure-finalization.js   (contents, props changed)
   trunk/tests/constructor-prototype.js
   trunk/tests/function-info.js   (contents, props changed)
   trunk/tests/object-info.js   (contents, props changed)
Modified:
   trunk/examples/Makefile.am
   trunk/examples/introspect.js
   trunk/examples/n-oscillator.js
   trunk/extensions/Gio.js
   trunk/extensions/Gtk.js
   trunk/libseed/seed-closure.c
   trunk/libseed/seed-debug.h
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-gtype.c
   trunk/libseed/seed-structs.c
   trunk/libseed/seed-types.c
   trunk/tests/Makefile.am

Modified: trunk/examples/Makefile.am
==============================================================================
--- trunk/examples/Makefile.am	(original)
+++ trunk/examples/Makefile.am	Sun Nov 30 22:39:20 2008
@@ -1,13 +1,14 @@
 SUBDIRS = ide \
           lightsoff \
           clutter-shader \
-          glib
+          glib 
           
 examplesdir=$(datadir)/doc/seed/examples
 examples_DATA = \
 	actions.js \
 	calculator.js \
 	gconf.js \
+	video.js \
 	accelgroup.js \
 	clutter.js \
 	introspect.js \
@@ -28,6 +29,7 @@
 	actions.js \
 	calculator.js \
 	gconf.js \
+	video.js \
 	accelgroup.js \
 	clutter.js \
 	introspect.js \

Modified: trunk/examples/introspect.js
==============================================================================
--- trunk/examples/introspect.js	(original)
+++ trunk/examples/introspect.js	Sun Nov 30 22:39:20 2008
@@ -1,8 +1,8 @@
 #!/usr/bin/env seed
 Seed.import_namespace("Gtk");
 
-proto = Seed.prototype(Gtk.Window);
+proto = Gtk.Window.prototype;
 method = Seed.introspect(proto.translate_coordinates);
 //JSON.stringify and JSON.fromString come from json2.js available on json.org
 //Also in extensions/seed.js.
-Seed.print(JSON.stringify(method));
\ No newline at end of file
+Seed.print(JSON.stringify(method));

Modified: trunk/examples/n-oscillator.js
==============================================================================
--- trunk/examples/n-oscillator.js	(original)
+++ trunk/examples/n-oscillator.js	Sun Nov 30 22:39:20 2008
@@ -19,9 +19,9 @@
 	// No actual introspection data for audiotestsrc, so can not
 	// instantiate one with a constructor, have to use element_factory,
 	// likewise for the others.
-	this.audiosrc = Gst.element_factory_make("audiotestsrc", "audio");
-	this.audiosink = Gst.element_factory_make("alsasink", "sink");
-	this.volume = Gst.element_factory_make("volume", "vcontrol");
+	this.audiosrc = Gst.ElementFactory.make("audiotestsrc", "audio");
+	this.audiosink = Gst.ElementFactory.make("alsasink", "sink");
+	this.volume = Gst.ElementFactory.make("volume", "vcontrol");
 	this.audiosrc.freq = freq;
 	
 	this.pipeline.add(this.audiosrc);

Added: trunk/examples/video.js
==============================================================================
--- (empty file)
+++ trunk/examples/video.js	Sun Nov 30 22:39:20 2008
@@ -0,0 +1,24 @@
+#!/usr/local/bin/seed
+Seed.import_namespace("Gtk");
+Seed.import_namespace("Gst");
+Seed.import_namespace("GstVideo");
+
+Gtk.init(null, null);
+Gst.init(null, null);
+
+pipeline = new Gst.Pipeline({name: "VideoTest"});
+
+source = Gst.ElementFactory.make("videotestsrc", "video");
+sink = Gst.ElementFactory.make("autovideosink", "sink");
+
+
+pipeline.add(source);
+pipeline.add(sink);
+source.link(sink);
+
+pipeline.set_state(Gst.State.playing);
+
+Gtk.main();
+
+
+

Modified: trunk/extensions/Gio.js
==============================================================================
--- trunk/extensions/Gio.js	(original)
+++ trunk/extensions/Gio.js	Sun Nov 30 22:39:20 2008
@@ -1,6 +1,6 @@
 (function()
 {
-    var prototype = Seed.prototype(Gio.FileInputStream);
+    var prototype = Gio.FileInputStream.prototype;
 
     prototype.get_contents = function()
     {

Modified: trunk/extensions/Gtk.js
==============================================================================
--- trunk/extensions/Gtk.js	(original)
+++ trunk/extensions/Gtk.js	Sun Nov 30 22:39:20 2008
@@ -21,6 +21,6 @@
 						       padding, position);
 			 }
 		 }
-	 Seed.prototype(Gtk.VBox).pack = pack;
-	 Seed.prototype(Gtk.HBox).pack = pack;
- }).apply();
\ No newline at end of file
+	 Gtk.VBox.prototype.pack = pack;
+	 Gtk.HBox.prototype.pack = pack;
+ }).apply();

Modified: trunk/libseed/seed-closure.c
==============================================================================
--- trunk/libseed/seed-closure.c	(original)
+++ trunk/libseed/seed-closure.c	Sun Nov 30 22:39:20 2008
@@ -102,9 +102,14 @@
 {
 	SeedNativeClosure *privates =
 		(SeedNativeClosure *) JSObjectGetPrivate(object);
+	
+	SEED_NOTE(FINALIZATION, "Finalizing closure object %p with "
+			  "GIBaseInfo: %s \n", object,
+			  g_base_info_get_name((GIBaseInfo *)privates->info));
 
 	g_free(privates->cif->arg_types);
 	g_free(privates->cif);
+	g_base_info_unref((GIBaseInfo *)privates->info);
 	munmap(privates->closure, sizeof(ffi_closure));
 }
 

Modified: trunk/libseed/seed-debug.h
==============================================================================
--- trunk/libseed/seed-debug.h	(original)
+++ trunk/libseed/seed-debug.h	Sun Nov 30 22:39:20 2008
@@ -10,9 +10,11 @@
 	SEED_DEBUG_MISC = 1 << 1,
 	SEED_DEBUG_FINALIZATION = 1 << 2,
 	SEED_DEBUG_INITIALIZATION = 1 << 3,
-	SEED_DEBUG_INVOCATION = 1 << 4,
-	SEED_DEBUG_SIGNAL = 1 << 5,
-	SEED_DEBUG_STRUCTS = 1 << 6
+	SEED_DEBUG_CONSTRUCTION = 1 << 4,
+	SEED_DEBUG_INVOCATION = 1 << 5,
+	SEED_DEBUG_SIGNAL = 1 << 6,
+	SEED_DEBUG_STRUCTS = 1 << 7,
+	SEED_DEBUG_GTYPE = 1 << 8
 } SeedDebugFlag;
 
 #ifdef SEED_ENABLE_DEBUG

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Sun Nov 30 22:39:20 2008
@@ -33,6 +33,8 @@
 
 gchar *glib_message = 0;
 
+GIBaseInfo * base_info_info = 0;
+
 guint seed_debug_flags = 0;		/* global seed debug flag */
 
 #ifdef SEED_ENABLE_DEBUG
@@ -42,7 +44,9 @@
 	{"initialization", SEED_DEBUG_INITIALIZATION},
 	{"signal", SEED_DEBUG_SIGNAL},
 	{"invocation", SEED_DEBUG_INVOCATION},
-	{"structs", SEED_DEBUG_STRUCTS}
+	{"structs", SEED_DEBUG_STRUCTS},
+	{"construction", SEED_DEBUG_CONSTRUCTION},
+	{"gtype", SEED_DEBUG_GTYPE}
 };
 #endif							/* SEED_ENABLE_DEBUG */
 
@@ -150,7 +154,8 @@
 
 			g_free(mes);
 			g_free(params);
-
+			
+			JSPropertyNameArrayRelease(jsprops);
 			return (JSObjectRef) JSValueMakeNull(ctx);
 		}
 		// TODO: exception handling
@@ -171,6 +176,7 @@
 
 			g_free(prop_name);
 			g_free(params);
+			JSPropertyNameArrayRelease(jsprops);
 			return 0;
 		}
 		params[i].name = prop_name;
@@ -448,12 +454,13 @@
 												gboolean instance)
 {
 	GIFunctionInfoFlags flags;
-	JSValueRef method_ref;
+	JSObjectRef method_ref;
 	const gchar *name;
 
-	// if (g_base_info_is_deprecated ((GIBaseInfo *) info))
-	// g_printf("Not defining deprecated symbol: %s \n",
-	// g_base_info_get_name((GIBaseInfo *)info));
+	//if (g_base_info_is_deprecated ((GIBaseInfo *) info))
+	//g_printf("Not defining deprecated symbol: %s \n",
+	//g_base_info_get_name((GIBaseInfo *)info));
+	
 
 	flags = g_function_info_get_flags(info);
 
@@ -468,6 +475,8 @@
 	if (!strcmp(name, "new"))
 		name = "_new";
 	seed_object_set_property(ctx, object, name, method_ref);
+	seed_object_set_property(ctx, method_ref, "info", 
+	        	seed_make_struct(ctx, info, base_info_info));
 
 }
 
@@ -994,6 +1003,9 @@
 				seed_object_set_property(ctx, namespace_ref,
 										 g_base_info_get_name
 										 (info), constructor_ref);
+				seed_object_set_property(ctx, constructor_ref,
+										 "prototype",
+          		    seed_gobject_get_prototype_for_gtype(type));
 				JSValueProtect(ctx, (JSValueRef) constructor_ref);
 			}
 		}
@@ -1341,12 +1353,17 @@
 	seed_gtype_init(eng);
 
 	defaults_script =
-		JSStringCreateWithUTF8CString("try{Seed.include(\"/usr/share/"
+		JSStringCreateWithUTF8CString("Seed.import_namespace(\""
+									  "GIRepository\");"
+                                      "try{Seed.include(\"/usr/share/"
 									  "seed/Seed.js\");} catch(e){}"
 									  "Seed.include(\"/usr/local/share"
 									  "/seed/Seed.js\");");
 	JSEvaluateScript(eng->context, defaults_script, NULL, NULL, 0, NULL);
 	JSStringRelease(defaults_script);
+	
+	base_info_info = g_irepository_find_by_name(0, "GIRepository",
+												"IBaseInfo");
 
 	return eng;
 }

Modified: trunk/libseed/seed-gtype.c
==============================================================================
--- trunk/libseed/seed-gtype.c	(original)
+++ trunk/libseed/seed-gtype.c	Sun Nov 30 22:39:20 2008
@@ -278,7 +278,7 @@
 							" as first argument");
 		return (JSObjectRef) JSValueMakeNull(ctx);
 	}
-
+	
 	/* Signal name */
 	jsname = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
 	/* seed_value_to_string can handle non strings, however the kind
@@ -296,6 +296,10 @@
 	/* Type to install on. Comes from class. */
 	jstype = seed_object_get_property(ctx, thisObject, "type");
 	itype = seed_value_to_int(ctx, jstype, exception);
+	
+	SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s",
+			  name,
+			  g_type_name(itype));
 
 	/* Signal flags */
 	jsflags = seed_object_get_property(ctx, 
@@ -368,6 +372,9 @@
 	type = (GType) JSObjectGetPrivate(*(JSObjectRef *) args[1]);
 	jsargs[0] = seed_make_pointer(ctx, *(gpointer *) args[0]);
 	jsargs[1] = seed_gobject_get_prototype_for_gtype(type);
+	
+	SEED_NOTE(GTYPE, "Marshalling class init closure for type: %s",
+			  g_type_name(type));
 
 	// TODO: 
 	// Should probably have a custom type for class, and have it auto convert.
@@ -408,6 +415,10 @@
 	jsargs = seed_make_pointer(ctx, *(gpointer *) args[1]);
 	this_object =
 		(JSObjectRef) seed_value_from_object(ctx, *(GObject **) args[0], 0);
+	
+	SEED_NOTE(GTYPE, "Handling instance init closure for: %p with type: %s",
+			  *(GObject **)args[0],
+			  g_type_name(G_OBJECT_TYPE(*(GObject **)args[0])));
 
 	JSObjectCallAsFunction(ctx, function, this_object, 1, &jsargs,
 						   &exception);
@@ -529,7 +540,7 @@
 	if (!JSValueIsNumber(ctx, parent_ref))
 	{
 		seed_make_exception(ctx, exception, "TypeError",
-							"GType constructor expected" " GType for parent");
+							"GType constructor expected GType for parent");
 
 		return (JSObjectRef) JSValueMakeNull(ctx);
 	}
@@ -548,6 +559,9 @@
 	}
 
 	parent_type = (GType) seed_value_to_int(ctx, parent_ref, exception);
+	
+	SEED_NOTE(GTYPE, "Registering new GType with name: %s as child of %s.",
+			  new_name, g_type_name(parent_type));
 
 	g_type_query(parent_type, &query);
 	type_info.class_size = query.class_size;

Modified: trunk/libseed/seed-structs.c
==============================================================================
--- trunk/libseed/seed-structs.c	(original)
+++ trunk/libseed/seed-structs.c	Sun Nov 30 22:39:20 2008
@@ -39,7 +39,7 @@
 		(seed_struct_privates *) JSObjectGetPrivate(object);
 	
 	SEED_NOTE(STRUCTS, "Finalizing seed_pointer object %p. with "
-			  "priv->free_pointer = %d with type: %s\n", 
+			  "priv->free_pointer = %d with type: %s", 
 			  priv->pointer,
 			  priv->free_pointer,
 			  priv->info ? g_base_info_get_name(priv->info) : "[generic]");
@@ -216,7 +216,8 @@
 	GIFieldInfo * field;
 	GITypeInfo * field_type;
 	gchar * cproperty_name;
-	seed_struct_privates *priv = (seed_struct_privates *)JSObjectGetPrivate(object);
+	seed_struct_privates *priv = 
+		(seed_struct_privates *)JSObjectGetPrivate(object);
 	gboolean ret;
 
 	length = JSStringGetMaximumUTF8CStringSize(property_name);
@@ -408,7 +409,7 @@
 	seed_struct_privates *priv = g_malloc(sizeof(seed_struct_privates));
 
 	priv->pointer = younion;
-	priv->info = info;
+	priv->info = info ? g_base_info_ref(info) : 0;
 	priv->free_pointer = FALSE;
 
 	object = JSObjectMake(ctx, seed_union_class, priv);
@@ -440,7 +441,7 @@
 	gint i, n_methods;
 	seed_struct_privates *priv = g_malloc(sizeof(seed_struct_privates));
 
-	priv->info = info;
+	priv->info = info ? g_base_info_ref(info) : 0;
 	priv->pointer = boxed;
 	// Boxed finalize handler handles freeing.
 	priv->free_pointer = FALSE;
@@ -460,7 +461,7 @@
 	gint i, n_methods;
 	seed_struct_privates *priv = g_malloc(sizeof(seed_struct_privates));
 
-	priv->info = info;
+	priv->info = info ? g_base_info_ref(info) : 0;
 	priv->pointer = strukt;
 	priv->free_pointer = FALSE;
 
@@ -513,6 +514,9 @@
 	JSValueRef jsprop_value;
 	GArgument field_value;
 	gchar * prop_name;
+	
+	SEED_NOTE(CONSTRUCTION, "Constructing struct/union of type: %s \n",
+			  g_base_info_get_name(info));
 
 	if (type == GI_INFO_TYPE_STRUCT)
 	{
@@ -562,7 +566,7 @@
 			seed_make_exception(ctx, exception, "PropertyError", mes);
 			
 			g_free(mes);
-			
+			JSPropertyNameArrayRelease(jsprops);			
 			return (JSObjectRef) JSValueMakeNull(ctx);
 		}
 		field_type = g_field_info_get_type(field);

Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c	(original)
+++ trunk/libseed/seed-types.c	Sun Nov 30 22:39:20 2008
@@ -251,6 +251,9 @@
 	case GI_TYPE_TAG_UTF8:
 		arg->v_string = seed_value_to_string(ctx, value, exception);
 		break;
+	case GI_TYPE_TAG_GTYPE:
+		arg->v_int = seed_value_to_int(ctx, value, exception);
+		break;
 	case GI_TYPE_TAG_INTERFACE:
 		{
 			GIBaseInfo *interface;
@@ -448,6 +451,8 @@
 		return seed_value_from_double(ctx, arg->v_double, exception);
 	case GI_TYPE_TAG_UTF8:
 		return seed_value_from_string(ctx, arg->v_string, exception);
+	case GI_TYPE_TAG_GTYPE:
+		return seed_value_from_int(ctx, arg->v_int, exception);
 	case GI_TYPE_TAG_INTERFACE:
 		{
 			GIBaseInfo *interface;

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Sun Nov 30 22:39:20 2008
@@ -1,12 +1,16 @@
 EXTRA_DIST = \
-	argv.js \
+    argv.js \
+    closure-finalization.js \
     compare.js \
     struct-nested-set.js \
     struct-constructor.js \
+    function-info.js \
+    object-info.js \
     constructor-args.js \
     signal-this.js \
     struct-set-member.js \
     c-module.js \
+    constructor-prototype.js \
     struct-offsets.js \
     gtype-typerror.js \
     gtype-signal.js \

Added: trunk/tests/closure-finalization.js
==============================================================================
--- (empty file)
+++ trunk/tests/closure-finalization.js	Sun Nov 30 22:39:20 2008
@@ -0,0 +1,23 @@
+#!/usr/local/bin/seed
+// Returns: 0
+// STDIN:
+// STDOUT:\[object GtkVBox\]
+// STDERR:
+Seed.import_namespace("Gtk");
+Gtk.init(null, null);
+
+w = new Gtk.Window();
+
+// Closure will always be GCed at end of signal.
+signal = function()
+{
+	w.foreach(function(widget){Seed.print(widget)});
+}
+
+vbox = new Gtk.VBox();
+
+w.add(vbox);
+
+w.signal.show.connect(signal);
+
+w.show_all();

Added: trunk/tests/constructor-prototype.js
==============================================================================
--- (empty file)
+++ trunk/tests/constructor-prototype.js	Sun Nov 30 22:39:20 2008
@@ -0,0 +1,12 @@
+#!/usr/local/bin/seed
+// Returns: 0
+// STDIN:
+// STDOUT:Hello World
+// STDERR:
+Seed.import_namespace("Gtk");
+Gtk.init(null, null);
+
+Gtk.Window.prototype.hello = "Hello World";
+
+a = new Gtk.Window();
+Seed.print(a.hello);

Added: trunk/tests/function-info.js
==============================================================================
--- (empty file)
+++ trunk/tests/function-info.js	Sun Nov 30 22:39:20 2008
@@ -0,0 +1,10 @@
+#!/usr/local/bin/seed
+// Returns: 0
+// STDIN:
+// STDOUT:resize
+// STDERR:
+Seed.import_namespace("Gtk");
+
+f = Gtk.Window.prototype.resize.info
+
+Seed.print(GIRepository.base_info_get_name(f));

Added: trunk/tests/object-info.js
==============================================================================
--- (empty file)
+++ trunk/tests/object-info.js	Sun Nov 30 22:39:20 2008
@@ -0,0 +1,19 @@
+#!/usr/local/bin/seed
+// Returns: 0
+// STDIN:
+// STDOUT:Window implements interfaces\nInterface: Buildable\nInterface: ImplementorIface
+// STDERR:
+Seed.import_namespace("Gtk");
+
+info = GIRepository.irepository_find_by_gtype(null, Gtk.Window.type);
+Seed.print(GIRepository.base_info_get_name(info) + " implements interfaces");
+
+n = GIRepository.object_info_get_n_interfaces(info);
+for (i = 0; i < n; i++)
+{
+	property = GIRepository.object_info_get_interface(info, i);
+	Seed.print("Interface: " + GIRepository.base_info_get_name(property));
+	GIRepository.base_info_unref(property);
+}
+
+GIRepository.base_info_unref(info);



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