Commit Graph

191 Commits

Author SHA1 Message Date
Matthias Clasen
adf892e96a Annotate all examples with their language
The C ones, at least.
2014-02-01 15:11:49 -05:00
Matthias Clasen
17f51583a8 Docs: Convert examples to |[ ]| 2014-01-31 21:56:33 -05:00
Matthias Clasen
4d12e0d66f Docs: Don't use the emphasis tag
Most of the time, the text read just as well without the extra
boldness.
2014-01-31 20:34:33 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
3d42934b71 Docs: don't use the structname tag
Just avoid explicit docbook markup.
2014-01-31 00:29:14 -05:00
Matthias Clasen
6f3c465535 Docs: don't use structfield tags
They don't add anything over @foo, and we want to avoid explicit
docbook markup as far as possible.
2014-01-30 23:59:06 -05:00
Dan Winship
6e4a7fca43 Require C90 compliance
Assume all supported platforms implement C90, and therefore they
(correctly) implement atexit(), memmove(), setlocale(), strerror(),
and vprintf(), and have <float.h> and <limits.h>.

(Also remove the configure check testing that "do ... while (0)" works
correctly; the non-do/while-based version of G_STMT_START and
G_STMT_END was removed years ago, but the check remained. Also, remove
some checks that configure.ac claimed were needed for libcharset, but
aren't actually used.)

Note that removing the g_memmove() function is not an ABI break even
on systems where g_memmove() was previously not a macro, because it
was never marked GLIB_AVAILABLE_IN_ALL or listed in glib.symbols, so
it would have been glib-internal since 2004.

https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-11-20 09:16:16 -05:00
Dan Winship
34e1a53795 gtype: fix a no-op assertion
g_type_class_add_private() was doing

    g_assert (node->data->instance.private_size <= 0xffff);

but that field is a guint16, so the check was a no-op. (Noticed by
clang, but not gcc for some reason.) Fix it to do the math in a gssize
variable and do the bounds checking there before updating the struct
field.

https://bugzilla.gnome.org/show_bug.cgi?id=706888
2013-08-27 09:42:14 -04:00
Emanuele Aina
66233f1d1b gtype: Fix typo in g_type_class_add_private() error message
https://bugzilla.gnome.org/show_bug.cgi?id=705398
2013-08-04 08:15:30 +02:00
Emmanuele Bassi
d3dec6ec80 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
2013-06-24 14:18:01 +01:00
Ryan Lortie
a8a9afe17c GObject: prevent installing properties after init
GObject has previously allowed installing properties after class_init
has finished running.  This means that you could install some of your
own properties on G_TYPE_OBJECT, for example, although they wouldn't
have worked properly.

A previous patch asserted that this was not true and we had to revert it
because it broke the shell.  Instead of reverting, we should have used a
critical, so do that now.

Complaints go to this bug:

https://bugzilla.gnome.org/show_bug.cgi?id=698614
2013-05-29 09:25:25 -04:00
Matthias Clasen
2afd39a90d Trivial doc typo fix 2013-05-29 08:38:03 -04:00
Dan Winship
4b94c0831e Use 'dumb quotes' rather than `really dumb quotes'
Back in the far-off twentieth century, it was normal on unix
workstations for U+0060 GRAVE ACCENT to be drawn as "‛" and for U+0027
APOSTROPHE to be drawn as "’". This led to the convention of using
them as poor-man's ‛smart quotes’ in ASCII-only text.

However, "'" is now universally drawn as a vertical line, and "`" at a
45-degree angle, making them an `odd couple' when used together.

Unfortunately, there are lots of very old strings in glib, and also
lots of new strings in which people have kept up the old tradition,
perhaps entirely unaware that it used to not look stupid.

Fix this by just using 'dumb quotes' everywhere.

https://bugzilla.gnome.org/show_bug.cgi?id=700746
2013-05-21 11:23:22 -03:00
Ryan Lortie
c30c0bb34d GType: add accessor for instance private offset
Since instance private data is now always at a constant offset to the
instance pointer, we can add an accessor for it that doesn't also
require an instance.

The idea is that classes can call this from their class_init and store
it in a file-scoped static variable and use that to find their private
data on instances very quickly, without a priv pointer.

https://bugzilla.gnome.org/show_bug.cgi?id=698056
2013-04-23 14:39:09 -04:00
Ryan Lortie
7409ac0d14 gtype: tweak valgrind hints
The valgrind client requests were not producing the intended result in
some cases, so step up our game a bit.
2013-04-23 12:01:17 -04:00
Ryan Lortie
e8438f98e2 Revert "GObject: prevent installing properties after init"
This reverts commit ddb0ce1421.

Colin's smoke testing has found issues in at least gjs and
gnome-settings-daemon.  We'll need to see if we can address those.
2013-04-22 18:32:49 -04:00
Ryan Lortie
ddb0ce1421 GObject: prevent installing properties after init
GObject has previously allowed installing properties after class_init
has finished running.  This means that you could install some of your
own properties on G_TYPE_OBJECT, for example, although they wouldn't
have worked properly.

Prevent this from happening.  Require that all properties are installed by
the time class_init has finished.

Complaints go to this bug:

https://bugzilla.gnome.org/show_bug.cgi?id=698614
2013-04-22 17:40:51 -04:00
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
Ryan Lortie
96f7e6d70b gtype: interface-after-init exception for gtk#
gtk# also has a problem with the new interface-after-init restriction
that nobody noticed until now.  Add an exception for them as well so
that they have a cycle or so to sort things out.

https://bugzilla.gnome.org/show_bug.cgi?id=687659
2013-04-04 11:41:19 -04:00
Ryan Lortie
c5307e4cba gtype: interface-after-init exception for glibmm
glibmm has a pretty difficult-to-solve problem caused by our recent
change to deny addition of interfaces to classes after initialisation.

They're looking for a long-term workaround for the problem, but in the
meantime we can allow the registration to succeed (with warning) if the
class looks like it's being defined by gtkmm.

https://bugzilla.gnome.org/show_bug.cgi?id=697229
2013-04-04 11:10:17 -04:00
Ryan Lortie
72df62600d disable support for unloading of dynamic types
Experimentally disable the ability to unload dynamic types by refusing
to drop the last reference on types (effectively turning the type
unloading into dead code).

The plan is to leave things like this for a stable cycle and only
proceed with removing the code if we are sure that there are no
unforeseen problems.

https://bugzilla.gnome.org/show_bug.cgi?id=693351
2013-02-07 14:15:45 -05:00
Ryan Lortie
c2055f22f4 gtype: disallow adding interfaces after the fact
Add a check to prevent adding an interface to a class that has already
had its class_init done.

This is an incompatible change but it is suspected that there are not
many users of this functionality.  Two known exceptions are pygobject
(fixed in bug 686149) and our own testsuite (affected tests have been
temporarily disabled by this patch).

Once we confirm that nobody else is using this functionality we can
remove a rather large amount of code for dealing with this case.

https://bugzilla.gnome.org/show_bug.cgi?id=687659
2013-01-04 21:20:04 +01:00
Rico Tzschichholz
efa7b5f1e7 Revert "gtype: disallow adding interfaces after the fact"
This reverts commit d6a075b0d8.
2013-01-04 20:25:46 +01:00
Matthias Clasen
f2e00a07f4 Improvde #include order consistency
This was mostly fixed already, just re-fix a few details here.
https://bugzilla.gnome.org/show_bug.cgi?id=71704
2013-01-01 13:54:54 -05:00
Ryan Lortie
5df1edaf70 gtype: disallow adding interfaces after the fact
Add a check to prevent adding an interface to a class that has already
had its class_init done.

This is an incompatible change but it is suspected that there are not
many users of this functionality.  Two known exceptions are pygobject
(fixed in bug 686149) and our own testsuite (affected tests have been
temporarily disabled by this patch).

Once we confirm that nobody else is using this functionality we can
remove a rather large amount of code for dealing with this case.

https://bugzilla.gnome.org/show_bug.cgi?id=687659
2012-12-18 21:37:07 +01:00
Rico Tzschichholz
d1ab41c940 Revert "gtype: disallow adding interfaces after the fact"
This reverts commit d6a075b0d8.
2012-12-18 21:23:13 +01:00
Christophe Fergeau
b055c82815 Fix g_type_add_class_private() name in g_warning
When g_type_class_get_private is called without calling
g_type_add_class_private first, a g_warning is issued, but
the name of the function to call is wrong:
g_type_class_add_class_private.

https://bugzilla.gnome.org/show_bug.cgi?id=690348
2012-12-17 15:51:07 +01:00
Alexander Larsson
e218b96a6b Add g_type_get_type_registration_serial()
This lets you cache type lookup information and then know when
the cache information is out of date. In particular, we want this
in order to be able to cache g_type_from_name() lookups in the Gtk+
theme machinery.

https://bugzilla.gnome.org/show_bug.cgi?id=689847
2012-12-10 12:55:28 +01:00
Paul Menzel
834e6e96b3 docs: Fix spelling of "exceed" in gobject/gtype.c
https://bugzilla.gnome.org/show_bug.cgi?id=688338
2012-11-16 08:44:23 +00:00
Ryan Lortie
d6a075b0d8 gtype: disallow adding interfaces after the fact
Add a check to prevent adding an interface to a class that has already
had its class_init done.

This is an incompatible change but it is suspected that there are not
many users of this functionality.  Two known exceptions are pygobject
(fixed in bug 686149) and our own testsuite (affected tests have been
temporarily disabled by this patch).

Once we confirm that nobody else is using this functionality we can
remove a rather large amount of code for dealing with this case.

https://bugzilla.gnome.org/show_bug.cgi?id=687659
2012-11-05 13:20:28 -05:00
Ryan Lortie
df02fa1e4c Properly deprecate g_type_init()
Now that all internal users of it are gone.

https://bugzilla.gnome.org/show_bug.cgi?id=686161
2012-10-16 09:39:24 -04:00
Ryan Lortie
7c42ab23b5 Convert g_type_init() to a ctor
Move the guts of g_type_init() into a ctor and turn g_type_init() itself
into a do-nothing function.

g_type_init_with_debug_flags() now ignores its arguments, but it has
always been possible to achieve the same effect via environment
variables.

https://bugzilla.gnome.org/show_bug.cgi?id=686161
2012-10-16 09:39:24 -04:00
Matthias Clasen
26ecc52073 Clarify g_type_init docs
Mention that there's no way to undo it.
https://bugzilla.gnome.org/show_bug.cgi?id=654239
2012-09-23 11:13:57 -04:00
Stefan Sauer
6c1276eb5f gtype: make these cases fatal.
Otherwise we crash with a null-ptr deref in g_object_newv and ever there we
should not return null, as we're saying that object creation will not return
null.
2012-06-12 20:45:29 +02:00
Dan Winship
e011d2c921 Add g_type_ensure() and use it rather than playing games with volatile
https://bugzilla.gnome.org/show_bug.cgi?id=605976
2012-05-15 13:46:38 -04:00
Dieter Verfaillie
0183c1f8a1 Fix malformed GTK-Doc comment blocks: invalid parameters and tags.
Found these thanks to the improved gobject-introspection
GTK-Doc comment block/annotation parser.
See https://bugzilla.gnome.org/show_bug.cgi?id=672254

https://bugzilla.gnome.org/show_bug.cgi?id=673385
2012-04-05 10:23:42 -03:00
Colin Walters
cf912785b6 gtype: Note idempotency of g_type_init() 2012-03-16 11:49:30 -04:00
Christian Dywan
cb0566eaf3 gobject/gtype.c: Emphasize use of priv in member and use g_return_val_if_fail
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=597785

Signed-off-by: Javier Jardón <jjardon@gnome.org>
2012-03-01 21:40:35 +00:00
David King
500aafd099 docs: Clarify g_type_register_fundamental() behaviour
https://bugzilla.gnome.org/show_bug.cgi?id=580873
2012-02-26 22:21:19 -05:00
Matthias Clasen
599f254066 Cleanups to debug env var handling 2011-11-12 19:13:44 -05:00
Simon McVittie
5dcc502f91 Document that types are limited to 64 KiB
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=659916
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2011-10-15 17:59:35 -04:00
Ryan Lortie
47444dacc0 Deprecate g_thread_init()
Move the last few things that needed thread-safe initialisation to a
global ctor.

https://bugzilla.gnome.org/show_bug.cgi?id=660744
2011-10-04 15:31:49 -04:00
Simon McVittie
5bed8317ea Warn when classes/instances exceed the allowed size, if possible
It's impossible to check this if the library user is using
g_type_register_static, but in that case their compiler should hopefully
warn about the truncation. This fixes it for G_DEFINE_TYPE and friends,
at least.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=659916
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
2011-10-04 09:35:54 +01:00
Ryan Lortie
2a677d1370 locks: drop _INIT macros
All locks are now zero-initialised, so we can drop the G_*_INIT macros
for them.

Adjust various users around GLib accordingly and change the docs.

https://bugzilla.gnome.org/show_bug.cgi?id=659866
2011-10-02 22:33:10 -04:00
Ryan Lortie
aecec33c49 gtype: port from GStaticRWLock to GRWLock 2011-09-21 16:09:05 -04:00
Ryan Lortie
b6140c2f89 Port internal GStaticRecMutex users to GRecMutex 2011-09-21 16:09:04 -04:00
Dan Winship
5bc7729d16 Make threads mandatory
G_THREADS_ENABLED still exists, but is always defined. It is still
possible to use libglib without threads, but gobject (and everything
above it) is now guaranteed to be using threads (as, in fact, it was
before, since it was accidentally impossible to compile with
--disable-threads).

https://bugzilla.gnome.org/show_bug.cgi?id=616754
2011-09-09 12:41:55 -04:00
Ryan Lortie
9829d04be8 GObject docs: resolve broken links
Some links were broken due to typos, because functionality was removed
in GLib 2.0 or for various other reasons.  Fix up as many of them as is
reasonable.
2011-09-05 18:46:59 -04:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Ryan Lortie
8073759f8c Remove all uses of G_CONST_RETURN
Just use 'const'.

https://bugzilla.gnome.org/show_bug.cgi?id=644611
2011-06-09 11:15:40 -04:00