diff --git a/gio/giomodule.c b/gio/giomodule.c index e27f1ab76..f20b64875 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -477,9 +477,7 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname, filename = g_build_filename (dirname, "giomodule.cache", NULL); - cache = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify)g_strfreev); - + cache = NULL; cache_time = 0; if (g_stat (filename, &statbuf) == 0 && g_file_get_contents (filename, &data, NULL, NULL)) @@ -523,6 +521,10 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname, while (g_ascii_isspace (*colon)) colon++; + if (G_UNLIKELY (!cache)) + cache = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify)g_strfreev); + extension_points = g_strsplit (colon, ",", -1); g_hash_table_insert (cache, file, extension_points); } @@ -536,13 +538,15 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname, GIOExtensionPoint *extension_point; GIOModule *module; gchar *path; - char **extension_points; + char **extension_points = NULL; int i; path = g_build_filename (dirname, name, NULL); module = g_io_module_new (path); - extension_points = g_hash_table_lookup (cache, name); + if (cache) + extension_points = g_hash_table_lookup (cache, name); + if (extension_points != NULL && g_stat (path, &statbuf) == 0 && statbuf.st_ctime <= cache_time) @@ -577,7 +581,8 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname, g_dir_close (dir); - g_hash_table_destroy (cache); + if (cache) + g_hash_table_destroy (cache); g_free (filename); } diff --git a/gio/gresource.c b/gio/gresource.c index b495d12ac..4c9652a94 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -929,9 +929,10 @@ g_resource_enumerate_children (GResource *resource, if (*path == 0) { - g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, - _("The resource at “%s” does not exist"), - path); + if (error) + g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, + _("The resource at “%s” does not exist"), + path); return NULL; } @@ -968,9 +969,10 @@ g_resource_enumerate_children (GResource *resource, if (children == NULL) { - g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, - _("The resource at “%s” does not exist"), - path); + if (error) + g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, + _("The resource at “%s” does not exist"), + path); return NULL; } @@ -1237,9 +1239,10 @@ g_resources_enumerate_children (const gchar *path, if (hash == NULL) { - g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, - _("The resource at “%s” does not exist"), - path); + if (error) + g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, + _("The resource at “%s” does not exist"), + path); return NULL; } else diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 16adc3ff7..a4e90265e 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -897,10 +897,12 @@ get_contents_posix (const gchar *filename, if (fd < 0) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to open file “%s”: %s"), - saved_errno); + + if (error) + set_file_error (error, + filename, + _("Failed to open file “%s”: %s"), + saved_errno); return FALSE; } @@ -909,10 +911,11 @@ get_contents_posix (const gchar *filename, if (fstat (fd, &stat_buf) < 0) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to get attributes of file “%s”: fstat() failed: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Failed to get attributes of file “%s”: fstat() failed: %s"), + saved_errno); close (fd); return FALSE; @@ -939,10 +942,11 @@ get_contents_posix (const gchar *filename, if (f == NULL) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to open file “%s”: fdopen() failed: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Failed to open file “%s”: fdopen() failed: %s"), + saved_errno); return FALSE; } @@ -969,10 +973,11 @@ get_contents_win32 (const gchar *filename, if (f == NULL) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to open file “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Failed to open file “%s”: %s"), + saved_errno); return FALSE; } @@ -1165,9 +1170,10 @@ write_to_file (const gchar *contents, if (saved_errno == EINTR) continue; - set_file_error (err, - dest_file, _("Failed to write file “%s”: write() failed: %s"), - saved_errno); + if (err) + set_file_error (err, + dest_file, _("Failed to write file “%s”: write() failed: %s"), + saved_errno); close (fd); return FALSE; @@ -1185,9 +1191,10 @@ write_to_file (const gchar *contents, if (do_fsync && g_fsync (fd) != 0) { int saved_errno = errno; - set_file_error (err, - dest_file, _("Failed to write file “%s”: fsync() failed: %s"), - saved_errno); + if (err) + set_file_error (err, + dest_file, _("Failed to write file “%s”: fsync() failed: %s"), + saved_errno); close (fd); return FALSE; @@ -1353,9 +1360,10 @@ g_file_set_contents_full (const gchar *filename, if (fd == -1) { int saved_errno = errno; - set_file_error (error, - tmp_filename, _("Failed to create file “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + tmp_filename, _("Failed to create file “%s”: %s"), + saved_errno); retval = FALSE; goto consistent_out; } @@ -1396,10 +1404,11 @@ g_file_set_contents_full (const gchar *filename, if (g_unlink (filename) == -1) { int saved_errno = errno; - set_file_error (error, - filename, - _("Existing file “%s” could not be removed: g_unlink() failed: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Existing file “%s” could not be removed: g_unlink() failed: %s"), + saved_errno); g_unlink (tmp_filename); retval = FALSE; goto consistent_out; @@ -1462,9 +1471,10 @@ consistent_out: mode, error); #endif /* O_NOFOLLOW */ - set_file_error (error, - filename, _("Failed to open file “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, _("Failed to open file “%s”: %s"), + saved_errno); return FALSE; } @@ -1764,10 +1774,11 @@ g_get_tmp_name (const gchar *tmpl, if (retval == -1) { int saved_errno = errno; - set_file_error (error, - fulltemplate, - _("Failed to create file “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + fulltemplate, + _("Failed to create file “%s”: %s"), + saved_errno); g_free (fulltemplate); return -1; } @@ -2301,10 +2312,11 @@ g_file_read_link (const gchar *filename, if (read_size < 0) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to read the symbolic link “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Failed to read the symbolic link “%s”: %s"), + saved_errno); g_free (buffer); return NULL; } @@ -2329,10 +2341,11 @@ g_file_read_link (const gchar *filename, if (read_size < 0) { int saved_errno = errno; - set_file_error (error, - filename, - _("Failed to read the symbolic link “%s”: %s"), - saved_errno); + if (error) + set_file_error (error, + filename, + _("Failed to read the symbolic link “%s”: %s"), + saved_errno); return NULL; } else if (read_size == 0) diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 8fc0322e8..cb442e98e 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -631,9 +631,9 @@ g_key_file_init (GKeyFile *key_file) { key_file->current_group = g_slice_new0 (GKeyFileGroup); key_file->groups = g_list_prepend (NULL, key_file->current_group); - key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal); + key_file->group_hash = NULL; key_file->start_group = NULL; - key_file->parse_buffer = g_string_sized_new (128); + key_file->parse_buffer = NULL; key_file->list_separator = ';'; key_file->flags = 0; } @@ -1473,6 +1473,9 @@ g_key_file_parse_data (GKeyFile *key_file, parse_error = NULL; + if (!key_file->parse_buffer) + key_file->parse_buffer = g_string_sized_new (128); + i = 0; while (i < length) { @@ -1529,6 +1532,9 @@ g_key_file_flush_parse_buffer (GKeyFile *key_file, g_return_if_fail (key_file != NULL); + if (!key_file->parse_buffer) + return; + file_error = NULL; if (key_file->parse_buffer->len > 0) @@ -3831,6 +3837,9 @@ g_key_file_add_group (GKeyFile *key_file, if (key_file->start_group == NULL) key_file->start_group = group; + if (!key_file->group_hash) + key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal); + g_hash_table_insert (key_file->group_hash, (gpointer)group->name, group); } @@ -3883,7 +3892,10 @@ g_key_file_remove_group_node (GKeyFile *key_file, group = (GKeyFileGroup *) group_node->data; if (group->name) - g_hash_table_remove (key_file->group_hash, group->name); + { + g_assert (key_file->group_hash); + g_hash_table_remove (key_file->group_hash, group->name); + } /* If the current group gets deleted make the current group the last * added group. @@ -4089,6 +4101,9 @@ static GKeyFileGroup * g_key_file_lookup_group (GKeyFile *key_file, const gchar *group_name) { + if (!key_file->group_hash) + return NULL; + return (GKeyFileGroup *)g_hash_table_lookup (key_file->group_hash, group_name); } diff --git a/gobject/gparam.c b/gobject/gparam.c index d4659beca..ef13f2a51 100644 --- a/gobject/gparam.c +++ b/gobject/gparam.c @@ -1203,52 +1203,30 @@ pspec_compare_id (gconstpointer a, return strcmp (pspec1->name, pspec2->name); } -static inline GSList* -pspec_list_remove_overridden_and_redirected (GSList *plist, - GHashTable *ht, - GType owner_type, - guint *n_p) +static inline gboolean +should_list_pspec (GParamSpec *pspec, + GType owner_type, + GHashTable *ht) { - GSList *rlist = NULL; + GParamSpec *found; - while (plist) + /* Remove paramspecs that are redirected, and also paramspecs + * that have are overridden by non-redirected properties. + * The idea is to get the single paramspec for each name that + * best corresponds to what the application sees. + */ + if (g_param_spec_get_redirect_target (pspec)) + return FALSE; + + found = param_spec_ht_lookup (ht, pspec->name, owner_type, TRUE); + if (found != pspec) { - GSList *tmp = plist->next; - GParamSpec *pspec = plist->data; - GParamSpec *found; - gboolean remove = FALSE; - - /* Remove paramspecs that are redirected, and also paramspecs - * that have are overridden by non-redirected properties. - * The idea is to get the single paramspec for each name that - * best corresponds to what the application sees. - */ - if (g_param_spec_get_redirect_target (pspec)) - remove = TRUE; - else - { - found = param_spec_ht_lookup (ht, pspec->name, owner_type, TRUE); - if (found != pspec) - { - GParamSpec *redirect = g_param_spec_get_redirect_target (found); - if (redirect != pspec) - remove = TRUE; - } - } - - if (remove) - { - g_slist_free_1 (plist); - } - else - { - plist->next = rlist; - rlist = plist; - *n_p += 1; - } - plist = tmp; + GParamSpec *redirect = g_param_spec_get_redirect_target (found); + if (redirect != pspec) + return FALSE; } - return rlist; + + return TRUE; } static void @@ -1260,18 +1238,23 @@ pool_depth_list (gpointer key, gpointer *data = user_data; GSList **slists = data[0]; GType owner_type = (GType) data[1]; + GHashTable *ht = data[2]; + int *count = data[3]; - if (g_type_is_a (owner_type, pspec->owner_type)) + if (g_type_is_a (owner_type, pspec->owner_type) && + should_list_pspec (pspec, owner_type, ht)) { if (G_TYPE_IS_INTERFACE (pspec->owner_type)) { slists[0] = g_slist_prepend (slists[0], pspec); + *count = *count + 1; } else { - guint d = g_type_depth (pspec->owner_type); + guint d = g_type_depth (pspec->owner_type); - slists[d - 1] = g_slist_prepend (slists[d - 1], pspec); + slists[d - 1] = g_slist_prepend (slists[d - 1], pspec); + *count = *count + 1; } } } @@ -1294,9 +1277,15 @@ pool_depth_list_for_interface (gpointer key, gpointer *data = user_data; GSList **slists = data[0]; GType owner_type = (GType) data[1]; + GHashTable *ht = data[2]; + int *count = data[3]; - if (pspec->owner_type == owner_type) - slists[0] = g_slist_prepend (slists[0], pspec); + if (pspec->owner_type == owner_type && + should_list_pspec (pspec, owner_type, ht)) + { + slists[0] = g_slist_prepend (slists[0], pspec); + *count = *count + 1; + } } /** @@ -1319,29 +1308,29 @@ g_param_spec_pool_list (GParamSpecPool *pool, { GParamSpec **pspecs, **p; GSList **slists, *node; - gpointer data[2]; + gpointer data[4]; guint d, i; + int n_pspecs = 0; g_return_val_if_fail (pool != NULL, NULL); g_return_val_if_fail (owner_type > 0, NULL); g_return_val_if_fail (n_pspecs_p != NULL, NULL); g_mutex_lock (&pool->mutex); - *n_pspecs_p = 0; d = g_type_depth (owner_type); slists = g_new0 (GSList*, d); data[0] = slists; data[1] = (gpointer) owner_type; + data[2] = pool->hash_table; + data[3] = &n_pspecs; g_hash_table_foreach (pool->hash_table, - G_TYPE_IS_INTERFACE (owner_type) ? - pool_depth_list_for_interface : - pool_depth_list, - &data); - - for (i = 0; i < d; i++) - slists[i] = pspec_list_remove_overridden_and_redirected (slists[i], pool->hash_table, owner_type, n_pspecs_p); - pspecs = g_new (GParamSpec*, *n_pspecs_p + 1); + G_TYPE_IS_INTERFACE (owner_type) ? + pool_depth_list_for_interface : + pool_depth_list, + &data); + + pspecs = g_new (GParamSpec*, n_pspecs + 1); p = pspecs; for (i = 0; i < d; i++) { @@ -1354,10 +1343,11 @@ g_param_spec_pool_list (GParamSpecPool *pool, g_free (slists); g_mutex_unlock (&pool->mutex); + *n_pspecs_p = n_pspecs; + return pspecs; } - /* --- auxiliary functions --- */ typedef struct {