[nautilus-actions] NASettings: fix segmentation fault when emitting a signal



commit 3d1bd5cb57c5c76fc11880af0ba69775a4234408
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Jan 31 22:40:16 2011 +0100

    NASettings: fix segmentation fault when emitting a signal

 ChangeLog                          |   11 +++
 src/api/na-boxed.h                 |    1 +
 src/core/na-boxed.c                |  151 +++++++++++++++++++++++++++++-------
 src/core/na-marshal                |    2 +
 src/core/na-settings.c             |   22 +++---
 src/nact/nact-preferences-editor.c |   17 ++---
 6 files changed, 155 insertions(+), 49 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 36ca885..67ce87e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-01-31 Pierre Wieser <pwieser trychlos org>
+
+	* src/api/na-boxed.h:
+	* src/core/na-boxed.c (na_boxed_dump): New function.
+
+	* src/core/na-settings.c (on_keyfile_changed_timeout): Fix segfault.
+
+	* src/nact/nact-preferences-editor.c (on_dialog_ok): Spare a function.
+
+	* src/core/na-marshal: New file.
+
 2011-01-28 Pierre Wieser <pwieser trychlos org>
 
 	* src/core/Makefile.am: Generate na_cclosure_masharl functions.
diff --git a/src/api/na-boxed.h b/src/api/na-boxed.h
index bcb40d7..edb1cd7 100644
--- a/src/api/na-boxed.h
+++ b/src/api/na-boxed.h
@@ -94,6 +94,7 @@ typedef struct _NABoxed NABoxed;
 
 int           na_boxed_compare                 ( const NABoxed *a, const NABoxed *b );
 NABoxed      *na_boxed_copy                    ( const NABoxed *value );
+void          na_boxed_dump                    ( const NABoxed *value );
 void          na_boxed_free                    ( NABoxed *value );
 NABoxed      *na_boxed_new_from_string         ( guint type, const gchar *string );
 NABoxed      *na_boxed_new_from_string_with_sep( guint type, const gchar *string, const gchar *sep );
diff --git a/src/core/na-boxed.c b/src/core/na-boxed.c
index 116f94f..cde7fbb 100644
--- a/src/core/na-boxed.c
+++ b/src/core/na-boxed.c
@@ -59,6 +59,7 @@ typedef struct {
 	const gchar *label;
 	int       ( *compare )        ( const NABoxed *, const NABoxed * );
 	void      ( *copy )           ( NABoxed *, const NABoxed * );
+	gchar   * ( *dump )           ( const NABoxed * );
 	void      ( *free )           ( NABoxed * );
 	void      ( *from_string )    ( NABoxed *, const gchar * );
 	void      ( *from_array )     ( NABoxed *, const gchar ** );
@@ -77,6 +78,7 @@ static const gchar    *get_type_label( guint type );
 
 static int      string_compare( const NABoxed *a, const NABoxed *b );
 static void     string_copy( NABoxed *dest, const NABoxed *src );
+static gchar   *string_dump( const NABoxed *boxed );
 static void     string_free( NABoxed *boxed );
 static void     string_from_string( NABoxed *boxed, const gchar *string );
 static gpointer string_get_pointer( const NABoxed *boxed );
@@ -84,6 +86,7 @@ static gchar   *string_get_string( const NABoxed *boxed );
 
 static int      string_list_compare( const NABoxed *a, const NABoxed *b );
 static void     string_list_copy( NABoxed *dest, const NABoxed *src );
+static gchar   *string_list_dump( const NABoxed *boxed );
 static void     string_list_free( NABoxed *boxed );
 static void     string_list_from_string( NABoxed *boxed, const gchar *string );
 static void     string_list_from_array( NABoxed *boxed, const gchar **array );
@@ -92,6 +95,7 @@ static GSList  *string_list_get_string_list( const NABoxed *boxed );
 
 static int      bool_compare( const NABoxed *a, const NABoxed *b );
 static void     bool_copy( NABoxed *dest, const NABoxed *src );
+static gchar   *bool_dump( const NABoxed *boxed );
 static void     bool_free( NABoxed *boxed );
 static void     bool_from_string( NABoxed *boxed, const gchar *string );
 static gboolean bool_get_bool( const NABoxed *boxed );
@@ -99,6 +103,7 @@ static gpointer bool_get_pointer( const NABoxed *boxed );
 
 static int      uint_compare( const NABoxed *a, const NABoxed *b );
 static void     uint_copy( NABoxed *dest, const NABoxed *src );
+static gchar   *uint_dump( const NABoxed *boxed );
 static void     uint_free( NABoxed *boxed );
 static void     uint_from_string( NABoxed *boxed, const gchar *string );
 static gpointer uint_get_pointer( const NABoxed *boxed );
@@ -106,6 +111,7 @@ static guint    uint_get_uint( const NABoxed *boxed );
 
 static int      uint_list_compare( const NABoxed *a, const NABoxed *b );
 static void     uint_list_copy( NABoxed *dest, const NABoxed *src );
+static gchar   *uint_list_dump( const NABoxed *boxed );
 static void     uint_list_free( NABoxed *boxed );
 static void     uint_list_from_string( NABoxed *boxed, const gchar *string );
 static void     uint_list_from_array( NABoxed *boxed, const gchar **array );
@@ -117,6 +123,7 @@ static BoxedDef st_boxed_def[] = {
 				"string",
 				string_compare,
 				string_copy,
+				string_dump,
 				string_free,
 				string_from_string,
 				NULL,
@@ -131,6 +138,7 @@ static BoxedDef st_boxed_def[] = {
 				"ascii strings list",
 				string_list_compare,
 				string_list_copy,
+				string_list_dump,
 				string_list_free,
 				string_list_from_string,
 				string_list_from_array,
@@ -145,6 +153,7 @@ static BoxedDef st_boxed_def[] = {
 				"boolean",
 				bool_compare,
 				bool_copy,
+				bool_dump,
 				bool_free,
 				bool_from_string,
 				NULL,
@@ -159,6 +168,7 @@ static BoxedDef st_boxed_def[] = {
 				"unsigned integer",
 				uint_compare,
 				uint_copy,
+				uint_dump,
 				uint_free,
 				uint_from_string,
 				NULL,
@@ -173,6 +183,7 @@ static BoxedDef st_boxed_def[] = {
 				"unsigned integers list",
 				uint_list_compare,
 				uint_list_copy,
+				uint_list_dump,
 				uint_list_free,
 				uint_list_from_string,
 				uint_list_from_array,
@@ -262,26 +273,34 @@ na_boxed_compare( const NABoxed *a, const NABoxed *b )
 
 	result = 0;
 
-	if( a->type != b->type ){
-		g_warning( "%s: unable to compare: a is of type '%s' while b is of type %s",
-				thisfn, get_type_label( a->type ), get_type_label( b->type ));
-
-	} else if( a->is_set && !b->is_set ){
-		result = 1;
+	if( a && b ){
+		if( a->type != b->type ){
+			g_warning( "%s: unable to compare: a is of type '%s' while b is of type %s",
+					thisfn, get_type_label( a->type ), get_type_label( b->type ));
+
+		} else if( a->is_set && !b->is_set ){
+			result = 1;
+
+		} else if( !a->is_set && b->is_set ){
+			result = -1;
+
+		} else if( a->is_set && b->is_set ){
+			def = get_boxed_def( a->type );
+			if( def ){
+				if( def->compare ){
+					result = ( *def->compare )( a, b );
+				} else {
+					g_warning( "%s: unable to compare: '%s' type does not provide 'compare' function",
+							thisfn, def->label );
+				}
+			}
+		}
 
-	} else if( !a->is_set && b->is_set ){
+	} else if( !a ){
 		result = -1;
 
-	} else if( a->is_set && b->is_set ){
-		def = get_boxed_def( a->type );
-		if( def ){
-			if( def->compare ){
-				result = ( *def->compare )( a, b );
-			} else {
-				g_warning( "%s: unable to compare: '%s' type does not provide 'compare' function",
-						thisfn, def->label );
-			}
-		}
+	} else if( !b ){
+		result = 1;
 	}
 
 	return( result );
@@ -304,18 +323,20 @@ na_boxed_copy( const NABoxed *boxed )
 	const BoxedDef *def;
 
 	dest = NULL;
-	def = get_boxed_def( boxed->type );
-	if( def ){
-		if( def->copy ){
-			dest = boxed_new();
-			dest->type = boxed->type;
-			dest->is_set = FALSE;
-			if( boxed->is_set ){
-				( *def->copy )( dest, boxed );
+	if( boxed ){
+		def = get_boxed_def( boxed->type );
+		if( def ){
+			if( def->copy ){
+				dest = boxed_new();
+				dest->type = boxed->type;
+				dest->is_set = FALSE;
+				if( boxed->is_set ){
+					( *def->copy )( dest, boxed );
+				}
+			} else {
+				g_warning( "%s: unable to copy: '%s' type does not provide 'copy' function",
+						thisfn, def->label );
 			}
-		} else {
-			g_warning( "%s: unable to copy: '%s' type does not provide 'copy' function",
-					thisfn, def->label );
 		}
 	}
 
@@ -323,6 +344,39 @@ na_boxed_copy( const NABoxed *boxed )
 }
 
 /**
+ * na_boxed_dump:
+ * @boxed: the #NABoxed box to be dumped.
+ *
+ * Dumps the @boxed box.
+ *
+ * Since: 3.1.0
+ */
+void
+na_boxed_dump( const NABoxed *boxed )
+{
+	static const gchar *thisfn = "na_boxed_dump";
+	const BoxedDef *def;
+	gchar *str;
+
+	if( boxed ){
+		def = get_boxed_def( boxed->type );
+		if( def ){
+			if( def->dump ){
+				str = ( boxed->is_set ) ?  ( *def->dump )( boxed ) : NULL;
+				g_debug( "%s: boxed=%p, type=%u, is_set=%s, value=%s",
+						thisfn, ( void * ) boxed, boxed->type, boxed->is_set ? "True":"False", str );
+				g_free( str );
+			} else {
+				g_warning( "%s: unable to dump: '%s' type does not provide 'dump' function",
+						thisfn, def->label );
+			}
+		}
+	} else {
+		g_debug( "%s: boxed=(null)", thisfn );
+	}
+}
+
+/**
  * na_boxed_free:
  * @boxed: the #NABoxed to be released.
  *
@@ -648,6 +702,12 @@ string_copy( NABoxed *dest, const NABoxed *src )
 	dest->is_set = TRUE;
 }
 
+static gchar *
+string_dump( const NABoxed *boxed )
+{
+	return( g_strdup( boxed->u.string ));
+}
+
 static void
 string_free( NABoxed *boxed )
 {
@@ -716,6 +776,12 @@ string_list_copy( NABoxed *dest, const NABoxed *src )
 	dest->is_set = TRUE;
 }
 
+static gchar *
+string_list_dump( const NABoxed *boxed )
+{
+	return( na_core_utils_slist_join_at_end( boxed->u.string_list, "," ));
+}
+
 static void
 string_list_free( NABoxed *boxed )
 {
@@ -783,6 +849,12 @@ bool_copy( NABoxed *dest, const NABoxed *src )
 	dest->is_set = TRUE;
 }
 
+static gchar *
+bool_dump( const NABoxed *boxed )
+{
+	return( g_strdup( boxed->u.boolean ? "True":"False" ));
+}
+
 static void
 bool_free( NABoxed *boxed )
 {
@@ -827,6 +899,12 @@ uint_copy( NABoxed *dest, const NABoxed *src )
 	dest->is_set = TRUE;
 }
 
+static gchar *
+uint_dump( const NABoxed *boxed )
+{
+	return( g_strdup_printf( "%u", boxed->u.uint ));
+}
+
 static void
 uint_free( NABoxed *boxed )
 {
@@ -898,6 +976,23 @@ uint_list_copy( NABoxed *dest, const NABoxed *src )
 	dest->is_set = TRUE;
 }
 
+static gchar *
+uint_list_dump( const NABoxed *boxed )
+{
+	GString *str;
+	GList *i;
+
+	str = g_string_new( "" );
+	for( i = boxed->u.uint_list ; i ; i = i->next ){
+		if( strlen( str->str )){
+			str = g_string_append( str, "," );
+		}
+		g_string_append_printf( str, "%u", ( guint ) i->data );
+	}
+
+	return( g_string_free( str, FALSE ));
+}
+
 static void
 uint_list_free( NABoxed *boxed )
 {
diff --git a/src/core/na-marshal b/src/core/na-marshal
new file mode 100644
index 0000000..97bc557
--- /dev/null
+++ b/src/core/na-marshal
@@ -0,0 +1,2 @@
+# settings-key-changed signal
+VOID:STRING,STRING,POINTER,BOOLEAN
diff --git a/src/core/na-settings.c b/src/core/na-settings.c
index 711d79a..3c57926 100644
--- a/src/core/na-settings.c
+++ b/src/core/na-settings.c
@@ -1144,7 +1144,7 @@ on_keyfile_changed_timeout( NASettings *settings )
 #endif
 
 	/* for each modification found,
-	 * - check consumers and triggers callback if apply
+	 * - check if a consumer has registered for this key, and triggers callback if apply
 	 * - send a notification message
 	 */
 	for( im = modifs ; im ; im = im->next ){
@@ -1162,25 +1162,29 @@ on_keyfile_changed_timeout( NASettings *settings )
 			}
 
 			if(( !group_prefix || g_str_has_prefix( changed->group, group_prefix )) && !strcmp( changed->def->key, key )){
-				( *( NASettingsKeyCallback ) consumer->callback )
-						( changed->group, changed->def->key,
-								na_boxed_get_pointer( changed->boxed ), changed->mandatory, consumer->user_data );
+				( *( NASettingsKeyCallback ) consumer->callback )(
+						changed->group,
+						changed->def->key,
+						na_boxed_get_pointer( changed->boxed ),
+						changed->mandatory,
+						consumer->user_data );
 			}
 
 			g_free( group_prefix );
 		}
 
-		/*g_debug( "%s: sending signal for group=%s, key=%s", thisfn, changed->group, changed->def->key );
+		g_debug( "%s: sending signal for group=%s, key=%s", thisfn, changed->group, changed->def->key );
 		g_signal_emit_by_name( settings,
 				SETTINGS_SIGNAL_KEY_CHANGED,
-				g_strdup( changed->group ),
-				g_strdup( changed->def->key ), na_boxed_copy( changed->boxed ), changed->mandatory );*/
+				changed->group, changed->def->key, changed->boxed, changed->mandatory );
 	}
 
+	g_debug( "%s: releasing content", thisfn );
 	g_list_foreach( settings->private->content, ( GFunc ) release_key_value, NULL );
 	g_list_free( settings->private->content );
 	settings->private->content = new_content;
 
+	g_debug( "%s: releasing modifs", thisfn );
 	g_list_foreach( modifs, ( GFunc ) release_key_value, NULL );
 	g_list_free( modifs );
 }
@@ -1189,9 +1193,7 @@ static void
 on_key_changed_final_handler( NASettings *settings, gchar *group, gchar *key, NABoxed *new_value, gboolean mandatory )
 {
 	g_debug( "na_settings_on_key_changed_final_handler: group=%s, key=%s", group, key );
-	g_free( group );
-	g_free( key );
-	na_boxed_free( new_value );
+	na_boxed_dump( new_value );
 }
 
 static KeyValue *
diff --git a/src/nact/nact-preferences-editor.c b/src/nact/nact-preferences-editor.c
index 8fba042..1de566e 100644
--- a/src/nact/nact-preferences-editor.c
+++ b/src/nact/nact-preferences-editor.c
@@ -136,8 +136,6 @@ static void     import_mode_on_noimport_toggled( GtkToggleButton *togglebutton,
 static void     import_mode_on_toggled( NactPreferencesEditor *editor, GtkToggleButton *togglebutton, GCallback cb, guint import_mode );
 static void     on_cancel_clicked( GtkButton *button, NactPreferencesEditor *editor );
 static void     on_ok_clicked( GtkButton *button, NactPreferencesEditor *editor );
-static void     save_preferences( NactPreferencesEditor *editor );
-
 static void     on_dialog_ok( BaseDialog *dialog );
 
 GType
@@ -922,14 +920,19 @@ on_ok_clicked( GtkButton *button, NactPreferencesEditor *editor )
 }
 
 static void
-save_preferences( NactPreferencesEditor *editor )
+on_dialog_ok( BaseDialog *dialog )
 {
+	NactPreferencesEditor *editor;
 	NactApplication *application;
 	NAUpdater *updater;
 	NASettings *settings;
 	GtkWidget *container;
 	NAExportFormat *export_format;
 
+	g_return_if_fail( NACT_IS_PREFERENCES_EDITOR( dialog ));
+
+	editor = NACT_PREFERENCES_EDITOR( dialog );
+
 	if( !editor->private->preferences_locked ){
 		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( editor )));
 		updater = nact_application_get_updater( application );
@@ -995,11 +998,3 @@ save_preferences( NactPreferencesEditor *editor )
 		nact_providers_list_save( BASE_WINDOW( editor ));
 	}
 }
-
-static void
-on_dialog_ok( BaseDialog *dialog )
-{
-	g_return_if_fail( NACT_IS_PREFERENCES_EDITOR( dialog ));
-
-	save_preferences( NACT_PREFERENCES_EDITOR( dialog ));
-}



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