Commit Graph

32174 Commits

Author SHA1 Message Date
Philip Withnall
05193cdd4d Merge branch 'th/gobj-drop-bit-lock' into 'main'
[th/gobj-drop-bit-lock] gobject: drop object_bit_lock() functions

See merge request GNOME/glib!4641
2025-05-20 17:39:33 +00:00
Philip Withnall
7eba311448 2.85.0
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.85.0
2025-05-20 18:24:14 +01:00
Thomas Haller
51dd935202 gobject: drop object_bit_lock() functions
These functions are unused. The per-object bitlock OPTIONAL_FLAG_LOCK
was replaced by using GData's lock and g_datalist_id_update_atomic().

Note that object_bit_lock() was originally introduced to replace global
locks for GObject so that all locks were per-object. Now this lock is
also dropped, and we only use the (per-object) GData lock.

When we introduced object_bit_lock(), we also added optional-flags on
32bit (see HAVE_OPTIONAL_FLAGS_IN_GOBJECT). These flags are still
useful, to have also on x86, so we keep them even if the original user
is gone now.
2025-05-20 18:29:08 +02:00
Philip Withnall
9dc2028c32 Merge branch 'th/gobj-toggle-ref-lock' into 'main'
[th/gobj-toggle-ref-lock] drop object bitlock for toggle references

Closes #3693

See merge request GNOME/glib!4624
2025-05-20 16:10:14 +00:00
Philip Withnall
fb0f3820a1 Merge branch 'atomic-gpointer-annotations' into 'main'
Mark pointer as (type gpointer)

See merge request GNOME/glib!4599
2025-05-20 16:05:15 +00:00
Philip Withnall
fc79ee45ec Merge branch 'android_no_faccessat' into 'main'
glocalfile: Disable faccessat()-based query_exists on Android

See merge request GNOME/glib!4620
2025-05-20 15:14:40 +00:00
Thomas Haller
e6a1e78029 gobject: drop OPTIONAL_BIT_LOCK_TOGGLE_REFS lock
It was replaced by the GData lock and g_datalist_id_update_atomic().

Note that we introduced object_bit_lock() to replace global mutexes.
Now, object_bit_lock() is also replaced, by using the GData lock via
g_datalist_id_update_atomic().

This means, all mutex-like locks on the GObject now go through the GData
lock on the GObject's qdata.

For the moment, the object_bit_lock() API is still here and unused. It
will be dropped in a separate commit.
2025-05-20 16:40:49 +02:00
Thomas Haller
588dbc569d gobject: rework g_object_remove_toggle_ref() to use g_datalist_id_update_atomic() 2025-05-20 16:40:49 +02:00
Thomas Haller
f438ef6802 gobject: rework g_object_add_toggle_ref() to use g_datalist_id_update_atomic() 2025-05-20 16:40:49 +02:00
Thomas Haller
2fe2f2f9b7 gobject: rework toggle_refs_check_and_ref() to use g_datalist_id_update_atomic()
This is the first step to drop OPTIONAL_BIT_LOCK_TOGGLE_REFS lock. That
will happen soon after.

Note that toggle_refs_check_and_ref_or_deref() is called from
g_object_ref()/g_object_unref(), when the ref count toggles between 1
and 2 and called frequently. Also consider that most objects have no
toggle references and would rather avoid the overhead.

Note that we expect that the object has no toggle references. So the
fast path only takes a g_datalist_lock() first, updates the ref-count
and checks OBJECT_HAS_TOGGLE_REF(). If we have no toggle reference, we
avoid the call to g_datalist_id_update_atomic() -- which first needs to
search the datalist for the quark_toggle_refs key.

Only if OBJECT_HAS_TOGGLE_REF(), we call g_datalist_id_update_atomic().
At that point, we pass "already_locked" to indicate that we hold the
lock, and avoid the overhead of taking the lock a second time.

In this commit, the fast-path actually gets worse. Because previously we
already had the OBJECT_HAS_TOGGLE_REF() optimization and only needed the
object_bit_lock(). Now we additionally take the g_datalist_lock(). Note
that the object_bit_lock() will go away next, which brings the fast path
back to take only one bit lock. You might think, that the fast-path then
is still worse, because previously we took a distinct lock
object_bit_lock(), while now even more places go through the GData lock.
Which theoretically could allow for higher parallelism, by taking different
locks. However, note that in both cases these are per-object locks. So
it would be very hard to find a usage where previously higher
parallelism was achieved due to that (e.g. a concurrent g_weak_ref_get()
vs toggling the last reference). And that is only the fast-path in
toggle_refs_check_and_ref_or_deref(). At all other places, we soon will
take one lock less.

This also fixes a regression of commit abdb58007a ('gobject: drop
OPTIONAL_BIT_LOCK_NOTIFY lock'). Note the code comment in
toggle_refs_check_and_ref_or_deref() how it relies to hold the same lock
that is also taken while destroying the object. This was no longer the
case since OPTIONAL_BIT_LOCK_NOTIFY lock was replaced by GData lock.
This is fixed by this commit, because again the same lock is taken.

Fixes: abdb58007a ('gobject: drop OPTIONAL_BIT_LOCK_NOTIFY lock')
2025-05-20 16:40:49 +02:00
Thomas Haller
61aa0c3ace gdataset: add "already_locked" argument to g_datalist_id_update_atomic()
This allows the caller to take the lock on the GData first, and perform
some operations.

This is useful under the assumption, that the caller can find cases
where calling g_datalist_id_update_atomic() is unnecessary, but where
they still need to hold the lock to atomically make that decision.

That can avoid performance overhead, if we can avoid calling
g_datalist_id_update_atomic(). That matters for checking the
toggle-notify in g_object_ref()/g_object_unref().

Note that with "already_locked", g_datalist_id_update_atomic() will
still unlock the GData at the end. That is because the API of
g_datalist_id_update_atomic() requires that it might re-allocate the
buffer, and it can do a more efficient unlock in that case, instead of
leaving it to the caller. The usage and purpose of this parameter is
anyway special, so the few callers will be fine with this asymmetry.
It can safe an additional atomic operation to first set the buffer and
then do a separate g_datalist_unlock().
2025-05-20 16:40:47 +02:00
Thomas Haller
d3e0b3620a gdataset: expose g_datalist_lock()/g_datalist_unlock() as private API
g_datalist_id_update_atomic() allows to use GData's internal look and
perform complex operations on the data while holding the lock.

Now, also expose g_datalist_{lock,unlock}() functions as private API.

That will be useful, because g_datalist_id_update_atomic() and GData's
lock is the main synchronization point for GObject. By being able to
take those locks directly, we can perform operations without having to
also look up GData key.
2025-05-20 16:39:45 +02:00
Philip Withnall
25677d10bf Merge branch '3616-action-map-docs' into 'main'
gactionmap: Fix broken link in documentation comment

Closes #3616

See merge request GNOME/glib!4505
2025-05-20 14:35:17 +00:00
Philip Withnall
e15bb80af4 Merge branch 'th/gdataset-fix-zero-key' into 'main'
[th/gdataset-fix-zero-key] fix and cleanup related to using a zero GQuark for keys in GData

See merge request GNOME/glib!4628
2025-05-20 14:17:46 +00:00
Colin Kinloch
06602315c3 glocalfile: Disable faccessat()-based query_exists on Android
The bionic version of faccessat() returns EINVAL when flags are set.

See 35778253a5
2025-05-20 15:00:02 +01:00
Philip Withnall
546bf019f9 Merge branch 'main' into 'main'
gmessages: add `SYSLOG_IDENTIFIER` to structured logs using select functions

Closes #3656

See merge request GNOME/glib!4589
2025-05-20 13:52:54 +00:00
Thomas Haller
8434618129 gdataset: correctly handle NULL string in g_datalist_get_data()
All code that adds an entry to GData calls down to datalist_append().
No caller would never pass a zero key_id. So a GData will never contain
the zero GQuark.

g_datalist_get_data() allows to lookup the keys by string. Looking up
by string, only makes sense if the string is a valid GQuark. And the
NULL string is not a valid GQuark (or, in another interpretation is to
say that the GQuark of NULL is zero). In any case, the GData does not
contain the zero quark and it should never find a NULL string there.

Note however that you can add invalid (non-zero) GQuarks to GData. That
is because we avoid the overhead of checking that the non-zero key_is is
infact a valid GQuark. Thus, if you called

  g_datalist_get_data(&data, NULL)

the check

  if (g_strcmp0 (g_quark_to_string (data_elt->key), key) == 0)

would have found entries where the key is not a valid GQuark.

Fix that. Looking up a NULL string should never finds an entry.

Fixes: f6a9d04796 ('GDataSet: silently accept NULL/0 as keys')
2025-05-20 15:37:36 +02:00
Thomas Haller
88688b1ae5 gdataset/tests: add another test for GData 2025-05-20 15:37:36 +02:00
Thomas Haller
7a1dfea458 gdataset: check for valid key before taking lock
In g_dataset_id_remove_no_notify() and g_dataset_id_get_data(), check
first the argument before taking a lock.

Note that this doesn't matter much for g_dataset_id_get_data(). We could
leave the check as it was or drop it altogether. That is because
g_dataset_id_get_data() calls g_datalist_id_get_data(), which is fine
with a zero key_id. Also, passing a zero key is not something that would
somebody to normally, so the check is not necessary at all. I leave the
check for consistency with g_dataset_id_remove_no_notify() and do the
change for the same reason as there.

However, the check for key matters for g_dataset_id_remove_no_notify().
That function calls g_data_set_internal(), which must not be called with
zero key.

At this point, it seems a code smell to perform the check after taking
the lock. Something you notice every time that you look at it, and while
technically no problem, it is ugly. Hence the change.
2025-05-20 15:37:36 +02:00
Thomas Haller
8a273a7a3e gdataset: add assertions that we never add a zero key
All public API already ensures that this cannot ever happen.

The assertion is only for the reviewer and ease of mind.
2025-05-20 15:37:36 +02:00
Thomas Haller
8df7da0cc2 gdataset: drop "Since" annotation from internal g_datalist_id_update_atomic()
This is internal API, and is only used via GLIB_PRIVATE_CALL(). Such
private API is not stable. That is, you must use the same version of
e.g. libgobject and libglib.

In that case, the "Since" annotation makes no sense.
2025-05-20 15:37:36 +02:00
Thomas Haller
75ea33be11 gdataset: check arguments of g_datalist_id_update_atomic()
g_datalist_id_update_atomic() is internal API only, and all callers
(supposedly) get this right.

Add assertions for these requirements.
2025-05-20 15:37:36 +02:00
Axel Karjalainen
8153cd8551 gmessages: add SYSLOG_IDENTIFIER to structured logs using select functions
Fixes #3656
2025-05-20 13:19:07 +01:00
Philip Withnall
c697f682a6 Merge branch 'wip/jtojnar/fix-macros-doc-syntax' into 'main'
docs: Fix formatting of definition lists

See merge request GNOME/glib!4638
2025-05-20 09:49:01 +00:00
Michael Catanzaro
7c7d7c6c78 Merge branch 'wip/finaw/search-prefer-early-tokens' into 'main'
gdesktopappinfo: Prefer matches that occur earlier in the match string

See merge request GNOME/glib!4369
2025-05-19 10:51:28 -05:00
Luca Bacci
01454b823b Rework Windows implementation of g_getenv()
Fixes the following issues:

1. g_getenv didn't properly differentiate between non-exisiting variables
   and variables with empty values. This happened bacause we didn't call
   SetLastError (0) before GetEnvironmentVariable (as with most APIs,
   GetEnvironmentVariable doesn't set the error code to 0 on success).

2. g_getenv called GetEnvironmentVariable, g_free, and GetLastError in sequence;
   the call to g_free could change the last error code.

3. We can use the looping pattern to call APIs that return the required buffer
   size. The looping pattern makes the two phases (get size and retrieve value)
   appear as just one call. It's also important for values that can change at any
   time like environment variables [1].

[1] https://devblogs.microsoft.com/oldnewthing/20220302-00/?p=106303
2025-05-19 10:27:50 +02:00
Fina Wilke
b36e646b54 gdesktopappinfo: Prefer matches that occur earlier in the match string
Some apps names or keywords contain multiple words. For example 'LibreOffice
Calc' contains the word 'Calc'. This is rightfully detected as a prefix match,
however generally it is expected that searching for 'calc' would consistantly
return 'Calculator' in first position, instead of ranking them equally.

We now prioritise tokens that would otherwise rank equal based on where they
occur in the string, giving earlier occurences precedence.
2025-05-17 15:43:13 +02:00
Jan Tojnar
ec19c0c6b5 docs: Fix formatting of definition lists
Definitions in definition lists in most markdown implementations,
including the GitLab one, support laziness for the definition text
(https://spec.commonmark.org/0.31.2/#lazy-continuation-line).
As a result, each defined term would be collapsed into preceding definition.
To fix this, definitions need to be separated by blank line.
2025-05-16 21:43:34 +02:00
Philip Withnall
39b5613e73 Merge branch 'glib-merge-request-main' into 'main'
gmain: Mark several GSourceFuncs members as nullable

Closes #3686

See merge request GNOME/glib!4636
2025-05-14 17:03:16 +00:00
Michael Catanzaro
290d90473d Merge branch 'gzlib-docs' into 'main'
gzlibcompressor: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4633
2025-05-14 11:35:03 -05:00
BZZZZ
4b938fc34b gmain: Mark several GSourceFuncs members as nullable
Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3686
2025-05-14 17:30:50 +01:00
Philip Withnall
696c03ea4d Merge branch 'key_file_non_existent_key' into 'main'
docs: Non-existent group name/key passed to g_key_file_set_comment

Closes #490

See merge request GNOME/glib!4635
2025-05-14 16:22:59 +00:00
marklkram
6d1a820340 docs: Non-existent group name/key passed to g_key_file_set_comment
Specifies that passing a non-existent group name/key to g_key_file_set_comment returns an error.

Closes #490
2025-05-14 11:42:53 -04:00
Philip Withnall
843779903c Merge branch 'socket_address_native_size' into 'main'
docs: Description of return value of get_native_size

Closes #2377

See merge request GNOME/glib!4625
2025-05-14 10:44:20 +00:00
Philip Withnall
13a73f9008 gzlibcompressor: Convert docs to gi-docgen linking syntax
Improve formatting while I’m there, and try and ensure all the docs in
these two files matches the
[guidelines](https://developer.gnome.org/documentation/guidelines/devel-docs.html#writing-api-references).

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

Helps: #3250
2025-05-14 11:38:05 +01:00
Philip Withnall
997c41b648 Merge branch 'wip/otte/zlib-os' into 'main'
gio: Add GZlibCompressor:os property

Closes #3663

See merge request GNOME/glib!4597
2025-05-14 10:20:01 +00:00
Philip Withnall
e5fd9c42ff Merge branch 'wip/otte/win32-version' into 'main'
win32: Only print one OS version

See merge request GNOME/glib!4632
2025-05-14 09:20:09 +00:00
Benjamin Otte
4cc75b144c win32: Only print one OS version
Exit the version-checking loop after the first successful check instead
of trying again.
2025-05-14 10:22:54 +02:00
Philip Withnall
d6beb02518 Merge branch 'de-translation' into 'main'
Update German translation

See merge request GNOME/glib!4631
2025-05-13 12:06:20 +00:00
Philip Withnall
cb4d8e02e2 Merge branch 'zbrown/galloc-docs' into 'main'
gallocator: mark as deprecated

See merge request GNOME/glib!4621
2025-05-13 12:00:50 +00:00
Philipp Kiemle
ff3b7f0600 Update German translation 2025-05-12 18:18:43 +02:00
Benjamin Otte
f5b0415539 gio: Add GZlibCompressor:os property
The use case for exposing this field is GTK wanting reproducible
encoding output across different OSes.

I decided to expose the OS as an integer because zlib uses an int
in its header and does not make its OS codes available as a custom
type in its API.

I also decided to limit it to values between 0 and 255 because zlib
encodes the OS as a single byte.

Test included.

Fixes: #3663
2025-05-12 09:07:57 +02:00
Michael Catanzaro
314d63fcf7 Merge branch 'simultaneous-main-context-source-destruction' into 'main'
glib: add a proper weak-ref-like relationship between GSource and GMainContext

Closes #803

See merge request GNOME/glib!2187
2025-05-11 09:31:21 -05:00
marklkram
c0c0e212d9 docs: Description of return value of get_native_size
Specified that if the user passes an invalid address, the function returns -1.

closes #2377
2025-05-10 22:28:18 -04:00
Matthew Waters
a235350bc0 source: minimise direct access to source->context
Doing so can cause a use-after-free as the main context referenced can
be destroyed by another thread freeing the GMainContext.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/803
2025-05-11 10:40:10 +10:00
Matthew Waters
9251e99cdc glib: add a proper weak-ref-like relationship between GSource and GMainContext
Like the GWeakRef's in GObject, there is a global lock that is consulted
whenever g_main_context_unref() or g_source_destroy() or
g_source_unref() is called to retrieve a reference to the associated
GMainContext.

There are a number of actual races that are fixed by this change.
1. Racing GSource destruction with g_main_context_unref() is solved
   by holding the global source_weak_locations lock while setting
   source->context = NULL and while g_source_destroy() attempts to
   retrieve source->context;
2. Same race as 1. but inside g_source_unref()
3. Theoretical race of double freeing the contents of
   context->pending_dispatches if both g_source_destroy() and
   g_main_context_unref() both free resources inside g_main_context_unref().

A couple of implementation notes:
1. Unlocking source_weak_locations too early in g_main_context_unref()
   (before g_source_destroy_internal() is called) may have a race of the
   G_HOOK_FLAG_ACTIVE state of the source and cause a leak of the source.
   This is why source_weak_locations is also held over the calls to
   g_source_destroy_internal() in g_main_context_unref().  So that
   either g_main_context_unref() or g_source_destroy() (but only 1) has
   the chance to free the resources associated with the GMainContext.
2. g_main_context_unref() now needs to be more of a dispose()
   implementation as it can be called multiple times with losing the
   last ref.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/803
2025-05-11 10:40:10 +10:00
Michael Catanzaro
93073ec317 Merge branch 'th/revert-weakref-change' into 'main'
Revert "Merge branch 'th/gobj-doc-weakref' into 'main'"

Closes #3684

See merge request GNOME/glib!4629
2025-05-09 14:05:45 -05:00
Thomas Haller
3cf6d22f76 Revert "Merge branch 'th/gobj-doc-weakref' into 'main'"
This change appears to cause crashes. Revert for now, to investigate why
exactly that happens.

This reverts commit 22f57fce78, reversing
changes made to 549a966b46.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/3684
See-also: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4584#note_2436512
See-also: https://gitlab.gnome.org/GNOME/gnome-builder/-/issues/2324
2025-05-09 20:34:18 +02:00
Zander Brown
cff415f221 gallocator: mark as deprecated
These show up in various places in docgen-based docs, including in
results for fairly common searches (such as ‘alloc’). Whilst people
should have been scared off by these being undocumented, the red
deprecated tags make it clear these shouldn't be touched.
2025-05-09 15:48:40 +01:00
Michael Catanzaro
3674b4a805 Merge branch 'th/gsignalgroup-dispose' into 'main'
[th/gsignalgroup-dispose] gsignalgroup: make GSignalGroup.dispose() a bit more reentrant

See merge request GNOME/glib!4627
2025-05-08 19:51:22 +00:00