31358 Commits

Author SHA1 Message Date
Philip Withnall
05c7f11306 Merge branch 'th/datalist-update-atomic-no-keyid' into 'main'
[th/datalist-update-atomic-no-keyid] gdataset: drop "key_id" argument from GDataListUpdateAtomicFunc

See merge request GNOME/glib!4508
2025-02-21 15:30:25 +00:00
Thomas Haller
6ce489bf83 gdataset: drop "key_id" argument from GDataListUpdateAtomicFunc
None of the users actually care about this parameter. And it's unlikely
that they ever will. Also, the passed "key_id" is the argument from
g_datalist_id_update_atomic(). If the caller really cared to know the
"key_id" in the callback, they could pass it as additional user data.
2025-02-21 15:24:51 +01:00
Philip Withnall
b4224a5d6d Merge branch 'th/gdataset-misc' into 'main'
[th/gdataset-misc] minor improvements in gdataset.c (around g_datalist_id_remove_multiple())

See merge request GNOME/glib!4507
2025-02-21 12:47:57 +00:00
Thomas Haller
70623887ad gdataset: avoid initializing "out_idx" if datalist_find() fails
In some sense, it might be desirable to always initialize out parameters
to something.

However, this fallback index G_MAXUINT32 is not really useful for any
caller. That is, no caller can blindly access the index without checking
whether datalist_find() found (and returned) an entry.

Also, a caller cannot check for whether a entry was found via `if (idx
== G_MAXUINT32)`, because that theoretically is also a valid index.

The only sensible way to use datalist_find() is by accessing "idx"
if-and-only-if an entry was found. And all callers did that.

There is no point for initializing the value.

Uninitialized values can be even preferable over a non-useful
initialization to G_MAXUINT32, because if there is a buggy access them
under valgrind, there will be at least a warning.
2025-02-21 11:09:29 +01:00
Thomas Haller
3024d9b47e gdataset: remove/inline internal function g_data_remove_internal()
This internal function only had one caller. Drop it.
2025-02-21 11:09:29 +01:00
Thomas Haller
82977db352 gdataset/trivial: adjust obsolte code comment
The code comment was no longer correct. g_data_remove_internal() does
not depend on this anymore. It also just calls datalist_find(), which
searches the entire list.
2025-02-21 10:00:45 +01:00
Thomas Haller
76d77d1cab gdataset: avoid initializing temporary array with NULL in g_data_remove_internal()
The code comment was correct in the past, and how the code was then we
had to ensure the array is initialized.

This is no longer the case. We will only access the array at the indexes
from zero to up to (found_keys-1). And those places get always
initialized before we use them (as we increment found_keys at the same
time).

There is no longer a need to initialize this array to zero. Drop this.

Fixes: 3437414dd4f7 ('gdataset: use lookup index in g_datalist_id_remove_multiple()')
2025-02-21 09:55:26 +01:00
Philip Withnall
e35c796e62
2.83.4
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.83.4
2025-02-20 12:37:13 +00:00
Philip Withnall
c753d26b84 Merge branch 'wip/smcv/gdbus-clear-signal' into 'main'
gdbus: Add g_clear_dbus_signal_subscription() inline convenience function

See merge request GNOME/glib!4493
2025-02-20 00:48:33 +00:00
Simon McVittie
030fbca6c2 gdbus: Add g_clear_dbus_signal_subscription() inline convenience function
This is like g_clear_signal_handler(), but for GDBus signal subscriptions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-20 00:10:02 +00:00
Philip Withnall
0b08232416 Merge branch 'mcatanzaro/mr4206-followup' into 'main'
gcancellable: remove sketchy source ref/unref

See merge request GNOME/glib!4477
2025-02-19 23:32:27 +00:00
Philip Withnall
3a4beabc29 Merge branch 'wip/3v1n0/gmain-more-atomic' into 'main'
gmain: Use atomic logic to handle internal GSource flags

See merge request GNOME/glib!4488
2025-02-19 23:27:51 +00:00
Marco Trevisan (Treviño)
14da9d459c gio/tests/cancellable: Actually init atomic values with atomic functions
This is to make thread sanitizer happy, even those aren't really issues.
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
ee836d7723 gmain: Use atomic logic to init the ref counting
Ensure we're consistent with the field usage
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
42283ffb45 gmain: Use atomic logic to set and use dispose function
It can be read/written in a racy way, so let's be safer.
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
a5bc497021 gmain: Use atomic logic to handle internal GSource flags
We use flags in both locked paths and in public ones (to check if a
source is destroyed or running), but those checks are not using atomic
logic, thus they lead to races in various tests.

Fix them by atomically change and read the values.
And this fixes various tests in thread sanitizer.
2025-02-19 19:36:21 +01:00
Marco Trevisan
30fbe0e859 Merge branch 'wip/3v1n0/gmain-source-reffing-fixes' into 'main'
glib/gmain: Avoid potential dispose race on GSource due to refcount dance

Closes #3612

See merge request GNOME/glib!4501
2025-02-19 18:26:19 +00:00
Marco Trevisan (Treviño)
7097359597 gmain: Ensure old reference is valid during unref
We were checking this already, leading to an extra atomic read that
isn't needed.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
5d117b021a gmain: Avoid unneeded atomic read on GSource ref
In g_source_ref() we can just ensure that the value we've referenced was
valid, instead of checking it before, since if get to such state the
GSource is broken anyways, but at least we can avoid doing an unneeded
atomic read.

Reason why we don't bother resetting the reference in case of failure.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
6052374c78 gmain: Go back to using the standard unref logic if the final unref failed
If going from 1 -> 0 references failed, then we should restart the unref
process, by potentially re-entering in the dispose function again if
instead something else re-references us and we're going to drop the last
one again.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
7b61cc8277 glib/gmain: Avoid potential dispose race on GSource due to refcount dance
During g_source_unref() we might end up calling dispose from
multiple threads, and due to the ref/unref dance we were doing we could
end up initiating a GSource finalization while another thread was about
to revive the source.

This was because we were unreffing a source in a thread, and potentially
re-reffing it, at the same time, but it was not guaranteed that the
final decrement and test couldn't be followed by a further re-ref.

To avoid this, do not do any ref/unref/re-ref/re-unref dance while we're
about to dispose, but instead follow a bit more the g_object_unref()
logic, and start the disposal phase only if we're about to drop the last
reference, and only after the potential disposal call is done, we do an
actual ref count decrement, which may lead to the finalization or not.

We don't bother following the same logic at later point, since after
disposal we should really have just one thread running and revival of a
finalizing GSource isn't supported anyways.

With this logic we can also avoid doing unneeded context locking when
we've enough references on a GSource that disposal is unlikely to
happen.

Closes: #3612
2025-02-19 18:59:33 +01:00
Philip Withnall
01289dd242 Merge branch 'gwin32-com-free-cpp-fix' into 'main'
gwin32.h: Avoid including unknwn.h

Closes #3613

See merge request GNOME/glib!4502
2025-02-19 13:22:03 +00:00
Chun-wei Fan
d920a86e25 gwin32.h: Avoid including unknwn.h
It pulls in windows.h causing conflict for code that assume windows.h is not
previously included.

Thanks to Luca Bacci for proposing this fix, and @Osyotr for pointing
out this issue!

Fixes issue #3613.
2025-02-19 20:52:01 +08:00
Philip Withnall
67a2f8c593 Merge branch '3560-register-object-with-closures' into 'main'
gdbusconnection: Add g_dbus_connection_register_object_with_closures2() API

Closes #3560

See merge request GNOME/glib!4431
2025-02-18 18:45:03 +00:00
Marco Trevisan
c8a81f1b8e Merge branch 'date-time-iso8601-overflow' into 'main'
gdatetime: Fix integer overflow when parsing very long ISO8601 inputs

See merge request GNOME/glib!4498
2025-02-18 18:44:56 +00:00
Philip Withnall
cbd5c9b3cc
tests: Add some missing GDateTime ISO8601 parsing tests
This improves test coverage, adding coverage for some lines which I
spotted were not covered while testing the preceding commits.

It doesn’t directly test the preceding commits, though.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 18:20:56 +00:00
Philip Withnall
0ffdbebd9a
gdatetime: Factor out an undersized variable
For long input strings, it would have been possible for `i` to overflow.
Avoid that problem by using the `tz_length` instead, so that we count up
rather than down.

This commit introduces no functional changes (outside of changing
undefined behaviour), and can be verified using the identity
`i === length - tz_length`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 17:31:48 +00:00
Philip Withnall
3672764a17
gdatetime: Factor out some string pointer arithmetic
Makes the following code a little clearer, but doesn’t introduce any
functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 17:31:14 +00:00
Philip Withnall
0b225e7cd8
gdatetime: Track timezone length as an unsigned size_t
It’s guaranteed to be in (0, length] by the calculations above.

This avoids the possibility of integer overflow through `gssize` not
being as big as `size_t`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 17:00:51 +00:00
Philip Withnall
2fa1e18361
gdatetime: Fix potential integer overflow in timezone offset handling
This one is much harder to trigger than the one in the previous commit,
but mixing `gssize` and `gsize` always runs the risk of the former
overflowing for very (very very) long input strings.

Avoid that possibility by not using the sign of the `tz_offset` to
indicate its validity, and instead using the return value of the
function.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 16:51:36 +00:00
Philip Withnall
8d60d7dc16
gdatetime: Fix integer overflow when parsing very long ISO8601 inputs
This will only happen with invalid (or maliciously invalid) potential
ISO8601 strings, but `g_date_time_new_from_iso8601()` needs to be robust
against that.

Prevent `length` overflowing by correctly defining it as a `size_t`.
Similarly for `date_length`, but additionally track its validity in a
boolean rather than as its sign.

Spotted by chamalsl as #YWH-PGM9867-43.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 16:44:58 +00:00
Philip Withnall
d705612505 Merge branch 'gsubprocess-test-leak' into 'main'
tests: Fix a minor leak in a new GSubprocess test

See merge request GNOME/glib!4497
2025-02-18 15:22:14 +00:00
Philip Withnall
9d81da62f2
tests: Fix a minor leak in a new GSubprocess test
And also rearrange the asserts so that the error is checked first (since
that’s the more informative failure to receive if the test did fail).

Spotted by Marco in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4494#note_2352013
and by The Machines in
https://gitlab.gnome.org/GNOME/glib/-/jobs/4768121.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-18 15:04:06 +00:00
Philip Withnall
e46d54074b Merge branch 'piotrdrag/pl-translation-250216' into 'main'
Update Polish translation for GNOME 48

See merge request GNOME/glib!4496
2025-02-18 14:30:35 +00:00
Philip Withnall
2c8a044cec Merge branch 'gvolumemonitor_suggest_disco_sigs' into 'main'
gio/gvolumemonitor: Suggest disconnecting signals

See merge request GNOME/glib!4495
2025-02-18 14:30:03 +00:00
Colin Kinloch
6119bb0042 gio/gvolumemonitor: Suggest disconnecting signals
It is easy to overlook that unreffing a GVolumeMonitor doesn't
disconnect signal handlers, this can lead to segfaults from dangling
user data pointers.
2025-02-16 17:33:20 +00:00
Piotr Drąg
385470e970 Update Polish translation 2025-02-16 17:04:41 +01:00
Philip Withnall
4738951270 Merge branch 'gbsneto/fix-gsubprocess-pid' into 'main'
gio/subprocess: Initialize pid variable to 0

See merge request GNOME/glib!4494
2025-02-15 10:12:02 +00:00
Georges Basile Stavracas Neto
14909ffe1e
gio/subprocess: Initialize pid variable to 0
The documentation for g_spawn_async_with_pipes_and_fds() states:

> If an error occurs, child_pid, stdin_pipe_out, stdout_pipe_out, and
> stderr_pipe_out will not be filled with valid values.

Before 2dc3a6f0c80e5a8f786369eee0c45bfe19b55f4f, the `child_pid`
argument was `self->pid`, and GObject zero-initializes structs. So
the pid field was properly initialized to zero.

After 2dc3a6f0c80e5a8f786369eee0c45bfe19b55f4f, however, the out
variable is now declared inside initable_init(), and it's unitialized.
So if g_spawn_async_with_pipes_and_fds() errors out, `pid` will have
trash value in it, and the following assertion will fail:

```
g_assert (success == (pid != 0));
```

Fix that by initializing the `pid` variable to zero. Add a test to
exercise the fail code path, and prevent errors like this in the
future.
2025-02-14 21:20:24 -03:00
Philip Withnall
c5d82f9099 Merge branch 'keyfile-docs' into 'main'
gkeyfile: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4472
2025-02-14 00:56:06 +00:00
Philip Withnall
985cc08d43 Merge branch 'wip/3v1n0/gsubprocess-races-fix' into 'main'
gio/subprocess: Lock while writing on shared pid and status values

See merge request GNOME/glib!4490
2025-02-13 22:17:48 +00:00
Marco Trevisan
2dc3a6f0c8 gio/subprocess: Lock while writing on shared pid and status values
The process PID is initialized by the initable vfunc, while
g_subprocess_exited sets it again, when we're protecting it via a lock.
The status is set when the process exits instead, again while locking.

This makes the thread sanitizer unhappy (even if it shouldn't really be
a race for the PID init case), but still locking during initialization is
not a bad thing to do.

At the same time g_subprocess_wait() and friends were using the pid and status
values without any protection, so let's ensure this is not the case anymore.

WARNING: ThreadSanitizer: data race (pid=8213)
  Write of size 4 at 0x7b200000084c by thread T1:
    #0 g_subprocess_exited ../gio/gsubprocess.c:284
    #1 g_child_watch_dispatch ../glib/gmain.c:5963
    #2 g_main_dispatch ../glib/gmain.c:3373
    #3 g_main_context_dispatch_unlocked ../glib/gmain.c:4224
    #4 g_main_context_iterate_unlocked ../glib/gmain.c:4289
    #5 g_main_context_iteration ../glib/gmain.c:4354
    #6 glib_worker_main ../glib/gmain.c:6553
    #7 g_thread_proxy ../glib/gthread.c:892
  Previous read of size 4 at 0x7b200000084c by main thread:
    #0 g_subprocess_wait ../gio/gsubprocess.c:908
    #1 g_subprocess_wait_check ../gio/gsubprocess.c:939
    #2 end_element ../gio/glib-compile-resources.c:342
    #3 emit_end_element ../glib/gmarkup.c:1045
    #4 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #5 parse_resource_file ../gio/glib-compile-resources.c:578
    #6 main ../gio/glib-compile-resources.c:967
  Location is heap block of size 120 at 0x7b2000000800 allocated by main
  thread:
    #0 calloc <null>
    #1 g_malloc0 ../glib/gmem.c:133
    #2 g_type_create_instance ../gobject/gtype.c:1933
    #3 g_object_new_internal ../gobject/gobject.c:2621
    #4 g_object_new_valist ../gobject/gobject.c:2960
    #5 g_initable_new_valist ../gio/ginitable.c:245
    #6 g_initable_new ../gio/ginitable.c:163
    #7 g_subprocess_newv ../gio/gsubprocess.c:619
    #8 g_subprocess_new ../gio/gsubprocess.c:590
    #9 end_element ../gio/glib-compile-resources.c:334
    #10 emit_end_element ../glib/gmarkup.c:1045
    #11 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #12 parse_resource_file ../gio/glib-compile-resources.c:578
    #13 main ../gio/glib-compile-resources.c:967
  Thread T1 'gmain' (tid=8228, running) created by main thread at:
    #0 pthread_create <null>
    #1 g_system_thread_new ../glib/gthread-posix.c:762
    #2 g_thread_new_internal ../glib/gthread.c:996
    #3 g_thread_new ../glib/gthread.c:949
    #4 g_get_worker_context ../glib/gmain.c:6580
    #5 initable_init ../gio/gsubprocess.c:443
    #6 g_initable_init ../gio/ginitable.c:129
    #7 g_initable_new_valist ../gio/ginitable.c:249
    #8 g_initable_new ../gio/ginitable.c:163
    #9 g_subprocess_newv ../gio/gsubprocess.c:619
    #10 g_subprocess_new ../gio/gsubprocess.c:590
    #11 end_element ../gio/glib-compile-resources.c:334
    #12 emit_end_element ../glib/gmarkup.c:1045
    #13 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #14 parse_resource_file ../gio/glib-compile-resources.c:578
    #15 main ../gio/glib-compile-resources.c:967
SUMMARY: ThreadSanitizer: data race ../gio/gsubprocess.c:284 in
g_subprocess_exited

======================================

WARNING: ThreadSanitizer: data race (pid=15959)
  Read of size 4 at 0x7b200000084c by main thread:
    #0 g_subprocess_wait ../gio/gsubprocess.c:913
    #1 g_subprocess_wait_check ../gio/gsubprocess.c:944
    #2 test_cat_utf8 ../gio/tests/gsubprocess.c:489
    #3 test_case_run ../glib/gtestutils.c:3115
    #4 g_test_run_suite_internal ../glib/gtestutils.c:3210
    #5 g_test_run_suite_internal ../glib/gtestutils.c:3229
    #6 g_test_run_suite ../glib/gtestutils.c:3310
    #7 g_test_run ../glib/gtestutils.c:2379
    #8 main ../gio/tests/gsubprocess.c:2266

  Previous write of size 4 at 0x7b200000084c by thread T1:
    #0 g_subprocess_exited ../gio/gsubprocess.c:284
    #1 g_child_watch_dispatch ../glib/gmain.c:5963
    #2 g_main_dispatch ../glib/gmain.c:3373
    #3 g_main_context_dispatch_unlocked ../glib/gmain.c:4224
    #4 g_main_context_iterate_unlocked ../glib/gmain.c:4289
    #5 g_main_context_iteration ../glib/gmain.c:4354
    #6 glib_worker_main ../glib/gmain.c:6553
    #7 g_thread_proxy ../glib/gthread.c:892
2025-02-13 22:17:48 +00:00
Marco Trevisan
a3d3e3b96e Merge branch 'file-monitor-props-cleanups' into 'main'
gfilemonitor: Various cleanups and minor fixes to property handling

See merge request GNOME/glib!4492
2025-02-13 19:22:44 +00:00
Philip Withnall
f2878327f4
gfilemonitor: Fix value of GFileMonitor:cancelled via g_object_get_property()
It was hard-coded to return `FALSE` for some reason. Fix that.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-13 18:58:30 +00:00
Philip Withnall
06077435c9
gfilemonitor: Emit GObject::notify by pspec rather than property name
This is equivalent, but slightly faster, as it avoids a pspec lookup.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-13 18:57:58 +00:00
Philip Withnall
8ffdbb55d9
gfilemonitor: Install properties all at once
This is a minor performance improvement, since the pspec list for the
class now only has to be modified once, rather than twice.

It also means we now have the `GParamSpec` pointers to hand in a `props`
array, which will be used in the upcoming commits.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-13 18:57:04 +00:00
Philip Withnall
5aa42683ee
gfilemonitor: Use an enum for properties to allow -Wswitch-enum
This lets the compiler tell us if we’ve accidentally missed a property
implementation from `get_property()` or `set_property()`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-13 18:56:04 +00:00
Philip Withnall
40fd0e4759 Merge branch 'wip/3v1n0/gfilemonitor-atomic-cancelled' into 'main'
gio/gfilemonitor: Use atomic API to get / store cancelled state

See merge request GNOME/glib!4487
2025-02-13 18:43:50 +00:00
Philip Withnall
2fab2c38ff Merge branch 'rafaelff/update-pt_BR' into 'main'
Update Brazilian Portuguese translation

See merge request GNOME/glib!4491
2025-02-13 18:39:36 +00:00
Rafael Fontenelle
2e928adfd1 Update Brazilian Portuguese translation 2025-02-13 16:43:55 +00:00