Generic arg being free'ed after use inside function it is passed to
Commit 63551aca broke treating primitives such as int
as generic types, by free'ing them inside a function they were passed to.
E.g:
string to_display_string<T>(T value) {
var type = typeof(T);
string? display = null;
if (typeof(T) == typeof(string)) {
display = "“%s”".printf((string) ((string?) value));
} else if (typeof(T) == typeof(int)) {
display = ((int) ((int?) value)).to_string();
}
return display;
}
Compiles to:
gchar*
to_display_string (GType t_type,
GBoxedCopyFunc t_dup_func,
GDestroyNotify t_destroy_func,
gconstpointer value)
{
GType type = 0UL;
gchar* display = NULL;
gchar* result = NULL;
type = t_type;
display = NULL;
if (t_type == G_TYPE_STRING) {
gchar* _tmp0_;
_tmp0_ = g_strdup_printf ("“%s”", (const gchar*) ((const gchar*) value));
_g_free0 (display);
display = _tmp0_;
} else {
if (t_type == G_TYPE_INT) {
gchar* _tmp1_;
_tmp1_ = g_strdup_printf ("%i", (gint) (*((gint*) value)));
_g_free0 (display);
display = _tmp1_;
_g_free0 (value);
}
}
result = display;
return result;
}
Note the bogus _g_free0 (value)
in the int
case, but not in the string
case.
I realising this trades off a lot of badness in using primitives as generics, but I don't think that free should be in there in any case.
Minimal-ish test case: primitive-generic-arg-freed.vala