Missing cast for g_value_set_pointer() on generic property value
@pwithnall
Submitted by Philip Withnall Link to original bug (#710863)
Description
If a generic class (with type parameter T
) has a property of type T
, the generated C code will use g_value_[get|set]_pointer()
for the property marshalling. However, it will pass the value from the property’s getter method (which has return type gconstpointer) into g_value_set_pointer()
, which takes a gpointer
. This means GCC will complain about discarding the const qualifier from the pointer because Vala is violating the C type system.
For example:
public abstract class Folks.AbstractFieldDetails<T> : Object
{
public virtual T @value
{
get { return this._value; }
construct set { this._value = value; }
}
}
generates the following:
static void _vala_folks_abstract_field_details_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
…
switch (property_id) {
case FOLKS_ABSTRACT_FIELD_DETAILS_VALUE:
g_value_set_pointer (value, folks_abstract_field_details_get_value (self));
break;
…
}
}
gconstpointer folks_abstract_field_details_get_value (FolksAbstractFieldDetails* self) {
g_return_val_if_fail (self != NULL, NULL);
return FOLKS_ABSTRACT_FIELD_DETAILS_GET_CLASS (self)->get_value (self);
}
This is with Vala 0.22.0.26-f79fe.
Edited by Rico Tzschichholz