A general suggestion: when you have this kind of problems is much cleaner to wrap the GLib code with your own specialized functions and hide the implementation as much as you can, for example (untested):
// country.h: public interface
typedef struct _Country Country;
Country * country_new (void);
void country_town_add (Country * country,
const gchar * state,
const gchar * town);
...
// country.c: implementation
struct _Country {
GHashTable *states;
};
Country *
country_new(void)
{
Country *coutry = g_new(Country, 1);
country->states = g_hash_table_new(g_str_hash, g_str_equal);
return country;
}
void
country_town_add(Country *country, const gchar *state, const gchar *town)
{
GSList *towns = g_hash_table_lookup(country->states, state);
towns = g_slist_append(towns, town);
g_hash_table_insert(country->states, state, towns);
}
This has the huge advantage you can reimplement country.c
in whatever way you want, e.g. by using @pwithnall idea, without having to touch the code above it.