Allow registering instance private data during get_type()
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 9 May 2013 21:41:26 +0000 (14:41 -0700)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 24 Jun 2013 13:18:01 +0000 (14:18 +0100)
commitd3dec6ec80e9243bdc14d47f6e51c381eb46cda2
tree199c7cf976a696fc781a28231c70447611eac2aa
parentebdbbd9b62efa40542a467862a5401e0a8b4e07e
Allow registering instance private data during get_type()

For static types, it should be possible to register a private data
structure right when we are registering the type, i.e. from the
get_type() implementation. By allowing this, we can take advantage of
the existing type definition macros to cut down the amount of code
necessary (as well as the knowledge baggage) when creating a new type.

The main issue with this new feature is that it cannot be mixed with the
old idiomatic way of adding private instance data by calling a function
in the middle of the class_init() implementation, as that imposes the
additional constraint of initializing the whole type hierarchy in order
to retrieve the offset of the private data in the GTypeInstance
allocation.

For this reason we are going to follow a two-step process; in the first
step, we are going to introduce the new (semi-private) API to register
the intent to add private instance data from within the get_type()
implementation, and hide it behind a macro; at the same time, the
G_DEFINE_TYPE_EXTENDED macro is going to be modified so that it will
register the private instance data if the macro was used, using a new
(semi-private) function as well. Once we have migrated all our code, we
will make the first new function perform the actual private data
registration, and turn the second new function into a no-op. This should
guarantee a transparent migration of existing code to the new idiomatic
form.

https://bugzilla.gnome.org/show_bug.cgi?id=700035
gobject/gtype.c
gobject/gtype.h
gobject/tests/.gitignore
gobject/tests/Makefile.am
gobject/tests/private.c [new file with mode: 0644]