Fix string allocation handling with GtkBuilder translations

Use g_string_assign to avoid issues with assigning GString's internal
buffer back to the same string. This can happen when no translations are
available and _gtk_builder_parser_translate returns back the same
pointer that was passed in.

This fixes a regression from commit e9f182e37a
that caused GtkComboBoxText <items> from GtkBuilder to show up empty if
no translations are available.

https://bugzilla.gnome.org/show_bug.cgi?id=700629
This commit is contained in:
Kalev Lember 2013-06-07 14:12:14 +02:00
parent 6b63348037
commit a37450110b
4 changed files with 15 additions and 19 deletions

View File

@ -1128,16 +1128,16 @@ end_element (GMarkupParseContext *context,
if (prop_info->translatable && prop_info->text->len) if (prop_info->translatable && prop_info->text->len)
{ {
prop_info->data = g_strdup (_gtk_builder_parser_translate (data->domain, const gchar *translated;
prop_info->context,
prop_info->text->str)); translated = _gtk_builder_parser_translate (data->domain,
g_string_free (prop_info->text, TRUE); prop_info->context,
} prop_info->text->str);
else g_string_assign (prop_info->text, translated);
{
prop_info->data = g_string_free (prop_info->text, FALSE);
} }
prop_info->data = g_string_free (prop_info->text, FALSE);
object_info->properties = object_info->properties =
g_slist_prepend (object_info->properties, prop_info); g_slist_prepend (object_info->properties, prop_info);
} }

View File

@ -820,8 +820,7 @@ cell_packing_end_element (GMarkupParseContext *context,
translated = _gtk_builder_parser_translate (domain, translated = _gtk_builder_parser_translate (domain,
parser_data->context, parser_data->context,
parser_data->string->str); parser_data->string->str);
g_string_set_size (parser_data->string, 0); g_string_assign (parser_data->string, translated);
g_string_append (parser_data->string, translated);
} }
if (parser_data->cell_prop_name) if (parser_data->cell_prop_name)

View File

@ -240,8 +240,7 @@ item_end_element (GMarkupParseContext *context,
translated = _gtk_builder_parser_translate (data->domain, translated = _gtk_builder_parser_translate (data->domain,
data->context, data->context,
data->string->str); data->string->str);
g_string_set_size (data->string, 0); g_string_assign (data->string, translated);
g_string_append (data->string, translated);
} }
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->object), data->id, data->string->str); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->object), data->id, data->string->str);

View File

@ -667,17 +667,15 @@ attributes_end_element (GMarkupParseContext *context,
/* translate the string */ /* translate the string */
if (parser_data->string->len && parser_data->translatable) if (parser_data->string->len && parser_data->translatable)
{ {
gchar *translated; const gchar *translated;
const gchar *domain; const gchar *domain;
domain = gtk_builder_get_translation_domain (parser_data->builder); domain = gtk_builder_get_translation_domain (parser_data->builder);
translated = g_strdup (_gtk_builder_parser_translate (domain, translated = _gtk_builder_parser_translate (domain,
parser_data->context, parser_data->context,
parser_data->string->str)); parser_data->string->str);
g_string_set_size (parser_data->string, 0); g_string_assign (parser_data->string, translated);
g_string_append (parser_data->string, translated);
g_free (translated);
} }
if (parser_data->child_prop_name) if (parser_data->child_prop_name)