Commit Graph

155 Commits

Author SHA1 Message Date
Emmanuele Bassi
7e5db31d36 Deprecate g_type_class_add_private()
It's been 4 years and 8 development cycles since we introduced
G_ADD_PRIVATE and offset-based private data access. It is now
time to finally deprecate the old mechanism.

Closes: #699
2018-06-14 11:33:53 +01:00
Christian Hergert
e924f77736 gtype: improve get_type fast path
The -fstack-protector-strong used in many distributions by default has a
rather drastic slowdown of the fast path in generated _get_type()
functions using G_DEFINE_* macros. The amount can vary by architecture,
GCC version, and compiler flags.

To work around this, and ensure a higher probability that our fast-path
will match what we had previously, we need to break out the slow-path
(registering the type) into a secondary function that is not a candidate
for inlining.

This ensures that the common case (type registered, return the GType id)
is the hot path and handled in the prologue of the generated assembly even
when -fstack-protector-strong is enabled.

https://bugzilla.gnome.org/show_bug.cgi?id=795180
2018-05-09 12:25:06 +01:00
Philip Withnall
55e1c6185f gtype: Fix use of potentially undefined GVoidFunc
It’s defined in gutils.h, but various users of GLib might not have
access to that.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody

https://bugzilla.gnome.org/show_bug.cgi?id=793272
2018-02-16 17:42:55 +00:00
Lubomir Rintel
c1f5e52844 gtype: cast *_init functions to void(*)(void) first
The *_init() functions have prototypes incompatible with *InitFunc types they
are being cast to. This upsets GCC 8's -Wcast-function-type that's enabled by
default with -Wextra.

Let's not have the public header files emit a warning and neutralize it by
doing a void(*)(void) cast first.

https://bugzilla.gnome.org/show_bug.cgi?id=793272
2018-02-16 15:48:15 +00:00
Simon McVittie
0c0b1bdd0a g_type_check_value, g_type_check_value_holds: accept const argument
Conceptually, these functions clearly ought to be fine for a const
structure. This avoids _G_TYPE_CVH (the implementation of
G_TYPE_CHECK_VALUE_TYPE, G_VALUE_HOLDS, G_VALUE_HOLDS_BOXED etc.)
needing to cast to a mutable GValue, which causes
G_VALUE_HOLDS (cv, type) to issue warnings under gcc -Wcast-qual if
cv is a const GValue *.

https://bugzilla.gnome.org/show_bug.cgi?id=734479
2017-12-13 17:15:16 +00:00
Colin Walters
017f78d77f gtype: Add private DEFINE_TYPE with prelude to workaround gtype deadlocks
And use it in GSocket, as it had a real-world case reported.

https://bugzilla.gnome.org/show_bug.cgi?id=674885
2017-06-14 14:45:45 -04:00
Sébastien Wilmet
6b948d9613 gobject/: LGPLv2+ -> LGPLv2.1+
All gobject/*.{c,h} files have been processed.

gmarshal.c and gmarshal.h don't have a license header.

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-24 11:58:19 +02:00
Philip Withnall
953c182d25 gobject: Document behaviour of GType checking macros on NULL
The macros differ in their handling of NULL values — some macros ignore
them and pass through (e.g. G_TYPE_CHECK_INSTANCE_CAST) while others
will explicitly emit a warning if passed NULL (e.g.
G_TYPE_CHECK_INSTANCE).

Document their behaviour, so people don’t end up putting unnecessary
NULL checks in their code when doing checked type casts.

https://bugzilla.gnome.org/show_bug.cgi?id=735731
2017-01-07 23:43:06 +00:00
Emmanuele Bassi
85a23529ab Revert "make *_get_instance_private const-compliant"
This reverts commit a3a9664ed2.

Constifying the autogenerated get_instance_private functio makes C++
compilers and GCC with -Wcast-qual warn during compilation of GLib and
projects depending on GLib.

Since using const with GObject instances is not a common coding
practice, it's better to revert than trying to make every sigle GType
function const-safe (and possibly add more compiler warnings in the
process).

https://bugzilla.gnome.org/show_bug.cgi?id=745068
2016-01-18 18:48:42 +00:00
Emmanuele Bassi
617189f28c Revert "G_DECLARE_*: be const-compliant"
This reverts commit 52f23db74a.

Constifying these macros make C++ compilers and GCC with -Wcast-qual
warn during compilation of GLib and projects depending on GLib.

Since using const with GObject instances is not a common coding
practice, it's better to revert than trying to make every sigle GType
function const-safe (and possibly add more compiler warnings in the
process).

https://bugzilla.gnome.org/show_bug.cgi?id=745068
2016-01-18 18:46:12 +00:00
Philip Withnall
25a7c817d3 glib: Add missing (nullable) and (optional) annotations
Add various (nullable) and (optional) annotations which were missing
from a variety of functions. Also port a couple of existing (allow-none)
annotations in the same files to use (nullable) and (optional) as
appropriate instead.

Secondly, add various (not nullable) annotations as needed by the new
default in gobject-introspection of marking gpointers as (nullable). See
https://bugzilla.gnome.org/show_bug.cgi?id=729660.

This includes adding some stub documentation comments for the
assertion macro error functions, which weren’t previously documented.
The new comments are purely to allow for annotations, and hence are
marked as (skip) to prevent the symbols appearing in the GIR file.

https://bugzilla.gnome.org/show_bug.cgi?id=719966
2015-11-07 10:48:32 +01:00
Xavier Claessens
32811598f3 doc: clarify that _get_instance_private() is NULL-safe
https://bugzilla.gnome.org/show_bug.cgi?id=755083
2015-09-22 11:15:19 -04:00
Emmanuele Bassi
5e7e058a9c docs: Add an example of G_DEFINE_BOXED_TYPE
Mention that the GType of the boxed type is stored inside the
g_define_type_id variable.

See bug: https://bugzilla.gnome.org/show_bug.cgi?id=723394
2015-05-25 14:02:43 +01:00
Marc-Antoine Perennou
a3a9664ed2 make *_get_instance_private const-compliant
This is pure read-only access to an external struct
so void warnings for people calling it from const
contexts such as accessors

https://bugzilla.gnome.org/show_bug.cgi?id=745068

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2015-02-27 08:51:08 +01:00
Marc-Antoine Perennou
52f23db74a G_DECLARE_*: be const-compliant
switching to the old macros boilerplate to G_DECLARE_*
a lot of warnings start to pop when *_IS_A_* or such are
called from a const context.
Fix this by taking const pointers as parameters

https://bugzilla.gnome.org/show_bug.cgi?id=745068

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2015-02-27 08:51:08 +01:00
Xavier Claessens
3d39b8eb01 Add G_DECLARE_INTERFACE
https://bugzilla.gnome.org/show_bug.cgi?id=743939
2015-02-06 12:18:37 +01:00
Xavier Claessens
6a97275c45 docs: fix many documentation issues in gobject/ 2015-02-05 16:01:17 +01:00
Xavier Claessens
2b536d3cbb docs: fix typos in G_DECLARE_*_TYPE
https://bugzilla.gnome.org/show_bug.cgi?id=743656
2015-02-03 15:57:54 +01:00
Chun-wei Fan
6161b285da gtype.h: Fix Build on non-GCC
Use the (private) _GLIB_DEFINE_AUTOPTR_CHAINUP macro for
G_DECLARE_DERIVABLE_TYPE and G_DECLARE_FINAL_TYPE so that we will
attempt to typedef and define items necessary for GCC
__attribute__((cleanup)) on, well, GCC only.

This fixes the build on non-GCC.

https://bugzilla.gnome.org/show_bug.cgi?id=743640
2015-02-03 20:20:46 +08:00
Chun-wei Fan
407adc6ea1 gobject\gtype.h: Make up for Missing '\'
The macro definition for G_DECLARE_DERIVABLE_TYPE was missing a '\' when
we wanted to ignore deprecation warnings for it.
2015-02-02 11:16:29 +08:00
Ryan Lortie
8ea414c8c6 G_DECLARE_*_TYPE: add auto cleanup support
Automatically add support for the new cleanup macros to the type
declaration macros.

This is an API break because now your parent class needs to support
cleanup if you want to use G_DECLARE_*_TYPE.  These macros are only 1
day old, however, so that's probably not a big problem (and we are
already busy adding the macros all over GLib and Gtk+).

https://bugzilla.gnome.org/show_bug.cgi?id=743640
2015-01-30 16:52:36 +01:00
Ryan Lortie
b5e1ea6fee DECLARE_TYPE: ignore deprecations in inlines
Prevent complaints about deprecations in the inline functions emitted by
the new G_DECLARE_*_TYPE macros.
2015-01-30 16:49:53 +01:00
Ryan Lortie
9d0389b3b5 G_DECLARE_FINAL_TYPE: trivial fix in docs comment
https://bugzilla.gnome.org/show_bug.cgi?id=743640
2015-01-30 16:49:53 +01:00
Christian Hergert
f3c604d273 G_DECLARE_DERIVED_TYPE: allow forward declarations
This allows multiple declarations such as:

 typedef struct _Foo Foo;

as is needed when you have systems with circular referencing.

https://bugzilla.gnome.org/show_bug.cgi?id=743596
2015-01-28 13:22:23 +00:00
Ryan Lortie
3b4cb28e17 gtype: add type declaration macros for headers
Add G_DECLARE_DERIVABLE_TYPE() and G_DECLARE_FINAL_TYPE() to allow
skipping almost all of the typical GObject boilerplate code.

These macros make some assumptions about GObject best practice that mean
that they may not be usable with older classes that have to preserve
API/ABI compatibility with a time before these practices existed.

https://bugzilla.gnome.org/show_bug.cgi?id=389585
2015-01-27 11:07:52 +00:00
Owen W. Taylor
011bf876e7 Add simple instance count facility
Add GOBJECT_DEBUG=instance-count which enables internal accounting
of the number of instances of each GType, and g_type_get_instance_count()
to retrieve the result.

https://bugzilla.gnome.org/show_bug.cgi?id=354457
2014-10-11 13:54:29 -04:00
Kang Hu
baef9d1811 gobject: move _g_type_debug_flags from gtype.h to gtype-private.h
_g_type_debug_flags is used internally to suport GOBJECT_DEBUG
environment variable. it should never be exposed to the outside.

https://bugzilla.gnome.org/show_bug.cgi?id=729914
2014-06-28 14:00:32 -04:00
Matthias Clasen
adfaf0e456 docs: GType documentation cleanup
Still some markup left.
2014-05-31 20:55:00 -04:00
Emmanuele Bassi
24ab95582b docs: Replace <function> XML tag with back ticks
https://bugzilla.gnome.org/show_bug.cgi?id=731050
2014-05-31 19:22:15 +01:00
Edward Hervey
6072e3650f gtype: Add check for fundamental instance type
When checking whether an instance is of a given fundamental type (such
as G_TYPE_OBJECT), we can avoid over 60%+ of the cost of checking types.

https://bugzilla.gnome.org/show_bug.cgi?id=730984
2014-05-31 15:45:29 +02:00
Mathieu Bridon
24fdee7a78 Fix some typos in documentation 2014-05-05 18:30:56 +08:00
Philip Withnall
704852ff09 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
2014-04-29 10:40:20 +01:00
Volker Sobek
4441595378 docs: Remove <!-- --> comment before plural s
These did show up in the html. Since symbol names are checked for a
trailing plural s when generating the docs, the links stay functional
after removing these comments.

https://bugzilla.gnome.org/show_bug.cgi?id=728380
2014-04-24 13:42:37 +02:00
Volker Sobek
9f0ad54c80 docs: Use markdown links in all .c and .h files
Commit e7fd3de86d already did most of this.

https://bugzilla.gnome.org/show_bug.cgi?id=728285
2014-04-15 22:19:07 +02:00
Sebastian Dröge
012011538f gtype – Mark _get_instance_private() function as G_GNUC_UNUSED
clang likes to complain about it being unused.

https://bugzilla.gnome.org/show_bug.cgi?id=723899
2014-03-08 09:01:52 -05:00
Matthias Clasen
49cc207e35 docs: Ditch more markup
Some markup was hiding in docs in headers. Drop it there, too.
2014-03-02 18:23:43 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Misty De Meo
54e79d7dcb gobject: Fix compilation on OS X/ppc64
Apple's GCC compilers cannot deal well with 64-bit pointers in
transparent unions on ppc64, so compilation of
_G_DEFINE_BOXED_TYPE_BEGIN was failing. Fortunately glib already
provides a fallback for compilers that can't deal with it; this adds
this specific case to the check.

https://bugzilla.gnome.org/show_bug.cgi?id=647145
2013-09-19 08:39:18 -04:00
Dieter Verfaillie
9bcb6d3f00 Fix G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE documentation
https://bugzilla.gnome.org/show_bug.cgi?id=706469
2013-08-22 20:52:17 +02:00
Rico Tzschichholz
023e3b31a5 Fix a typo
Introduced by 3b01cbe8a8
2013-07-27 09:02:58 +02:00
Matthias Clasen
3b01cbe8a8 Document restrictions on private names
With the new machinery, private structs must be named
TypeNamePrivate if TypeName is the name of the instance
struct.
2013-07-26 14:42:22 -04:00
Sébastien Wilmet
b3968fb150 Improve documentation
- Mention G_SOURCE_CONTINUE and G_SOURCE_REMOVE in the GSourceFunc doc;
- Mention G_PARAM_READWRITE and G_PARAM_STATIC_STRINGS in the
  GParamFlags doc;
- Fix "Since:" version for G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE;
- Fix typo.

https://bugzilla.gnome.org/show_bug.cgi?id=704250
2013-07-20 11:07:46 +02:00
Emmanuele Bassi
a4c352cd99 Ensure that MAX_ALLOWED keeps working with the type macros
When using the GLIB_VERSION_MAX_ALLOWED macro to define the upper bound
of allowed API the G_DEFINE_TYPE_EXTENDED starts warning about the newly
added g_type_class_adjust_private_offset() function; this effectively
introduces a run-time dependency on GLib 2.38 even if we don't use its
API explicitly.

https://bugzilla.gnome.org/show_bug.cgi?id=703191
2013-07-03 09:37:03 -04:00
Emmanuele Bassi
54cc43630d Rename the generated private data getter function
As it turns out, we have examples of internal functions called
type_name_get_private() in the wild (especially among older libraries),
so we need to use a name for the per-instance private data getter
function that hopefully won't conflict with anything.
2013-06-24 15:43:04 +01:00
Emmanuele Bassi
39ba7c8142 gobject: Add private field access macros
Similar to G_STRUCT_MEMBER and G_STRUCT_MEMBER_P, but automatically using
the G_PRIVATE_OFFSET macro.

https://bugzilla.gnome.org/show_bug.cgi?id=700035
2013-06-24 14:18:01 +01:00
Emmanuele Bassi
d91d114a54 Add G_PRIVATE_OFFSET
A macro that evaluates to the offset of a field inside an instance
private data structure.

https://bugzilla.gnome.org/show_bug.cgi?id=700035
2013-06-24 14:18:01 +01: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
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
Andres G. Aragoneses
859e4239c5 gobject: fix G_DEFINE_TYPE_EXTENDED docs so code snippet actually compiles
Flags being used in the G_DEFINE_TYPE_EXTENDED sample was "0", so it
should expand to 0 as well, otherwise the compiler would bark with:
maman-bar.c: In function ‘maman_bar_get_type’:
maman-bar.c:36:53: error: ‘flags’ undeclared (first use in this function)
maman-bar.c:36:53: note: each undeclared identifier is reported only once for each function it appears in

https://bugzilla.gnome.org/show_bug.cgi?id=697250
2013-04-04 12:11:06 +01:00
Ryan Lortie
0156092a42 various: add GLIB_AVAILABLE_IN_ALL everywhere else
Add the GLIB_AVAILABLE_IN_ALL annotation to all old functions (that
haven't already been annotated with the GLIB_AVAILABLE_IN_* macros or a
deprecation macro).

If we discover in the future that we cannot use only one macro on
Windows, it will be an easy sed patch to fix that.

https://bugzilla.gnome.org/show_bug.cgi?id=688681
2013-01-13 13:11:57 -05:00