GNOME Bugzilla – Bug 526542
Support nullable structs and boxed types
Last modified: 2008-09-29 18:51:48 UTC
We currently support nullable structs only when used in input parameters. We should add support for nullable structs when used in local variables, fields, and output parameters. A nullable struct should be equivalent to a boxed struct as non-null boxed struct types rarely make sense and boxing is a sensible implementation for nullable struct types. This means that nullable structs should be treated like heap-allocated structs. Instead of reference counting, values will always be duplicated when used in multiple locations, similar to strings. Generate for each struct the following C functions MyStruct *my_struct_dup (const MyStruct *my_struct) { return g_slice_dup (MyStruct, my_struct); } void my_struct_free (MyStruct *my_struct) { g_slice_free (MyStruct, my_struct); } and add a get_type method for GBoxed support. We can directly use g_slice_dup and g_slice_free as fallbacks for structs that don't provide their own dup and free functions. Nullable structs are implicitly convertible to the corresponding normal struct types (i.e. auto unboxing) and normal struct types are implicitly convertible to the corresponding nullable struct types (i.e. auto boxing). This makes it possible to easily use GLib.List<double?>, although less efficient than list types that support arbitrary structs without boxing.
2008-05-31 Jürg Billeter <j@bitron.ch> * gobject/valaccodegenerator.vala: * gobject/valaccodeinvocationexpressionbinding.vala: * gobject/valaccodememberaccessbinding.vala: Add basic support for nullable structs * tests/structs.vala: Test nullable struct parameters Fixed in r1502.
\o/