1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2026-10-24 00:49:00 +03:00

2545 Commits

Author SHA1 Message Date
Christian Hergert
30dfead61b gobject/gclosure: cache libffi plans for closures
If we are using libffi to trampoline then there is opportunity to cache
the ffi_call_plan introduced in newer libffi releases. A rather contrived
test introduced in the previous commit includes a basic performance test
that can compare between versions.

For my system, the average call time dropped from 200ns/call to 145ns/call
for cached GClosure. Since the previous version did no caching, the
uncached GClosure use was also just slightly slower around 205ns/call. For
the cached form (since it can reuse a global plan cache via GMutex) it
drops to 180ns/call. So that is 27.5% savings and a 10% savings in runtime
duration.

Closes: #4002
Co-authored-by: Philip Withnall <pwithnall@gnome.org>
2026-10-14 12:55:41 +02:00
Christian Hergert
c4d9e92e11 gobject/tests: add performance test for generic marshaller
The goal here is to get a baseline for upcoming performance work
to use the cached libffi plans rather than generating a new plan
on every pass through libffi.
2026-10-14 12:55:41 +02:00
Eugenio Depalo
4c7b3f488f gvalue: Annotate reset result as borrowed
g_value_reset() returns the GValue passed in, so ownership of the
storage stays with the caller. Annotate the return value as borrowed
to prevent introspection consumers from treating it as newly owned.
2026-10-13 18:02:23 +02:00
Philip Withnall
1372dd5bc9 tests: Mark some signal ID variables as unused
They’re written to but not read from.

See https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171580 and
https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171674

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-11 13:25:59 +01:00
Philip Withnall
e1e24568cb gobject: Mark dynamic type parent class pointer as potentially unused
Just as with commit 1567250294, but for
`G_DEFINE_DYNAMIC_TYPE_EXTENDED`.

See https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171461

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-11 00:08:09 +01:00
Philip Withnall
1ca4b33948 tests: Mark a static test variable as unused
Because it’s written to but not read. And that’s fine; this is test
code.

See https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171414

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-10 23:51:53 +01:00
Philip Withnall
11de1d730e gobject-query: Remove no-op -s spacing option
msys2-clang64 noticed that the `spacing` variable was written to but
never read from. Indeed, this option has been a no-op since I
accidentally/deliberately broke it in commit
98e6ac788e.

Drop it, because nobody has complained about it breaking since 2022, and
I’m not sure about what the use case for it originally was meant to be.

See https://gitlab.gnome.org/pwithnall/glib/-/jobs/7171235

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-10-10 23:40:34 +01:00
Philip Withnall
e25292063a Merge branch 'ebassi/gtype-class-rec-mutex' into 'main'
Simplify locking when adding interfaces

See merge request GNOME/glib!5378
2026-10-07 10:42:18 +00:00
Philip Withnall
094f8ed5f8 Merge branch 'wip/3v1n0/ci-sanitizer-tests' into 'main'
CI: Add address (asan) and thread sanitizer (tsan) jobs

Closes #3356

See merge request GNOME/glib!4062
2026-10-06 15:14:53 +00:00
Emmanuele Bassi
139453e0da Simplify locking when adding interfaces
The act of initialising a class requires acquiring the class_init
recursive mutex alongside the type read/write mutex, to avoid the case
when one thread calls the type registration function on type B in the
middle of the class initialisation of type A—for instance, to add a
property of type B.

The initial implementation of GTypeInterface allowed adding interfaces
to a GType after the class had already been initialised, which leads to
a deadlock if, in the case outlined above, type B also adds an
interface. See issue #3892 for an example.

Luckily for us, we have disabled adding interfaces to types after their
class has been initialised: see commits c2055f22 and 545b4444.

Now that 14 years have passed, we can remove the class_init_rec_mutex
lock acquisition when adding an interface to a static or a dynamic
types, and when getting the default interface vtable.

See: #541
2026-09-25 12:02:06 +01:00
Sunil Dora
1567250294 gtype: Mark the G_DEFINE_TYPE parent_class variable as unused
clang 23 added -Wunused-but-set-global, which fires on the
type_name##_parent_class variable that _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE
emits whenever a type never chains up to its parent:

  error: variable 'my_thing_parent_class' set but not used
  [-Werror,-Wunused-but-set-global]

Projects that promote the unused-but-set group to an error (pango, for
one) now fail to build with clang 23, and they cannot fix it on their
side because the variable comes from this macro.

Annotate it G_GNUC_UNUSED, the same treatment the adjacent
get_instance_private helper already gets.

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
Fixes: #4038
2026-09-08 22:56:43 +01:00
Marco Trevisan (Treviño)
f8cd442d73 build: Mark all the failing and flacky tests with thread sanitizer
Sadly many tests don't pass with thread sanitizer, but better to
mark them as such to try to fix them in the future

See also: https://gitlab.gnome.org/GNOME/glib/-/issues/1672
2026-08-30 00:34:48 +02:00
Michael Catanzaro
e2ed2d54ba mkenums: remove use of deprecated os.path.commonprefix()
This path function is deprecated because it doesn't work properly if you
are using paths. glib-mkenums is using it "properly" in the sense that
it is not passing it any paths, but on the other hand, passing non-paths
to a path function is pretty silly. You can see why the function is
deprecated.

Embarassingly, my replacement implementation is AI-generated, although I
have simplified it to be less robust than the AI proposed. Why did I
intentionally make the function less robust? Because it's only used in
one place, and doesn't need to be able to handle any possible number of
arguments.
2026-08-20 19:27:54 -05:00
DaKnig
e3d0954c29 glib-mkenums: Fix a potentially quadratic-time regex to be linear 2026-08-11 11:04:23 +00:00
Philip Chimento
0213ee7354 Avoid reserved identifiers in public macros
Clang-tidy has a check to prohibit identifiers that are reserved for the
compiler. Those are identifiers that start with:
  - an underscore plus an uppercase letter
  - two underscores
  - an underscore, and are in the global scope
https://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html

Many public GLib macros define variables starting with two underscores,
which is technically not allowed. This is probably usually harmless, but
it causes false positives in the abovementioned clang-tidy check when
consumers of GLib use macros like G_VALUE_HOLDS_POINTER or
g_str_has_suffix.

This commit replaces all such names with one-underscore names, which are
not reserved because they're not in the global scope.

Here's the incantation I used to discover which macros needed editing:

git grep -P '\b__(?!builtin|atomic|sync|asm|volatile|pragma)[a-z].*\\$' \
  -- '*.h' | grep -v valgrind.h

This generates a manageable number of false positives. It also fails to
find identifiers on the last line of a macro, but those are generally
already mentioned elsewhere in the macro.

I left valgrind.h untouched.
2026-07-26 14:12:11 -07:00
Maximiliano Sandoval
9089e9a613 docs: Use dedicated docblocks for new enum members
... added since 2.74. 2.74 was selected arbitrarily.

When a Since annotation is written inline for an enum member, g-ir won't
parse it, they need dedicated doc blocks.
2026-07-20 20:37:22 +02:00
Maximiliano Sandoval
c4bf04f68f docs: Annotate callbacks rather than user_data
See
https://gi.readthedocs.io/en/latest/annotations/giannotations.html#callbacks
for more details.

These caused invalid "closure" annotation warnings.
2026-07-18 16:54:42 +02:00
Sam James
803810fa14 gtype: downgrade some (non-*_get_type) G_GNUC_CONST -> G_GNUC_PURE
g_type_check_is_value_type and g_type_test_flags both read global memory,
so can't be const. They only seem to write for the purpose of a lock, which
they undo at the end, so maybe we can get away with G_GNUC_PURE here.

Bug: https://gitlab.gnome.org/GNOME/glib/-/work_items/3984
Signed-off-by: Sam James <sam@gentoo.org>
2026-06-25 17:23:46 +01:00
Sam James
016829559e Drop G_GNUC_CONST for *_get_type
g_type_ensure has a large comment saying _get_type shouldn't be
marked with G_GNUC_CONST because it has side-effects on the first
run, but it's OK if you consistently call g_type_ensure first.

Unfortunately, this isn't accurate. GCC trunk (observed at r17-1725-ge259a182e1f100)
now analyses points-to information more effectively and propagates its
findings, so it sees the function modifies some global state, concludes
that can't be possible (because of the const attribute), and deletes
the stores.

pure unfortunately is unsuitable for *_get_type too as it has a side-effect
(writes to global memory).

Mesa had a similar issue which I fixed recently [0]. glib and glibmm likely
want the (not-yet-implemented) 'idempotent' attribute instead [1]. In fact,
this exact problem is what motivated that request! :)

ebassi mentions an alternative to the current setup as well, using
atomics [2].

This problem has gone back many years but the compiler has finally
fully outsmarted us here, so give in.

[0] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/42361
[1] https://gcc.gnu.org/PR32911
[2] https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4249#note_2583110

Fixes: https://gitlab.gnome.org/GNOME/glib/-/work_items/3984
Signed-off-by: Sam James <sam@gentoo.org>
2026-06-25 17:23:46 +01:00
Christian Hergert
8610cceac8 gobject/gclosure: add GTypeInstance support to generic marshaller
This commit extends the generic marshaller to support parameter and
return types that are custom GTypeInstance. This can be useful for
situations where writing a custom marshaller is impractical or lacks the
necessary plumbing to do so, such as <closure/> in GtkExpression defined
from UI files.

Fixes: #3954
2026-05-15 16:29:51 +02:00
Maximiliano Sandoval
b6845dde24 gtype: Improve G_DEFINE and G_DECLARE docs
The improved docstrings where for:

- G_DECLARE_FINAL_TYPE
- G_DEFINE_FINAL_TYPE
- G_DECLARE_DERIVABLE_TYPE
2026-04-11 12:07:15 +02:00
Emmanuele Bassi
fe604c4d15 docs: Linkify g_signal_emit in GSignalFlags 2026-03-29 16:01:09 +01:00
Emmanuele Bassi
3dfc30f80d docs: Make GSignalFlags descriptions consistent
Don't use "object method handler", and use default signal handler
instead.
2026-03-29 16:01:09 +01:00
Philip Withnall
e7525d0e41 tests: Adapt the param tests for the new GObject construct error message
Commit 18fbb182e8 changed the error
message for some conflicting GObject pspec flags, but the tests were not
updated to follow it. This wasn’t noticed because these tests are only
run with `-m thorough` as they’re a bit slow, so they only run weekly.
But we haven’t been noticing weekly CI run failures because the GitLab
issue-bot to report those failures has been broken for a long time. 😩

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-03-11 17:20:23 +00:00
Philip Withnall
d0162b385a tests: Fix a couple of typos in a comment in param test
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-03-11 15:59:36 +00:00
Philip Withnall
73c76439e0 gobject: Disable new construct property check with G_DISABLE_CHECKS
Just as all the other checks are disabled by virtue of
`g_return_val_if_fail()` being a no-op with `G_DISABLE_CHECKS`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-03-11 15:58:55 +00:00
depuc8
c86b3600fb gobject: Refactor nested assertions in property validation
Convert 'if (A) g_return_if_fail (B)' to 'g_return_if_fail (!A || B)'
for better consistency and improved assertion messages.
2026-03-09 17:58:21 +05:30
depuc8
18fbb182e8 gobject: Add warning for conflicting GParamSpec flags
Add a g_critical() warning when G_PARAM_CONSTRUCT and G_PARAM_CONSTRUCT_ONLY
are set simultaneously on a property
Closes #3730
2026-03-09 17:58:21 +05:30
Roberto Vidal
d9452bcc50 Minor documentation Markdown/gi-docgen fixes
* Markdown rendering breaks in a few places due to
  unescaped asterisks.
* A few intra-docs references are not being picked by
  gi-docgen.
2026-02-26 14:14:30 +00:00
Philip Withnall
6ce2b90c31 Merge branch 'wip/monster/gvalue-docs' into 'main'
gvalue: Update default terminology to initial

See merge request GNOME/glib!5028
2026-02-23 12:13:13 +00:00
Rudi Heitbaum
a9a9906537 Fix const qualifiers where discarded
This patch fixes several const qualifiers by adjusting where required.

Since glibc-2.43 and ISO C23, the functions bsearch, memchr, strchr,
strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr
that return pointers into their input arrays now have definitions as
macros that return a pointer to a const-qualified type when the input
argument is a pointer to a const-qualified type.

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-23 11:44:02 +00:00
Jamie Gravendeel
d026dc87ed gvalue: Update default terminology to initial
"default" can be confusing when comparing GValue to GParamSpec.

As a result, we chose to use "initial" as a term instead of "default" in
GTK. See: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/9461

This updates the docs to match that decision.
2026-02-16 15:53:49 +01:00
Philip Withnall
f5f20b71da Merge branch 'compilation-fixes' into 'main'
Compilation fixes for CLangCL and older MSVC

See merge request GNOME/glib!5012
2026-02-10 19:18:53 +00:00
Philip Withnall
1472ac76b4 Merge branch 'test-subprocess-timeouts' into 'main'
tests: Remove arbitrary timeouts in subprocesses

Closes #3877

See merge request GNOME/glib!5017
2026-02-10 18:38:38 +00:00
Luca Bacci
9649b8190f tests/gobject: Fix -Wcast-function-type-mismatch warning
Test objects-refcount1 is built with -Werror (see !3139).
This causes a compilation failure on clang-cl:

  glib/gobject/tests/objects-refcount1.c(64,7):
  error: cast from 'void (*)(GTestClass *)' (aka 'void (*)(struct _GTestClass *)')
  to 'GClassInitFunc' (aka 'void (*)(void *, void *)') converts to incompatible
  function type [-Werror,-Wcast-function-type-mismatch]
     64 |       (GClassInitFunc) my_test_class_init,
        |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2026-02-10 19:33:36 +01:00
Luca Bacci
3293d4a9d8 tests: Remove arbitrary timeouts in subprocesses
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3877
2026-02-10 19:13:57 +01:00
Luca Bacci
84931d5926 Use test-profile-dep in tests 2026-01-30 12:07:21 +01:00
badcel
ee5ff43425 gobject: Add nullable annotation to g_weak_ref_get return value 2026-01-22 22:32:13 +01:00
Philip Withnall
9a73fa5453 gobject: Enable -Wshorten-64-to-32 warnings for gobject
All the extent warnings in this library have been fixed, so we can now
enable the warning flag to prevent new ones being added in future.

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

Helps: #3527
2025-12-26 20:47:22 +00:00
Philip Withnall
de137f455a tests: Fix a couple of signal connection ID variables in gobject tests
`unsigned long` for signal *connection* IDs, `unsigned int` for signal
IDs.

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

Helps: #3527
2025-12-26 20:47:12 +00:00
Philip Withnall
99e7e683b2 gtype: Fix width of some array iteration variables
Use `size_t` for array indexing.

This fixes a `-Wshorten-64-to-32` warning, but it would have been
practically impossible to hit this as a bug in practice.

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

Helps: #3527
2025-12-26 20:47:08 +00:00
Philip Withnall
a30dffc273 gobject: Add restriction on number of construct properties
The `GObjectClass.n_construct_properties` member is of type `size_t`,
which is correct. However, it’s passed to `GObjectClass.constructor()`,
which takes an `unsigned int`. So in practice its maximum value is
`UINT_MAX`.

Add documentation and an assertion to check that, since it’s public API
and can’t be changed.

In practice, we don’t expect any code to come anywhere near this, but
it’s good to be correct (and this silences a `-Wshorten-64-to-32`
warning).

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

Helps: #3527
2025-12-26 20:47:03 +00:00
Philip Withnall
097668ada6 gobject: Fix storage location size for GObject signal IDs
This was too wide, which was harmless but unnecessary.

Confusingly, signal IDs are `unsigned int`, but signal *connection* IDs
are `unsigned long`.

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

Helps: #3527
2025-12-26 20:46:59 +00:00
Philip Withnall
6416656ed3 genums: Add explicit casts for enum/flags marshalling with GValue
For historic reasons (probably to try and support enums with more than
32 values), enums and flags are stored in the `long` field of a `GValue`.

This is fine, but it triggers a load of `-Wshorten-64-to-32` warnings.
Add some explicit casts to silence those warnings. I don’t think we can
do any better for the implementation anyway. This doesn’t change the
behaviour from before, it just makes the implicit casts explicit.

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

Helps: #3527
2025-12-26 20:46:55 +00:00
Philip Withnall
c253a124d4 gclosure: Fix 64-vs-32 bit integer storage sizes
Fix an array iteration to correctly use `size_t`, and add an assertion
to check the number of arguments passed to libffi is not too many to
overflow its argument (which is, unfortunately, an `unsigned int` rather
than a `size_t`).

Neither of these are real bugs, but fixing the warnings means we can
enable the warning flag permanently to catch actual bugs in future.

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

Helps: #3527
2025-12-26 20:46:50 +00:00
Philip Withnall
44fa86367e gbinding: Fix storage location size for signal connection IDs
As spotted by `-Wshorten-64-to-32`, the signal connection IDs were being
stored in an `int` rather than a `long`, which could truncate them if
the application has a lot of signals connected.

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

Helps: #3527
2025-12-26 20:46:46 +00:00
Marco Trevisan (Treviño)
1fe7474e54 gsignal: Steal the handler from hash table on disconnection
Instead of looking up for an handler and remove it later, just do it in
one operation, avoiding an unneeded extra-lookup every time we
disconnect an handler
2025-12-16 19:52:11 +01:00
Marco Trevisan (Treviño)
12a2c034df gsignal: Split the handler lookup function in two different cases
We may lookup an handler by its ID or by a closure, never by both.

Thus there's no reason to have a function with two cases when they are
very different ones.

So let's just split it in two cases, allowing some simplification
2025-12-16 19:52:11 +01:00
Marco Trevisan (Treviño)
1fa8636145 gsignal: Do not bother lookup a 0 handler ID to see if it's connected
This may currently happening during the gsettings binding destruction
and in this case we end up looking up for a NULL closure with a 0
handler ID for no reason, while we can just do an early return
2025-12-16 19:52:02 +01:00
Marco Trevisan (Treviño)
4504e4abdd gsignal: Drop the handler ID check on lookup search by closure
If we end up being here, it means that the handler_id is 0, and thus the
closure pointer is the only thing we should check
2025-12-16 02:44:26 +01:00