After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 526542 - Support nullable structs and boxed types
Support nullable structs and boxed types
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
0.1.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks: 530817
 
 
Reported: 2008-04-06 17:36 UTC by Jürg Billeter
Modified: 2008-09-29 18:51 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jürg Billeter 2008-04-06 17:36:51 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.
Comment 1 Jürg Billeter 2008-05-30 22:48:40 UTC
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.
Comment 2 Marc-Andre Lureau 2008-05-31 09:10:55 UTC
\o/