gobject: Document that classes/objects/interfaces are zero-filled

On initialisation, GObject guarantees to zero-fill
class/object/interface structures. Document this so people don’t spend
forever writing:
    my_object->priv->some_member = NULL;
    my_object->priv->some_other_member = NULL;

https://bugzilla.gnome.org/show_bug.cgi?id=729167
This commit is contained in:
Philip Withnall
2014-04-29 08:47:14 +01:00
parent cb3f6f9547
commit 704852ff09
3 changed files with 22 additions and 5 deletions

View File

@@ -147,7 +147,9 @@ GType maman_bar_get_type (void);
macro with the G_DEFINE_TYPE_WITH_CODE() or the G_DEFINE_TYPE_EXTENDED()
macros. The private structure is then defined in the .c file,
and can be accessed using the <function>get_instance_private()</function>
function generated by the G_DEFINE_TYPE_* macros.
function generated by the G_DEFINE_TYPE_* macros. It is automatically
zero-filled on creation, so it is unnecessary to explicitly
initialize pointer members to NULL.
<programlisting>
struct _MamanBarPrivate
{
@@ -333,7 +335,8 @@ maman_bar_init (MamanBar *self)
{
self->priv = maman_bar_get_instance_private (self);
/* initialize all public and private members to reasonable default values. */
/* initialize all public and private members to reasonable default values.
* They are all automatically initialized to 0 to begin with. */
}
</programlisting>
</para>
@@ -574,7 +577,7 @@ maman_bar_do_action (MamanBar *self, /* parameters */)
implementation for this class method in the object's
<function>class_init</function> function: initialize the
klass-&gt;do_action field to a pointer to the actual implementation.
By default, class method that are not inherited are initialized to
By default, class methods that are not inherited are initialized to
NULL, and thus are to be considered "pure virtual".
<programlisting>
static void