Commit Graph

1930 Commits

Author SHA1 Message Date
Gabor Karsay
7e64004db0 docs: mark macros, flags, enums with percent sign 2022-03-04 16:21:55 +00:00
Xavier Claessens
2bd152bfeb meson: Add PYTHONPATH to load GDB helper module
Meson generates a gdbinit file that will automatically load glib and
gobject scripts. However that script uses a helper python module that
needs PYTHONPATH to be pointing into the right location in the source
tree to be able to find glib_gdb.py and gobject_gdb.py
2022-02-25 16:50:18 -05:00
Philip Withnall
cb18e6b969 Merge branch 'empty-argv' into 'main'
Various minor fixes for empty argv handling

See merge request GNOME/glib!2466
2022-02-20 09:36:41 +00:00
Xavier Claessens
893ff61176 doc: Extend a bit G_DECLARE_* documentation example 2022-02-19 14:23:37 -05:00
Loic Le Page
8e37f9c48a Fix global variable name hidden by local variables in gobject/tests/reference.c 2022-02-18 10:49:00 +01:00
Loic Le Page
208593acc6 Fix redefinition of local variable and non-initialized variable in gobject/gsignal.c 2022-02-18 10:49:00 +01:00
Loic Le Page
84c5675cef Fix redefinition of local variable in gobject/gtype.c 2022-02-18 10:49:00 +01:00
Philip Withnall
3ea4ba31a1 tools: Fix handling of empty argv in various minor GLib tools
This won’t really affect anything, but we might as well fix them to not
crash if called with an empty `argv` by someone (ab)using `execve()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:42 +00:00
Christian Hergert
dd43471f60 gobject: add GSignalGroup
Much like GBindingGroup, the GSignalGroup object allows you to connect many
signal connections for an object and connect/disconnect/block/unblock them
as a group.

This is useful when using many connections on an object to ensure that they
are properly removed when changing state or disposing a third-party
object.

This has been used for years in various GNOME projects and makes sense to
have upstream instead of multiple copies.
2022-02-01 17:09:14 -08:00
Christian Hergert
0d9de09192 gobject: add GBindingGroup
Originally, GBindingGroup started with Builder as a way to simplify all
of the third-degree object bindings necessary around Model-Controller
objects such as TextBuffer/TextView.

Over time, it has grown to be useful in a number of scenarios outside
of Builder and has been copied into a number of projects such as GNOME
Text Editor, GtkSourceView, libdazzle, and more.

It makes sense at this point to unify on a single implementation and
include that upstream in GObject directly alongside GBinding.
2022-01-28 16:01:22 -08:00
Andoni Morales Alastruey
b1ed9907c2 gi: expose some files as variable for gobject-introspection
see:
https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/313
2022-01-28 16:16:29 +01:00
Xavier Claessens
9159e84ce5 Windows: Do not link DLL specific resources when doing a static build
Fixes: #2585
2022-01-26 09:49:30 -05:00
Loic Le Page
42c77c7ac7 Enable full-static build on Windows
Glib cannot be built statically on Windows because glib, gobject and gio
modules need to perform specific initialization when DLL are loaded and
cleanup when unloaded. Those initializations and cleanups are performed
using the DllMain function which is not called with static builds.

Issue is known for a while and solutions were already proposed but never
merged (see: https://gitlab.gnome.org/GNOME/glib/-/issues/692). Last
patch is from version 2.36.x and since then the
"constructor/destructor" mechanism has been implemented and used in
other part of the system.

This patch takes back the old idea and updates it to the last version of
glib to allow static compilation on Windows.

WARNING: because DllMain doesn't exist anymore in static compilation
mode, there is no easy way of knowing when a Windows thread finishes.
This patch implements a workaround for glib threads created by calling
g_thread_new(), so all glib threads created through glib API will behave
exactly the same way in static and dynamic compilation modes.
Unfortunately, Windows threads created by using CreateThread() or
_beginthread/ex() will not work with glib TLS functions. If users need
absolutely to use a thread NOT created with glib API under Windows and
in static compilation mode, they should not use glib functions within
their thread or they may encounter memory leaks when the thread finishes.

This should not be an issue as users should use exclusively the glib API
to manipulate threads in order to be cross-platform compatible and this
would be very unlikely and cumbersome that they may mix up Windows native
threads API with glib one.

Closes #692
2022-01-26 10:14:02 +01:00
Sebastian Dröge
3b3022dff1 Merge branch 'doc_sync_signals' into 'main'
Make clear in doc that signals are emitted synchroniously

See merge request GNOME/glib!2423
2022-01-18 08:53:21 +00:00
Alexander Schwinn
28d833a075 Make clear in doc that signals are emitted synchroniously 2022-01-18 08:53:20 +00:00
Emmanuel Fleury
66ebcbced4 Merge tests/gobject/paramspec-test.c into gobject/tests/param.c
Helps issue #1434
2022-01-17 20:43:27 +00:00
Emmanuel Fleury
86fedcfb93 Merge tests/gobject/gvalue-test.c with gobject/tests/value.c
Helps issue #1434
2022-01-12 21:51:05 +01:00
Bilal Elmoussaoui
2f9b3ec6cc paramspec: fix unref annotation 2021-12-30 12:40:47 +00:00
Emmanuel Fleury
c8274a51cd Fix defined but not used warning in gobject/gobject.c
gobject/gobject.c:1189:1: warning: ‘floating_check’ defined but not used
2021-12-17 15:30:18 +01:00
Emmanuel Fleury
ae345e56c2 Distribute cxx test tests/cxx-test.cpp to each module tests directory
tests/cxx-test.cpp is removed and splitted into gio/tests/cxx.cpp,
gmodule/tests/cxx.cpp and gobject/tests/cxx.cpp.

Helps issue #1434
2021-12-14 14:43:03 +01:00
Emmanuele Bassi
1ec331266a Defer GObject::notify during object destruction
Notifying during object destruction is a dubious "feature": objects
might end up recreating a bunch of state just before clearing it;
language bindings might get spurious notifications during garbage
collection runs.

We freeze the notification queue before running the dispose() chain; if
the object was temporarily vivified during dispose, we thaw the
notification queue, otherwise we let the instance clear it when we
finalize it.

See: https://gitlab.gnome.org/GNOME/gjs/-/issues/445
2021-11-29 15:43:59 +00:00
Nishal Kulkarni
1529c2ca4d gobject: Use new g_newa0() function
Replace old `g_newa()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Nishal Kulkarni
34cf69ef17 gsignal: Use new g_newa0() function
Replace old `g_alloca()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Sebastian Dröge
c3f4f9c215 Merge branch 'reformat-enums' into 'main'
tests: Reformat mkenums.py slightly to make run-black.sh happy

See merge request GNOME/glib!2342
2021-11-22 13:54:42 +00:00
Philip Withnall
7a8756d247 gobject: Add advice on larger alignment requirements for GObject members
We now guarantee that GObjects will always be allocated at least as
aligned as the basic types. If you want to put an element in your
GObject which has higher alignment requirements, we can’t guarantee it
will be aligned*. If you need it to be aligned, you’ll need to put it on
the heap (aligned appropriately), or add appropriate padding in your
GObject struct.

*Actually, GSlice will guarantee that the whole GObject is aligned to at
least the power of 2 greater than or equal to the size of the GObject,
which means any element in the GObject struct should always be
appropriate aligned if the compiler pads it appropriately. If malloc()
is used, however, it doesn’t make that guarantee, so we can’t make that
guarantee overall.

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

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
ed553e8e30 gtype: Eliminate -Wcast-align warnings with G_TYPE_CHECK_INSTANCE_CAST
Regardless of the actual alignment of the GTypeInstance in question,
these do a runtime check on the type, so if the type was originally
aligned correctly when allocated, it should be aligned correctly if the
type check succeeds. -Wcast-align is meant to warn about casts between
types, which this isn’t (if the check succeeds).

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

Fixes: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
0749643daa gobject: Assert that GObjects are at least as aligned as basic types
See the reasoning in the patch for why we believe GObjects *are*
(already) as aligned as the basic types.

We want to make this guarantee so that it’s guaranteed to be safe for
people to ignore -Wcast-align warnings for GObjects which contain basic
types. This typically happens with gdouble on 32-bit ARM platforms.

The checks are slightly complicated by the need to support GObjects with
custom constructors. We should expect that a custom construction
function will chain up to g_object_constructor (which calls
g_type_create_instance() as normal), but it’s possible that someone has
done something crazy and uses a custom allocator which doesn’t return
with the same alignment as GSlice. Hand them a warning in that case. If
that is true, the code which uses their custom-constructed GObject can
presumably already deal with the alignment it gets given.

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

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
c6dca3459b tests: Reformat mkenums.py slightly to make run-black.sh happy
This should remove some warnings from the CI, making it easier to see
legitimate CI failures.

For example, see https://gitlab.gnome.org/GNOME/glib/-/jobs/1621041.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-17 10:37:07 +00:00
Michael Catanzaro
98e0789fea Merge branch 'weak-refs-docs' into 'main'
gobject: Clarify behaviour of adding weak refs during disposal

See merge request GNOME/glib!2255
2021-10-27 23:37:22 +00:00
Philip Withnall
2423419a29 Merge branch 'static-analysis' into 'main'
fix issues found by svace static code analyzer

See merge request GNOME/glib!2285
2021-10-18 11:03:33 +00:00
Egor Bychin
5419228f63 gtype: Fix pointer being dereferenced despite NULL check 2021-10-15 14:15:43 +03:00
Philip Withnall
a4c9049486 build: Don’t pass false to install_dir
This fixes a Meson deprecation warning which appeared in Meson 0.50.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-07 17:15:13 +01:00
Simon McVittie
6ccb387197 Merge branch 'object-weak-ref-docs' into 'main'
gobject: Document it’s unsafe to call g_object_ref() from GWeakNotify

See merge request GNOME/glib!2246
2021-09-28 09:24:47 +00:00
Philip Withnall
579ff9f6c9 Merge branch 'ebassi/floating-warning' into 'main'
Add a (diagnostic) warning for finalized floating objects

Closes #2489

See merge request GNOME/glib!2247
2021-09-21 11:09:16 +00:00
Marco Trevisan (Treviño)
468246bb3b gobject: Ensure an object has toggle references before notifying it
When an object with toggle reference is notifying a change we just
assume that this is true because of previous checks.
However, while locking, another thread may have removed the toggle
reference causing the waiting thread to abort (as no handler is set at
that point).

To avoid this, once we've got the toggle references mutex lock, check
again if the object has toggle reference, and if it's not the case
anymore just ignore the request.

Add a test that triggers this, it's not 100% happening because this is
of course timing related, but this is very close to the truth.

Fixes: #2394
2021-09-20 17:56:25 +02:00
Philip Withnall
3f1a1cdb78 Merge branch 'prop-set-speedups' into 'main'
Small optimization for g_object_set

See merge request GNOME/glib!2254
2021-09-20 12:47:00 +00:00
Philip Withnall
3b67d53227 gobject: Clarify behaviour of adding weak refs during disposal
The previous wording was not clear about what happens if a new weak ref
is taken during disposal (shortly after resurrecting the object with a
new strong ref, otherwise taking the weak ref is invalid).

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2064/diffs#note_1270092

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2390
2021-09-20 13:23:34 +01:00
Matthias Clasen
497986cdc1 Small optimization for g_object_setv
No need to call memset in the loop, we can just
initialize all the values in one go.

GtkBuilder is now using g_object_setv, so this
may improve application start times a bit.
2021-09-20 08:21:49 -04:00
Matthias Clasen
23e37e05d2 Small optimization for g_object_set
We've already followed the redirection, no need
to check for that again - just avoid notifying
non-readable properties.
2021-09-20 08:21:42 -04:00
Marco Trevisan (Treviño)
a7262d6357 gobject: Cleanup weak locations data as part of dispose
Weak locations were not fully cleaned on run_dispose() and after dispose
vfunc was called, so ensure that this is the case.

Fixes: #865
2021-09-17 12:28:01 +02:00
Marco Trevisan (Treviño)
e861f60dcb gobject: Cleanup weak locations when the last one has been removed
As per the previous change, an object that had weak locations set may
need to lock again the weak locations mutex during qdata cleanup, but
we can avoid this when we know we're removing the last location, by
removing the qdata entry and freeing the data.

In case a new location is needed for the same object, new data will be
added.

However, by doing this the weak locations during dispose may be
invalidated once the weak locations lock is passed, so check again if
this is the case while removing them.
2021-09-17 12:27:59 +02:00
Marco Trevisan (Treviño)
ea68b22135 gobject: Cleanup GWeakRef locations on object finalization
It can happen that a GWeakRef is added to an object while it's disposing
(or even during finalizing) and this may happen in a thread that (weak)
references an object while the disposal isn't completed yet or when
using toggle references and switching to GWeakRef on notification (as
the API suggests).

In such scenario the weak locations are not cleaned up when the object
is finalized, and will point to a free'd area.

So, during finalization and when we're sure that the object will be
destroyed for sure, check again if there are new weak locations and
unset them if any as part of the qdata destruction.
Do this adding a new utility function so that we can avoid duplicating
code to free the weak locations.

Added various tests simulating this case.

Fixes: #2390
2021-09-17 12:21:23 +02:00
Philip Withnall
0d57092a03 gobject: Document it’s unsafe to call g_object_ref() from GWeakNotify
The documentation sort of already said this, but it’s better to make it
explicit.

This avoids the situation where some of the weak notify callbacks for an
object have been called, and then a subsequent one resurrects the
object. Without some way of undoing the weak notifications already sent,
that would leave external state which is coupled to the object’s
lifecycle out of sync.

This arose from discussion on !2064.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-09-15 15:02:47 +01:00
Emmanuele Bassi
6fe0f98360 Add a (diagnostic) warning for finalized floating objects
GTK currently checks if a GtkWidget is finalized while still using a
floating reference—i.e. a widget was disposed without any parent
container owning it.

This warning can be useful to identify and trace ownership transfer
issues in libraries using initially unowned floating object types.

To avoid introducing constraints ex post, we can gate this check behind
both the G_ENABLE_DEBUG compile time flag for GLib, and behind the
G_ENABLE_DIAGNOSTIC environment variable run time check.

Fixes: #2489
2021-09-14 16:09:22 +01:00
Philip Withnall
e99ee3588a Merge branch 'revert-cd93c350' into 'main'
Revert "Merge branch 'fix/gclosure-invoke-type-annotation' into 'main'"

Closes #2477

See merge request GNOME/glib!2237
2021-09-06 15:23:54 +00:00
DarkTrick
3c459b7fd6 doc: Explicitly said, that no null term. is needed 2021-09-06 11:23:14 +00:00
Evan Welsh
0de8ec87d2 Revert "Merge branch 'fix/gclosure-invoke-type-annotation' into 'main'"
This reverts merge request !2181
2021-08-29 20:56:08 +00:00
Philip Withnall
709df8eeb4 Merge branch 'docgen-fixes' into 'main'
Adapt documentation to gi-docgen

See merge request GNOME/glib!2206
2021-08-03 13:53:38 +00:00
Emmanuele Bassi
f62622fc7b docs: Start stanzas with a single paragraph
When rendering the contents of the GLib documentation stored inside the
introspection data, a common behaviour is to take the first paragraph as
a summary of the symbol being documented.

The documentation is assumed to be in Markdown format, which means:

 - paragraphs must be separated by newlines
 - lines that have an indentation of four or more spaces are considered
   code blocks
 - lines that start with a `#` are considered titles

This means we need to slightly tweak the documentation in our sources to
ensure that it can be rendered appropriately by tools that are not
gtk-doc.

See issue: #2365
2021-08-02 13:22:23 +01:00
Matthias Clasen
6a6da9637a Fix a Unicode typo
The name of one of the Unicode Break types is misspelt.
Add an alias, since it annoys me every time I look at
Pango's break code.
2021-07-29 10:09:27 -04:00