[Vala] Vala Switch Statements with Constant Strings



Hi,

I believe I have found a edge case which causes GCC to emit a warning from the vala compiled code. Specifically it involves the switch statement when comparing constant strings.

It would appear the solution is just adding a simple cast to _tmp0 = type_table_name to _tmp0 = (char *)type_table_name

Just a small detail!

Thanks for the great project!

- Dan Saul

GCC Warning: 

SidebarList.c:514: warning: assignment discards qualifiers from pointer target type

Original Vala source:

private void setup_load_sidebar_database_specified(int64 id, int64 type_id, int64 type_table_id,string type_table_name)
{
switch (type_table_name)
{
case "folders":
{
setup_load_sidebar_database_specified_folder(id,type_id,type_table_id,type_table_name);
break;
}
case "separators":
{
setup_load_sidebar_database_specified_separator(id,type_id,type_table_id,type_table_name);
break;
}
default:
{
stdout.printf("unhandled type type_table_name '%s'\n",type_table_name);
stdout.flush();
break;
}
}
}

Expanded C Source:

static void file_browser_sidebar_list_setup_load_sidebar_database_specified (FileBrowserSidebarList* self, gint64 id, gint64 type_id, gint64 type_table_id, const char* type_table_name) {
GQuark _tmp1;
char* _tmp0;
g_return_if_fail (self != NULL);
g_return_if_fail (type_table_name != NULL);
_tmp0 = NULL;
static GQuark _tmp1_label0 = 0;
static GQuark _tmp1_label1 = 0;
_tmp0 = type_table_name; # Line 514
_tmp1 = (NULL == _tmp0 ? 0 : g_quark_from_string (_tmp0));
if (_tmp1 == (0 != _tmp1_label0 ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("folders"))))
do {
{
file_browser_sidebar_list_setup_load_sidebar_database_specified_folder (self, id, type_id, type_table_id, type_table_name);
break;
}
} while (0); else if (_tmp1 == (0 != _tmp1_label1 ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("separators"))))
do {
{
file_browser_sidebar_list_setup_load_sidebar_database_specified_separator (self, id, type_id, type_table_id, type_table_name);
break;
}
} while (0); else
do {
{
fprintf (stdout, "unhandled type type_table_name '%s'\n", type_table_name);
fflush (stdout);
break;
}
} while (0);
}


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