Mercurial > emacs
diff src/gtkutil.c @ 109748:e2f8226efb99
Fix -Wwrite_strings in general and for Gtk+ specific code.
* callproc.c (synch_process_death): Make const.
(Fcall_process): Make signame const.
* emacs.c (main): Pass char[] to putenv instead of literal.
* floatfns.c (matherr): Use a const char* variable for x->name.
* font.c (font_open_by_name): Make name const.
* font.h (font_open_by_name): Make name const.
* gtkutil.c (get_utf8_string): Always return an allocated string.
Parameter is const.
(create_dialog, xg_create_one_menuitem, create_menus)
(xg_item_label_same_p, xg_update_menu_item): Free result from
get_utf8_string.
(xg_separator_p, xg_item_label_same_p): label is const.
* gtkutil.h: Replace widget_value with struct _widget_value.
(enum button_type, struct _widget_value): Remove and use the one from
keyboard.h.
* keyboard.h (_widget_value): Add defined USE_GTK. Replace Boolean
with unsigned char and XtPointer with void *.
* menu.c (Fx_popup_menu): error_name is const.
* menu.h (w32_menu_show, ns_menu_show, xmenu_show): error parameter
is const char **.
* w32menu.c (w32_menu_show):
* nsmenu.m (ns_menu_show): error parameter is const char **.
* process.h (synch_process_death): Is const char*.
* xmenu.c (Fx_popup_dialog): error_name is const char*.
(xmenu_show): error parameter is const char **. pane_string is const
char *.
(button_names): Is const char *.
(xdialog_show): error_name and pane_string is const.
* xrdb.c (get_system_app): Make path const and use char *p for non-const
char.
* xselect.c (Fx_get_atom_name): Use char empty[] instead of literal "".
* xsmfns.c (NOSPLASH_OPT): Change to char[].
(smc_save_yourself_CB): Do xstrdup on all ->type and ->name for
props. Free them at the end.
* xterm.c (emacs_class): New char[] for EMACS_CLASS.
(xim_open_dpy, xim_initialize, xim_close_dpy): Use emacs_class.
(x_term_init): Use char[] display_opt and name_opt instead of
string literal. file is const char*.
author | Jan D <jan.h.d@swipnet.se> |
---|---|
date | Wed, 11 Aug 2010 14:34:46 +0200 |
parents | 64732fa6188a |
children | be18c3b67d66 |
line wrap: on
line diff
--- a/src/gtkutil.c Wed Aug 11 11:16:35 2010 +0200 +++ b/src/gtkutil.c Wed Aug 11 14:34:46 2010 +0200 @@ -432,20 +432,22 @@ } /* Allocate and return a utf8 version of STR. If STR is already - utf8 or NULL, just return STR. - If not, a new string is allocated and the caller must free the result + utf8 or NULL, just return a copy of STR. + A new string is allocated and the caller must free the result with g_free. */ static char * -get_utf8_string (char *str) +get_utf8_string (const char *str) { - char *utf8_str = str; + char *utf8_str; if (!str) return NULL; /* If not UTF-8, try current locale. */ if (!g_utf8_validate (str, -1, NULL)) utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0); + else + return g_strdup (str); if (!utf8_str) { @@ -1336,7 +1338,7 @@ } } - if (utf8_label && utf8_label != item->value) + if (utf8_label) g_free (utf8_label); } @@ -2076,7 +2078,7 @@ }; static int -xg_separator_p (char *label) +xg_separator_p (const char *label) { if (! label) return 0; else if (strlen (label) > 3 @@ -2174,8 +2176,8 @@ w = make_menu_item (utf8_label, utf8_key, item, group); - if (utf8_label && utf8_label != item->name) g_free (utf8_label); - if (utf8_key && utf8_key != item->key) g_free (utf8_key); + if (utf8_label) g_free (utf8_label); + if (utf8_key) g_free (utf8_key); cb_data = xmalloc (sizeof (xg_menu_item_cb_data)); @@ -2311,7 +2313,7 @@ gtk_menu_set_title (GTK_MENU (wmenu), utf8_label); w = gtk_menu_item_new_with_label (utf8_label); gtk_widget_set_sensitive (w, FALSE); - if (utf8_label && utf8_label != item->name) g_free (utf8_label); + if (utf8_label) g_free (utf8_label); } else if (xg_separator_p (item->name)) { @@ -2432,7 +2434,7 @@ /* Return non-zero if the menu item WITEM has the text LABEL. */ static int -xg_item_label_same_p (GtkMenuItem *witem, char *label) +xg_item_label_same_p (GtkMenuItem *witem, const char *label) { int is_same = 0; char *utf8_label = get_utf8_string (label); @@ -2443,7 +2445,7 @@ else if (old_label && utf8_label) is_same = strcmp (utf8_label, old_label) == 0; - if (utf8_label && utf8_label != label) g_free (utf8_label); + if (utf8_label) g_free (utf8_label); return is_same; } @@ -2590,6 +2592,7 @@ /* Set the title of the detached window. */ gtk_menu_set_title (GTK_MENU (submenu), utf8_label); + if (utf8_label) g_free (utf8_label); iter = g_list_next (iter); val = val->next; ++pos; @@ -2729,8 +2732,8 @@ if (! old_label || strcmp (utf8_label, old_label) != 0) gtk_label_set_text (wlbl, utf8_label); - if (utf8_key && utf8_key != val->key) g_free (utf8_key); - if (utf8_label && utf8_label != val->name) g_free (utf8_label); + if (utf8_key) g_free (utf8_key); + if (utf8_label) g_free (utf8_label); if (! val->enabled && gtk_widget_get_sensitive (w)) gtk_widget_set_sensitive (w, FALSE);