Closures and marshallers



Hi guys,

just committed the following to libbonobo which fixes a few bugs:

====
2001-08-01  Martin Baulig  <baulig suse de>

	* bonobo/bonobo-generic-factory.c (bonobo_generic_factory_construct):
	Use bonobo_marshal_POINTER__STRING, not g_cclosure_marshal_VOID__STRING
	as closure marshaller.
	(bonobo_generic_factory_new_generic): Use G_TYPE_POINTER as return value
	for the closure.

	* bonobo/bonobo-marshal.list: Changed BOXED:POINTER,STRING,POINTER to
	BOXED:POINTER,STRING,BOXED and added OBJECT:STRING.

	* bonobo/bonobo-moniker-simple.c (simple_moniker): Initialize the static
	GValue before calling g_value_init() on it or you'll get a core dump.

	* bonobo/bonobo-moniker-simple.c (bonobo_moniker_simple_construct): Use
	bonobo_marshal_BOXED__POINTER_STRING_BOXED, not
	bonobo_marshal_BOXED__POINTER_STRING_POINTER.

2001-08-01  Martin Baulig  <baulig suse de>

	* bonobo/bonobo-types.c (bonobo_corba_exception_get_type): We need to use
	a custom boxed type for BONOBO_TYPE_CORBA_ENVIRONMENT since it's not a
	CORBA::Object.

=====

A few comments so that we don't make the same mistakes over and over again:

	* bonobo/bonobo-generic-factory.c (bonobo_generic_factory_construct):
	Use bonobo_marshal_POINTER__STRING, not g_cclosure_marshal_VOID__STRING
	as closure marshaller.
	(bonobo_generic_factory_new_generic): Use G_TYPE_POINTER as return value
	for the closure.

It's important to use a marshaller which returns a value for a closure which
has a return value, otherwise you'll always get a return value of NULL.

	* bonobo/bonobo-moniker-simple.c (simple_moniker): Initialize the static
	GValue before calling g_value_init() on it or you'll get a core dump.

The following is a very quick way to get a segfault:

        void some_func () {
            GValue value;

            g_value_init (&value, <some-type>);
        }

Correct is:

        void some_func () {
            GValue value = { 0, };

            g_value_init (&value, <some-type>);
        }

Here's the full patch for it:

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libbonobo/ChangeLog,v
retrieving revision 1.118
diff -u -u -r1.118 ChangeLog
--- ChangeLog	2001/08/01 00:09:48	1.118
+++ ChangeLog	2001/08/01 02:08:55
@@ -1,3 +1,27 @@
+2001-08-01  Martin Baulig  <baulig suse de>
+
+	* bonobo/bonobo-generic-factory.c (bonobo_generic_factory_construct):
+	Use bonobo_marshal_POINTER__STRING, not g_cclosure_marshal_VOID__STRING
+	as closure marshaller.
+	(bonobo_generic_factory_new_generic): Use G_TYPE_POINTER as return value
+	for the closure.
+
+	* bonobo/bonobo-marshal.list: Changed BOXED:POINTER,STRING,POINTER to
+	BOXED:POINTER,STRING,BOXED and added OBJECT:STRING.
+
+	* bonobo/bonobo-moniker-simple.c (simple_moniker): Initialize the static
+	GValue before calling g_value_init() on it or you'll get a core dump.
+
+	* bonobo/bonobo-moniker-simple.c (bonobo_moniker_simple_construct): Use
+	bonobo_marshal_BOXED__POINTER_STRING_BOXED, not
+	bonobo_marshal_BOXED__POINTER_STRING_POINTER.
+
+2001-08-01  Martin Baulig  <baulig suse de>
+
+	* bonobo/bonobo-types.c (bonobo_corba_exception_get_type): We need to use
+	a custom boxed type for BONOBO_TYPE_CORBA_ENVIRONMENT since it's not a
+	CORBA::Object.
+
 2001-08-01  Michael Meeks  <michael ximian com>
 
 	* bonobo/bonobo-main.h: fix broken include guards.
Index: bonobo/bonobo-generic-factory.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-generic-factory.c,v
retrieving revision 1.36
diff -u -u -r1.36 bonobo-generic-factory.c
--- bonobo/bonobo-generic-factory.c	2001/07/31 00:12:29	1.36
+++ bonobo/bonobo-generic-factory.c	2001/08/01 02:08:56
@@ -21,6 +21,7 @@
 #include <bonobo/Bonobo.h>
 #include <bonobo/bonobo-main.h>
 #include <bonobo/bonobo-types.h>
+#include <bonobo/bonobo-marshal.h>
 #include <bonobo/bonobo-exception.h>
 #include <bonobo/bonobo-generic-factory.h>
 #include <bonobo/bonobo-running-context.h>
@@ -170,7 +171,7 @@
 	g_return_val_if_fail (corba_factory != CORBA_OBJECT_NIL, NULL);
 	
 	factory->priv->factory_closure =
-		bonobo_closure_store (factory_closure, g_cclosure_marshal_VOID__STRING);
+		bonobo_closure_store (factory_closure, bonobo_marshal_POINTER__STRING);
 	factory->priv->oaf_iid    = g_strdup (oaf_iid);
 
 	CORBA_exception_init (&ev);
@@ -289,14 +290,14 @@
 	g_return_val_if_fail (factory != NULL, NULL);
 	g_return_val_if_fail (BONOBO_IS_GENERIC_FACTORY (factory), NULL);
 
-	g_value_init (&ret_val, BONOBO_OBJECT_TYPE);
+	g_value_init (&ret_val, G_TYPE_POINTER);
 	
 	bonobo_closure_invoke (factory->priv->factory_closure,
 			       &ret_val,
 			       BONOBO_GENERIC_FACTORY_TYPE, factory,
 			       G_TYPE_STRING, oaf_iid, 0);
 
-	ret = g_value_get_object (&ret_val);
+	ret = g_value_peek_pointer (&ret_val);
 	g_value_unset (&ret_val);
 
 	return ret;
Index: bonobo/bonobo-marshal.list
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-marshal.list,v
retrieving revision 1.7
diff -u -u -r1.7 bonobo-marshal.list
--- bonobo/bonobo-marshal.list	2001/07/30 17:43:19	1.7
+++ bonobo/bonobo-marshal.list	2001/08/01 02:08:56
@@ -11,4 +11,5 @@
 VOID:BOXED,UINT,POINTER
 BOXED:STRING,BOOLEAN,POINTER,POINTER
 POINTER:POINTER,POINTER
-BOXED:POINTER,STRING,POINTER
+BOXED:POINTER,STRING,BOXED
+POINTER:STRING
Index: bonobo/bonobo-moniker-simple.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-moniker-simple.c,v
retrieving revision 1.11
diff -u -u -r1.11 bonobo-moniker-simple.c
--- bonobo/bonobo-moniker-simple.c	2001/07/30 17:43:19	1.11
+++ bonobo/bonobo-moniker-simple.c	2001/08/01 02:08:56
@@ -26,7 +26,7 @@
 		CORBA_Environment           *ev)
 {
 	BonoboMonikerSimple *simple;
-	GValue               value;
+	GValue               value = { 0, };
 	Bonobo_Unknown       ret;
 
 	g_return_val_if_fail (BONOBO_IS_MONIKER_SIMPLE (moniker),
@@ -104,7 +104,7 @@
 	g_return_val_if_fail (resolve_closure != NULL, NULL);
 
 	moniker->priv->resolve_closure =
-		bonobo_closure_store (resolve_closure, bonobo_marshal_BOXED__POINTER_STRING_POINTER);
+		bonobo_closure_store (resolve_closure, bonobo_marshal_BOXED__POINTER_STRING_BOXED);
 	
 	return bonobo_moniker_construct (
 		BONOBO_MONIKER (moniker), name);
Index: bonobo/bonobo-types.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-types.c,v
retrieving revision 1.8
diff -u -u -r1.8 bonobo-types.c
--- bonobo/bonobo-types.c	2001/07/30 17:43:19	1.8
+++ bonobo/bonobo-types.c	2001/08/01 02:08:56
@@ -212,7 +212,6 @@
 }
 
 BONOBO_TYPE_CORBA_OBJECT_IMPL (corba_object, "CorbaObject", TC_CORBA_Object, FALSE);
-BONOBO_TYPE_CORBA_OBJECT_IMPL (corba_exception, "CorbaException", TC_CORBA_exception_type, FALSE);
 BONOBO_TYPE_CORBA_OBJECT_IMPL (unknown, "BonoboUnknown", TC_Bonobo_Unknown, TRUE);
 
 static gpointer
@@ -240,6 +239,61 @@
 	if (!type)
 		type = g_boxed_type_register_static ("BonoboCorbaAny", corba_any_init,
 						     corba_any_copy, corba_any_free, TRUE);
+	return type;
+}
+
+static gpointer
+CORBA_exception__freekids (gpointer mem, gpointer dat)
+{
+	CORBA_Environment *env;
+	env = mem;
+	CORBA_exception_free (env);
+	return env + 1;
+}
+
+static CORBA_Environment *
+CORBA_exception__alloc (void)
+{
+	CORBA_Environment *retval = ORBit_alloc (sizeof (CORBA_Environment), 1, 
+						 &CORBA_exception__freekids);
+	CORBA_exception_init (retval);
+	return retval;
+}
+
+static gpointer
+corba_exception_init (void)
+{
+	return CORBA_exception__alloc ();
+}
+
+static gpointer
+corba_exception_copy (gpointer any)
+{
+	CORBA_Environment *src, *dest;
+
+	src = any;
+	dest = CORBA_exception__alloc ();
+	if (src->_major != CORBA_NO_EXCEPTION) {
+	    *dest = *src;
+	    CORBA_any__copy (&dest->_any, &src->_any);
+	}
+
+	return dest;
+}
+
+static void
+corba_exception_free (gpointer env)
+{
+	CORBA_free (env);
+}
+
+GType
+bonobo_corba_exception_get_type (void)
+{
+	static GType type = 0;
+	if (!type)
+		type = g_boxed_type_register_static ("BonoboCorbaException", corba_exception_init,
+						     corba_exception_copy, corba_exception_free, TRUE);
 	return type;
 }
 

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)


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