Commit a3745011 authored by Kalev Lember's avatar Kalev Lember

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 e9f182e3
that caused GtkComboBoxText <items> from GtkBuilder to show up empty if
no translations are available.

https://bugzilla.gnome.org/show_bug.cgi?id=700629
parent 6b633480
......@@ -1128,16 +1128,16 @@ end_element (GMarkupParseContext *context,
if (prop_info->translatable && prop_info->text->len)
{
prop_info->data = g_strdup (_gtk_builder_parser_translate (data->domain,
prop_info->context,
prop_info->text->str));
g_string_free (prop_info->text, TRUE);
}
else
{
prop_info->data = g_string_free (prop_info->text, FALSE);
const gchar *translated;
translated = _gtk_builder_parser_translate (data->domain,
prop_info->context,
prop_info->text->str);
g_string_assign (prop_info->text, translated);
}
prop_info->data = g_string_free (prop_info->text, FALSE);
object_info->properties =
g_slist_prepend (object_info->properties, prop_info);
}
......
......@@ -820,8 +820,7 @@ cell_packing_end_element (GMarkupParseContext *context,
translated = _gtk_builder_parser_translate (domain,
parser_data->context,
parser_data->string->str);
g_string_set_size (parser_data->string, 0);
g_string_append (parser_data->string, translated);
g_string_assign (parser_data->string, translated);
}
if (parser_data->cell_prop_name)
......
......@@ -240,8 +240,7 @@ item_end_element (GMarkupParseContext *context,
translated = _gtk_builder_parser_translate (data->domain,
data->context,
data->string->str);
g_string_set_size (data->string, 0);
g_string_append (data->string, translated);
g_string_assign (data->string, translated);
}
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->object), data->id, data->string->str);
......
......@@ -667,17 +667,15 @@ attributes_end_element (GMarkupParseContext *context,
/* translate the string */
if (parser_data->string->len && parser_data->translatable)
{
gchar *translated;
const gchar *translated;
const gchar *domain;
domain = gtk_builder_get_translation_domain (parser_data->builder);
translated = g_strdup (_gtk_builder_parser_translate (domain,
parser_data->context,
parser_data->string->str));
g_string_set_size (parser_data->string, 0);
g_string_append (parser_data->string, translated);
g_free (translated);
translated = _gtk_builder_parser_translate (domain,
parser_data->context,
parser_data->string->str);
g_string_assign (parser_data->string, translated);
}
if (parser_data->child_prop_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment