glib/gobject
Ryan Lortie 31fde567a9 gtype: put private data before the instance
Classically, a GTypeInstance has had the following layout:

 [[[[GTypeInstance] GObject] TypeA] TypeB] [TypeAPrivate] [TypeBPrivate]

where TypeB is a subclass of TypeA which is a GObject.  Both TypeA and
TypeB use pivate data.

The main problem with this approach is that the offset between a pointer
to an instance of TypeA and the TypeAPrivate is not constant: it changes
depending on the depth of derivation and the size of the instance
structures of the derived types.  For example, changing the size of the
TypeB structure in the above example would push the TypeAPrivate further
along.

This complicates the implementation of g_type_instance_get_private().
In particular, during object construction when the class pointer to the
'complete type' of the object is not yet stored in the header of the
GTypeInstance, we need a lookup table in order to be able to implement
g_type_instance_get_private() accurately.

We can avoid this problem by storing the private data before the
structures, in reverse order, like so:

  [TypeBPrivate] [TypeAPrivate] [[[[GTypeInstance] GObject] TypeA] TypeB]

Now the distance between TypeA and TypeAPrivate depends only on the size
of GObject and GTypeInstance, which are static.  Even in the case of
TypeB, the distance is not statically known but can be determined at
runtime and is constant (because we will know the size of TypeAPrivate
by the time we initialise TypeB and it won't change).

This approach requires a slighty dirty trick: allocating extra memory
_before_ the pointer we return from g_type_create_instance().  The main
problem with this is that it will cause valgrind to behave very badly,
reporting almost everything as "possibly lost".

We can correct for this by including a few valgrind client requests in
order to inform it that the start of the GTypeInstance should be
considered a block of memory and that pointers to it should mean that
this block is reachable.  In order to make the private data reachable,
we also declare it as a block and include an extra pointer from the end
of the primary block pointing back at it.  All of this is only done if
we are running under Valgrind.

https://bugzilla.gnome.org/show_bug.cgi?id=698595
2013-04-22 16:16:23 -04:00
..
tests build: Add --disable-compile-warnings 2013-02-27 08:34:01 -05:00
.gitignore Stop using glib-genmarshal at build time 2011-06-20 17:24:07 -04:00
ChangeLog Update README files to refer to git 2009-03-31 19:39:16 -04:00
gatomicarray.c Improvde #include order consistency 2013-01-01 13:54:54 -05:00
gatomicarray.h Move single-include guards inside include guards 2012-12-27 23:43:14 -05:00
gbinding.c Fix binding properties of the same object 2012-03-04 20:49:04 -05:00
gbinding.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gboxed.c gmarkup: Make GMarkupParseContext a boxed type 2013-01-01 11:03:19 -05:00
gboxed.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gclosure.c Improvde #include order consistency 2013-01-01 13:54:54 -05:00
gclosure.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
genums.c documentation fixes 2011-12-13 23:01:51 -05:00
genums.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
glib-genmarshal.c Revert "Improvde #include order consistency" 2013-01-15 19:35:52 +08:00
glib-mkenums.in glib-mkenums: fix handling of forward enum declarations 2012-02-07 13:32:22 -05:00
glib-types.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gmarshal.c Use G_VA_COPY instead of va_copy() 2012-03-08 14:51:22 +08:00
gmarshal.h gmarshal.h: replace "extern" with GLIB_AVAILABLE_IN_ALL 2013-01-13 13:13:55 -05:00
gmarshal.list Update the comment in gmarshal.list 2012-06-23 17:53:22 -04:00
gobject_probes.d Add missing semicolons to gobject_probes.d 2012-10-15 19:48:44 -04:00
gobject_trace.h Add dtrace and systemtap support for gobject 2010-05-27 14:51:41 -04:00
gobject-query.c Remove g_type_init() calls 2012-10-16 09:39:24 -04:00
gobject.c Doc: clarify a bit g_signal_connect_object() 2013-03-15 09:07:29 +01:00
gobject.h Doc: clarify set_property() vfunc 2013-03-15 09:07:30 +01:00
gobject.py Initial support for gdb python macros 2009-09-21 15:39:00 +02:00
gobject.rc.in Update the year in the *.rc.in files 2011-06-07 08:55:31 +08:00
gobject.stp.in Add dtrace and systemtap support for gobject 2010-05-27 14:51:41 -04:00
gobjectnotifyqueue.c [notify] add warning to gobjectnotifyqueue.c 2011-11-16 17:50:13 +00:00
gparam.c It is 'registered', not 'registred' 2012-08-18 23:17:47 -04:00
gparam.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gparamspecs.c GParamSpec: Make constructors introspectable 2013-01-14 11:36:14 +01:00
gparamspecs.h Add a new _GLIB_EXTERN macro for "extern" 2013-01-13 13:13:36 -05:00
gsignal.c gsignal: improve warning output 2013-02-22 00:54:50 +00:00
gsignal.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gsourceclosure.c Install an invalidation notifier for GClosure in g_source_set_closure() 2013-01-20 16:23:32 +01:00
gsourceclosure.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gtype-private.h Move single-include guards inside include guards 2012-12-27 23:43:14 -05:00
gtype.c gtype: put private data before the instance 2013-04-22 16:16:23 -04:00
gtype.h gobject: fix G_DEFINE_TYPE_EXTENDED docs so code snippet actually compiles 2013-04-04 12:11:06 +01:00
gtypemodule.c Do not use static GTypeInfo and GInterfaceInfo 2011-11-29 22:03:25 -05:00
gtypemodule.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gtypeplugin.c Do not use static GTypeInfo and GInterfaceInfo 2011-11-29 22:03:25 -05:00
gtypeplugin.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gvalue.c Remove g_type_init() calls 2012-10-16 09:39:24 -04:00
gvalue.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
gvaluearray.c Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS 2012-02-15 09:54:38 -05:00
gvaluearray.h GValueArray: clarify the deprecation warnings 2013-01-02 13:02:51 -05:00
gvaluecollector.h Constify collect and lcopy strings in GTypeValueTable 2012-07-05 23:27:35 -04:00
gvaluetransform.c valuetransform: Fix definition of ulong_bool 2012-06-27 10:59:29 +02:00
gvaluetypes.c values: Use v_pointer for g_value_set_gtype() 2012-01-14 01:15:16 +01:00
gvaluetypes.h various: add GLIB_AVAILABLE_IN_ALL everywhere else 2013-01-13 13:11:57 -05:00
libgobject-gdb.py.in Avoid shadowing the dir builtin 2010-12-03 14:08:36 -05:00
Makefile.am build: Add --disable-compile-warnings 2013-02-27 08:34:01 -05:00
makefile.msc.in gobject/: fully remove gobjectalias hacks 2010-07-07 19:40:48 -04:00
marshal-genstrings.pl Hacky script to fix up your .msc.in files on windows. Dunno if this is a 2001-08-04 15:49:55 +00:00