Commit Graph

2234 Commits

Author SHA1 Message Date
Alex Richardson
5ecd3cbe52 gobject: use g_once_init_enter_pointer for GType initializers
GType is either an integer or a pointer, so we have to use the _pointer
version here to support architectures such as Morello.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
See also: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3578
2023-10-04 14:50:54 +01:00
Alex Richardson
a1dfecf11f Use g_once_init_{enter,leave}_pointer where appropriate
This should not result in any functional changes, but will eventually
allow glib to be functional on CHERI-enabled systems such as Morello.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-04 13:57:16 +01:00
Philip Withnall
3d99d02112 Merge branch 'wip/chergert/make-gtype-create-instance-fast' into 'main'
gobject: cache flags needed for g_type_create_instance()

See merge request GNOME/glib!3595
2023-10-03 09:45:27 +00:00
Christian Hergert
ab2fe494a4 gobject: inline G_TYPE_IS() macros within gtype.c
If you take a release build (--buildtype=release) previously of GLib,
functions such as g_type_create_instance() would call out to
g_type_test_flags() which you can see by disassembling and looking for the
call instruction to <g_type_test_flags> via the library ABI.

Now that the previous commit allows checking abstract and deprecated flags
it makes sense to let the compiler optimize those checks into a single
pass. This is only possible if the functions themselves are inlined.

Additionally, any time we have the same TypeNode we would want to be able
to reuse that node rather than re-locate it.
2023-10-03 09:44:32 +01:00
Christian Hergert
5de7dd5a4b gobject: cache flags needed for g_type_create_instance()
Every call to g_type_create_instance() currently will incur a RWLock at
least once, but usually twice to test for both G_TYPE_FLAG_ABSTRACT and
G_TYPE_FLAG_DEPRECATED.

Additionally, each call to g_type_instance_free() also checks for these.
That results in a synchronization of GTypeInstance creation across all
threads as well as being a huge amount of overhead when creating instances
like GskRenderNode.

With this patch in place, the next two biggest issues are
g_type_class_ref() and g_type_test_flags() not getting inlined within
gtype.c in release builds. We can address that separately though.

Sysprof shows that the RWLock, with this patch in place, falls off the
profiles.
2023-10-03 09:44:32 +01:00
Philip Withnall
83eb8fc359 Merge branch 'wip/chergert/separate-gweakref-from-gweaknotify-gdata' into 'main'
gobject: Separate GWeakRef from GWeakNotify

See merge request GNOME/glib!3316
2023-10-03 08:43:37 +00:00
Emmanuele Bassi
70585f9a48 Add value annotation to G_TYPE_FUNDAMENTAL_MAX
The introspection parser isn't good enough to expand the shift symbol,
which means G_TYPE_FUNDAMENTAL_MAX is evaluated as (255 << 0).

We can use the `(value)` annotation to force the symbol value in the
introspection data.

See: GNOME/gobject-introspection#473
2023-10-02 01:29:50 +01:00
Alex Richardson
2787e59a77 CHERI: silence two pedantic warnings
When building for CHERI with additional warning flags, implicitly
converting uintptr_t to an integer type that can't store a pointer
results in a compiler warnings. Silence two of these by adding
explicit casts.
2023-09-12 10:23:20 -07:00
Christian Hergert
eb8a33625e gobject: Separate GWeakRef from GWeakNotify
This patch is based upon Garrett Regier's work from 2015 to provide
some reliability and predictability to how disposal handles weak
reference state.

A primary problem is that GWeakRef and GWeakNotify state is shared and
therefore you cannot rely on GWeakRef status due to a GWeakNotify
calling into second-degree code.

It's important to ensure that both weak pointer locations and GWeakRef
will do the proper thing before user callbacks are executed during
disposal. Otherwise, user callbacks cannot rely on the status of their
weak pointers. That would be mostly okay but becomes an issue when
second degree objects are then disposed before any notification of
dependent object disposal.

Consider objects A and B.

`A` contains a reference to `B` and `B` contains a `GWeakRef` to `A`.
When `A` is disposed, `B` may be disposed as a consequence but has not
yet been notified that `A` has been disposed. It's `GWeakRef` may also
cause liveness issues if `GWeakNotify` on `A` result in tertiary code
running which wants to interact with `B`.

This example is analagous to how `GtkTextView` and `GtkTextBuffer` work
in text editing applications.

To provide application and libraries the ability to handle this using
already existing API, `GWeakRef` is separated into it's own GData quark
so that weak locations and `GWeakRef` are cleared before user code is
executed as a consequence of `GData` cleanup.

# Conflicts:
#	gobject/tests/signals.c
2023-08-25 14:25:47 -07:00
Philip Withnall
c2df874e0b tests: Add some more tests for g_type_query()
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-07-30 13:51:00 +03:00
Philip Withnall
d9b23c5466 gtype: Allow g_type_query() to be called on dynamic types
There’s no reason that anyone can think of that this should be
disallowed. It’s useful for language runtimes like GJS to be able to
find out the allocation size of dynamic GObjects.

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

Fixes: #623
2023-07-30 11:25:42 +03:00
Chun-wei Fan
cb1eb57581 gobject tests: Fix running custom-dispatch on 32-bit Windows
UAC will terminate this test program from running in 32-bit x86 builds as
it believes that it will alter Windows.  In order to make this run, we
create a manifest file for 32-bit Windows builds in order to tell UAC
that this program should not need admin privileges.

This will allow the entire test suite for GLib to run on 32-bit Windows
builds.
2023-06-30 11:32:54 +08:00
Nelson Benítez León
c301542f81 gobject_gdb.py: adapt to recent gsignal changes
Add to script the new functions added in
commit 2368187e and commit e5ee6e14 which are:

signal_emitv_unlocked()
signal_emit_valist_unlocked()

so that the "<emit signal 'blabla'>" line keeps
showing after them.
2023-06-02 14:42:45 +01:00
Emmanuele Bassi
e8440ddcf9 Merge branch 'ebassi/type-table-docs' into 'main'
Allow proper introspection of GTypeValueTable

See merge request GNOME/glib!3441
2023-05-30 23:26:54 +00:00
Philip Withnall
5c50aec060 Merge branch 'glib-mkenums_parse_trigraph' into 'main'
Take double-quote characters into account when parsing trigraph

Closes #65

See merge request GNOME/glib!3452
2023-05-30 14:45:54 +00:00
Emmanuele Bassi
d4f2db270f Annotate GTypeValueTable callbacks for availability
The compiler annotations are mainly useful for people using the symbols
directly.

To avoid getting compiler warnings for the GTypeValueTable definition
itself, we need to wrap the structure with
G_GNUC_BEGIN_IGNORE_DEPRECATIONS and G_GNUC_END_IGNORE_DEPRECATIONS.
2023-05-30 14:38:16 +01:00
Emmanuele Bassi
23a9dbdaf6 Allow proper introspection of GTypeValueTable
The introspection scanner cannot deal very well with function pointers
into a plain structure. In order to document the various function
pointers in GTypeValueTable we need to create typed callbacks, and
use them to replace the anonymous function pointers inside the
structure. This not only allows us to properly document the function
pointers, but it also allows us to annotate the arguments and return
value of those function pointers.

See also: https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/400#note_1721707
2023-05-30 14:38:16 +01:00
Emmanuel Fleury
7e5607d534 Take double-quote characters into account when parsing trigraph
For now, the function parse_trigraph() defined in gobject/glib-mkenums
script was not taking double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': '"eek', 'a': None}

This patch take double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': 'eek, a comma'}

Closes issue #65
2023-05-30 15:22:05 +02:00
Marco Trevisan (Treviño)
2e1ceb9563 gsignals: Do not zero two times the instance GValue's GType
We already use g_new0 to create such arrays and nothing writes in the first
pointer till this point, so no need to zero it again.
2023-05-30 13:52:08 +01:00
Marco Trevisan (Treviño)
76ed55f3a7 gsignal: Use static allocation if we've just few emission hooks
Normally we don't really have emission hooks around, so try to allocate
only tiny array to contain a few of them and in case we exceed that limit,
we go back to use allocated ones.
2023-05-30 13:52:08 +01:00
Marco Trevisan (Treviño)
bfc599b8a2 gsignal: Reduce lock/unlock operations when calling signal_emit_unlocked_R
We used to call this function as unlocked, with a node value that
could be invalid at the point of the call, so let's ensure that when
we call such function it's defined, and then reduce the access to the
signal node members when we're unlocked or after a lock/unlock operation
that may have changed it.

As per this, add more tests handling multiple signal hooks cases that we
did not cover before.
2023-05-30 13:52:08 +01:00
Marco Trevisan (Treviño)
e5ee6e141d gsignal: Cleanup g_signal_emitv splitting it in locked and unlocked paths
It just makes code easier to maintain and more clearly scoped.
2023-05-30 13:52:08 +01:00
Marco Trevisan (Treviño)
f011910395 gsignal: Do not try to access to node members when unlocked
In g_signal_emit_valist() we used to access to param types array and
n_params values after unlocking the mutex, and this might have lead to
making such values unreliable for the current call.

So let's keep them around until we're done with the function call
2023-05-30 13:52:07 +01:00
Marco Trevisan (Treviño)
2368187eb9 gsignal: Avoid possible race in g_signal_emit_by_name
Since we're locking and unlocking once we've found the signal ID, we
might have performed calls to g_signal_emit_valist() with a signal id
that was already been removed, and thus failing later.

This is not really an issue as inside g_signal_emit_valist() we were
re-checking for the signal id, but we can make this more reliable so
that the first thread that acquires the lock can also be sure to emit.
2023-05-30 13:52:07 +01:00
Marco Trevisan (Treviño)
0bc725d4fe gobject/tests/signals: Add tests for g_object_emitv
It's very much used by bindings but we didn't really test it locally.
2023-05-30 13:52:07 +01:00
Philip Withnall
0196a36022 Merge branch 'more-atomic-exchange-full' into 'main'
gdataset, gobject: Use atomic compare and exchange full to set pointers

See merge request GNOME/glib!3426
2023-05-30 11:59:40 +00:00
Nelson Benítez León
f09805fd97 gobject_gdb.py: small style change to signal name
This is a minor style change to better differentiate
signal name by enclosing it in single quotes.

Before:
<emit signal event on instance 0xf14e60 [GdkWaylandToplevel]>

After:
<emit signal 'event' on instance 0xf14e60 [GdkWaylandToplevel]>
2023-05-20 02:30:07 +01:00
Nelson Benítez León
3e9db78656 gobject_gdb.py: support gsignal fastpath and detect more marshallers
- Commit f02ec2f2de added a gsignal fastpath where g_closure_invoke_va()
is directly called from g_signal_emit_valist() skipping signal_emit_unlocked_R()
altogether which it's the function used by gobject_gdb.py to detect
signal emission.

So we update gobject_gdb.py to also detect signals which use this
g_closure_invoke_va() fastpath.

- We also update the existent code to detect marshallers to also
include these:

surface_event_marshaller()
gdk_surface_event_marshallerv()
g_type_class_meta_marshal()
g_type_class_meta_marshalv()

This allow us that for signal emissions which use those marshallers
to keep showing the signal handler frame just after the
<emit signal blabla> line.
2023-05-20 02:30:00 +01:00
Nelson Benítez León
1a19095a36 gobject_gdb.py: fix regression caused by bfbe7127d5
commit bfbe7127d5 which did a code refactor in
gobject_gdb.py introduced a bug by failing to
return the signal name when a signal had no
'detail', this was preventing pretty printing
name for signals with no 'detail'.
2023-05-15 18:04:37 +01:00
Philip Withnall
eee3885077 Merge branch 'gtk-plus' into 'main'
Rename GTK+ to GTK (mostly comments and documentation)

See merge request GNOME/glib!3429
2023-05-10 08:39:58 +00:00
Arnaud Rebillout
d6e57943ea Fix style-check for {gconvert,gutils,gobject}.c
Also take this chance to change a 'Glib' to 'GLib'.
2023-05-10 10:56:44 +07:00
Arnaud Rebillout
f722f11e57 Rename GTK+ to GTK (mostly comments and documentation)
GTK lost it's '+' suffix back in 2019, according to
<https://mail.gnome.org/archives/gtk-devel-list/2019-February/msg00000.html>

This commit can be re-generated with:

    git grep -l GTK+ \
    | grep -v -e ^NEWS -e ^glib/tests/collate.c \
    | xargs sed -i 's/GTK+/GTK/g'

Most of the changes are in comments and documentation.
2023-05-10 10:56:44 +07:00
Eric Blake
2ab2ce57e6 gtestutils: Improve g_assert_cmpuint
While x86_64 has enough precision in long double to do a round trip
from guint64 to long double and back, this is platform-specific, and
is a disservice to users trying to debug failing unit tests on other
architectures where it loses precision for g_assert_cmp{int,uint,hex}.
See also https://bugzilla.gnome.org/show_bug.cgi?id=788385 which
mentions having to add casts to specifically silence the compiler on
platforms where the precision loss occurs.

Meanwhile, g_assert_cmpuint() does an unsigned comparison, but outputs
signed values if the comparison fails, which is confusing.

Fix both issues by introducing a new g_assertion_message_cmpint()
function with a new 'u' numtype.  For backwards compatibility, the
macros still call into the older g_assertion_message_cmpnum() when not
targetting 2.78, and that function still works when passed 'i' and 'x'
types even though code compiled for 2.78 and later will never invoke
it with numtype anything other than 'f'.  Note that g_assert_cmpmem
can also take advantage of the new code, even though in practice,
comparison between two size_t values representing array lengths that
can actually be compiled is unlikely to have ever hit the precision
loss.  The macros in signals.c test code does not have to worry about
versioning, since it is not part of the glib library proper.

Closes #2997
Signed-off-by: Eric Blake <eblake@redhat.com>
2023-05-09 08:28:09 -05:00
Marco Trevisan (Treviño)
f792b2ce64 gobject: Use atomic compare and exchange full to force floating
In case first exchange failed we can avoid repeating the pointer get
operation given that exchange full can provide us the old value.
2023-05-09 15:04:36 +02:00
Philip Withnall
dc95b911f3 docs: Drop outdated docs/debugging.txt
Most of the document was about traps, which have not existed since
commit 58cdf0b474, 10 years ago.

The rest of the document was about `GOBJECT_DEBUG`, and that information
would be more easily findable in the full GObject documentation — so
move it there and update it a bit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 23:56:59 +01:00
Przemyslaw Gorszkowski
74d49e447f Test g_signal_handlers_disconnect_matched for G_SIGNAL_MATCH_ID match
Signed-off-by: Przemyslaw Gorszkowski <pgorszkowski@igalia.com>
2023-04-18 12:50:55 +02:00
Przemyslaw Gorszkowski
b264585f3c gsignal: Support G_SIGNAL_MATCH_ID in g_signal_handlers_block/unblock/disconnect_matched()
Calling g_signal_handlers_block/unblock/disconnect_matched with only G_SIGNAL_MATCH_ID
do not match any handlers and return 0.

Fixes: #2980

Signed-off-by: Przemyslaw Gorszkowski <pgorszkowski@igalia.com>
2023-04-14 15:27:11 +01:00
Philip Withnall
2d8e38c00d gsignal: Clarify documentation for GSignalMatchType matching
The use of ‘OR’ in the existing documentation suggests that the matching
is disjunctive, but it’s actually conjunctive. Clarify that in the
documentation and add a test.

Spotted while reviewing
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3376.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-14 13:55:20 +01:00
Philip Withnall
d1eb9c840c tests: Add type flag tests for interfaces
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #252
2023-04-13 15:39:37 +01:00
Philip Withnall
783f1b8640 gtype: Improve documentation for G_TYPE_IS_CLASSED and interfaces
The documentation previously implicitly said in a few places that
interfaces are classed, but reading through the implementation of
`GType`, I don’t think they are. If they were, the registration of the
fundamental `G_TYPE_INTERFACE` in `gobject_init()` would specify
`G_TYPE_FLAG_CLASSED`. It only specifies `G_TYPE_FLAG_DERIVABLE`.

I think this makes sense, because you can’t subclass an interface.
Subclassing is a key property of being classed.

Tweak the `GType` tutorial to remove that implicit statement, and expand
the documentation for `G_TYPE_IS_CLASSED`.

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

Fixes: #252
2023-04-13 15:37:00 +01:00
Philip Withnall
c1e0506d86 gtype: Clarify return value documentation
‘returns TRUE on success’ is misleading for a lot of these macros, as
they are checking whether a type has a certain property. Such a check
could be successful but return `FALSE`, by the normal meaning of the
word ‘success’.

Instead, reword the docs to spell out when `TRUE` will be returned.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-13 13:51:04 +01:00
Marco Trevisan
9ec6695a72 Merge branch 'drop-gitignore' into 'main'
build: Drop old .gitignore files from test directories

See merge request GNOME/glib!3333
2023-04-05 14:29:13 +00:00
Philip Withnall
3504385eba gvalue: Fix a typo in a function name in an example in the docs
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2864
2023-03-23 12:24:33 +00:00
Philip Withnall
3d7e88a77d build: Drop old .gitignore files from test directories
They just listed built files. Since the move to Meson, these are all
kept in a separate build directory, not the source tree, so don’t need
to be ignored.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-20 12:09:02 +00:00
badcel
1c15f158b0
gobject: Fix some annotations 2023-02-24 18:06:14 +01:00
Emmanuele Bassi
2c14e71162 Merge branch 'no-performance-valgrind' into 'main'
tests: Don’t run the GObject performance tests under valgrind

See merge request GNOME/glib!3279
2023-02-22 01:36:27 +00:00
badcel
993f6d6698
g_type_name: Fix return annotation
The function can return null so it should be annotated as nullable.
2023-02-21 22:19:56 +01:00
Philip Withnall
0e84e28978 tests: Don’t run the GObject performance tests under valgrind
They take too long and time out, and are not particularly useful to run
under valgrind because they aren’t designed to test code coverage.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-16 12:52:30 +00:00
Philip Withnall
6ba1627fe6 Merge branch 'g-atomic-array-alignment' into 'main'
GAtomicArray: Ensure metadata does not misalign the payload

See merge request GNOME/glib!3242
2023-02-06 14:08:06 +00:00
Philip Withnall
bd8b756853 Merge branch 'gtype-use-sized-free' into 'main'
Revert "gtype: Use the system allocator on UNIX" and use g_free_sized instead

See merge request GNOME/glib!3251
2023-02-06 14:00:38 +00:00