8990 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Marco Trevisan (Treviño)
795a56d623 gio/gfilemonitor: Reorder includes as expected by syntax checker 2025-02-13 15:03:57 +01:00
Marco Trevisan (Treviño)
175e02f15c gio/gfilemonitor: Do not mark the filemonitor cancelled until vfunc is done
As per previous commit we used atomic logic to handle the cancellation,
but that lead to a slightly different behavior because the file monitor
was then marked as cancelled before the vfunc implementation was called.

Use similar behavior now (by still relying on the atomic logic), by
marking the state as about-to-cancel as soon as we're starting the
cancellation (preventing other threads to cancel it), and eventually
fully marking it as cancelled.
2025-02-13 15:03:57 +01:00
Marco Trevisan (Treviño)
218b298a1b gio/gfilemonitor: Use atomic API to get / store cancelled state
The cancelled state may be set and read by different threads, so ensure
that it's stored and managed in an atomic way.

We could in fact end up check for `g_file_monitor_is_cancelled()` in a
thread and `g_file_monitor_cancel()` or `g_file_monitor_emit_event` in
in another one.
2025-02-13 15:03:57 +01:00
Philip Withnall
3e5c454a02
gkeyfilesettingsbackend: 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-02-12 11:30:55 +00:00
Marco Trevisan (Treviño)
00ebf4e1eb tests/lib: Add a new unittest type to simplify launching test programs
We were reusing the same logic everywhere, while we can just reuse an
unique class to base our tests on that avoids having to copy-and-paste
code for no good reason
2025-02-11 18:51:15 +01:00
Marco Trevisan (Treviño)
4bcd99de43 tests: Avoid reusing and installing multiple files the taptestrunner
Add some basic support for having glib-tests-only python libraries that
can be shared across the various projects, so that we don't have to
maintain multiple copies of them.
2025-02-11 18:51:15 +01:00
Philip Withnall
14a756ae97
gdbusconnection: Add g_dbus_connection_register_object_with_closures2() API
This replaces `g_dbus_connection_register_object_with_closures()`, and
becomes the new binding-friendly version of
`g_dbus_connection_register_object()`.

The problem with `g_dbus_connection_register_object_with_closures()` is
that the `method_call_closure` kept the reference counting semantics of
`GDBusInterfaceMethodCallFunc`, in that the `invocation` argument was
`(transfer full)`, even though it was wrapped in a `GClosure`. This
couldn’t be described in introspection annotations, so the
`GDBusMethodInvocation` was being leaked by bindings. Some bindings
added workarounds to fix the leak at our direction (see
https://gitlab.gnome.org/GNOME/glib/-/issues/2600#note_1385050), which
meant we could no longer change the reference counting behaviour without
breaking those bindings (see #3559).

So let’s start afresh with
`g_dbus_connection_register_object_with_closures2()`, with correctly
defined reference counting semantics (the `GDBusMethodInvocation` is
`(transfer none)`) from the start.

Unfortunately we can’t add a `(rename-to)` annotation to the new API, as
that would effectively be an API break for existing binding code which
uses the old API via that rename.

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

Fixes: #3560
2025-02-11 14:08:05 +00:00
Philip Withnall
ca760eeeac Merge branch 'windows-fix-shebang' into 'main'
Windows: fix Python path can contain spaces

Closes #3331

See merge request GNOME/glib!4391
2025-02-11 13:42:32 +00:00
Dan Yeaw
160e55575e Windows: fix Python path cannot contain spaces
Move the shebang line from the full Python path of the build
machine to the first Python on the path during runtime. Set
the shebang in the main meson.build file so that it can be
overridden in one place if needed.

Fixes: #3331
2025-02-11 11:57:30 +00:00
Arjan Molenaar
04acc1741b
docs: Make docs more markdown-ish
Fixed some issues that came to light while compiling documentation
for the python bindings.
2025-02-10 10:26:42 +01:00
Philip Withnall
0234f8e1b1 Merge branch 'ppd-api-rename' into 'main'
gio/powerprofilemonitordbus: Use newer D-Bus API

See merge request GNOME/glib!4478
2025-02-07 08:34:19 +00:00
Marco Trevisan (Treviño)
dba2d618d5 gio/tests/power-profile-monitor*.py: Use upower ppd daemon APIs 2025-02-07 00:55:35 +01:00
Marco Trevisan (Treviño)
71d08b707a gio/tests/power-profile-monitor-*.py: Fix style using black 2025-02-07 00:55:35 +01:00
Marco Trevisan (Treviño)
236abac6fb gio/powerprofilemonitordbus: Use newer DBus API
Since some time the power-profiles-daemon project has been moved under
the upower umbrella and renamed its API to follow that.

While the legacy name is still supported, there are plans to not support
it anymore in future [2]. So let's update GLib code to use the
current main name instead.

[1] https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/merge_requests/148
[2] https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/merge_requests/166
2025-02-07 00:55:32 +01:00
Mavroudis Chatzilazaridis
cb1502ed66 docs: Fix invalid references and broken links
This commit fixes quite a few broken links and references, minor typos,
and improves wording in some sections.
2025-02-05 22:28:26 +02:00
Philip Withnall
ff2c5c3e74
tests: Fix non-atomic accesses to atomic variables in cancellable test
As suggested by Marco Trevisan in !4206.

This might eliminate some spurious failures of the test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 14:06:15 +00:00
Marco Trevisan (Treviño)
d7c8bb0726 gcancellable: Ignore cancelled callback on disposed source
Prevent to access to a disposed gsource in the GCancellable cancelled
signal callback.

Due to the fact that the signal is called in the same thread in which
the cancellable get cancelled, we may receive the callback just after
the GSource has been disposed or during its disposal.

To prevent this, let's pass to the signal a pointer to the source itself
and nullify atomically the first time we're calling a callback or
disposing it.

In case the dispose function wins the race, then the callback will just
do nothing, while the disposal will continue as expected.

In case the callback wins the race, during the concurrent disposal we'll
just wait for the callback to be completed, before returning the disposal
itself that will likely lead to freeing the GSource.

Closes: #3448
2025-02-04 13:01:03 +00:00
Philip Withnall
eec7ba6ef3 Merge branch '3592-dbus-serial-overflow' into 'main'
gdbusconnection: Prevent sending a serial of zero on overflow

Closes #3592

See merge request GNOME/glib!4470
2025-02-04 11:09:45 +00:00
Philip Withnall
f7a0e5f13f Merge branch 'wip/nacho/gregistry' into 'main'
Registry backend fixes

See merge request GNOME/glib!4468
2025-02-04 10:40:03 +00:00
Philip Withnall
8297bbc00c
gdbusmessage: Check that message serial is not set to zero
It’s disallowed by the D-Bus specification.

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

Helps: #3592
2025-02-04 10:32:44 +00:00
Philip Withnall
b94b44407a
gdbusconnection: Prevent sending a serial of zero on overflow
It finally happened: someone managed to keep a process alive long
enough, and using a single `GDBusConnection`, to overflow the
`last_serial` counter in the connection and send an invalid message with
serial of zero (which is disallowed by the D-Bus specification).

Avoid that happening in future by skipping serials of zero on overflow,
and wrapping straight back around to 1.

This looks a little more confusing than it is, because `last_serial` is
pre-incremented on use, so to skip zero, we explicitly set it to zero.
This is exactly what happens when the `GDBusConnection` is initialised
anyway.

I can’t think of a way to add a unit test for this — there is no way to
affect the value of `last_serial` except by sending messages (each one
increments it), and in order to get it to overflow by sending messages
at 1kHz, the test would have to run for 49 days.

Instead, I tested this manually by temporarily modifying
`GDBusConnection` to initialise `last_serial` to `G_MAXUINT32 - 3`, then
checked that the unit tests all still passed, and that the overflow code
was being executed.

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

Fixes: #3592
2025-02-04 10:32:37 +00:00
Silvio Lazzeretti
23ad130b15 registrybackend: fix some memory leaks 2025-02-04 08:38:48 +01:00
Silvio Lazzeretti
f45b5ea776 registrybackend: make subscribe and unsubscribe thread-safe
The registry backend uses a thread to monitor
registry changes and send notifications.
The state of this thread and structures used
for communicating with it are kept in the watch
variable.
The subscribe and unsubscribe functions might be
concurrently called from multiple threads and
need to communicate with the monitoring thread.
For this reason we need to synchronize the access
to the watch variable.
2025-02-04 08:38:45 +01:00
Felix Xing
e99e27848e Add checking for <sys/ucred.h>
A new header check is added for non-standard <sys/ucred.h>. Some platforms, like Linux, might support <sys/param.h>, <sys/mount.h>, and <fstab.h> but not this. Which can cause compilation to fail for gio/gunixmounts.c
2025-02-03 09:19:17 -05:00
Felix Xing
a177c46b19 Add support for QNX8.0
This request brings support to the latest version of QNX software. _g_get_unix_mount_points (void) for getfsent() system also works on QNX. To avoid duplicating codes, it will be reused.
2025-01-31 09:18:02 -05:00
Andre Miranda
62d8d0b6ec gosxappinfo: Fix leak
Slightly reworked by Philip Withnall (any mistakes his).
2025-01-28 12:03:10 +00:00
Andre Miranda
8b64bb8751 gosxappinfo: Correctly launch list of files
Fixes #3587
2025-01-24 12:29:54 +00:00
Maximiliano
9d3c384565 gioenums: Add deprecation for FLAGS_NONE
g-ir won't pick it if it is not in its own doc block.

Requires
https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/512,
otherwise the deprecated tag won't be set in the introspection data.
2025-01-13 19:42:09 +00:00
Philip Withnall
6f6743de61
gfilteroutputstream: Fix duplicated property name in doc comment
Looks like a copy/paste error from the doc comment immediately below.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-12-31 13:05:02 +00:00
Michael Catanzaro
55fbcb21d9 Merge branch 'autorelease-urlspec' into 'main'
Use autorelease pool to manage cocoa memory.

Closes #3568

See merge request GNOME/glib!4448
2024-12-22 00:49:56 +00:00
John Ralls
d3705ecdcf g_osx_appinfo_launch: Use autorelease pool to manage cocoa memory.
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3568
2024-12-21 13:12:41 -08:00
Philip Withnall
fbe324086e Merge branch 'unix-mounts-docs' into 'main'
gunixmounts: Clarify GUnixMountMonitor documentation and convert to gi-docgen linking syntax

Closes #3569

See merge request GNOME/glib!4447
2024-12-20 18:40:04 +00:00
Philip Withnall
46160f9aad
gunixmounts: 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
2024-12-20 15:11:41 +00:00
Philip Withnall
12f969eb79
gunixmounts: Consistently capitalise Unix in the documentation
Let’s not go with SHOUTY UNIX or quiet unix, let’s just call it what
Wikipedia calls it (https://en.wikipedia.org/wiki/Unix).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-12-20 12:42:58 +00:00
Philip Withnall
05afb30510
gunixmounts: Document caveats with *_changed_since() APIs
They need a `GUnixMountMonitor` to give valid timestamps, and if you
have one of those then you might as well listen to its signals anyway.

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

Fixes: #3569
2024-12-20 12:34:12 +00:00
Philip Withnall
2f010f5618
gunixmounts: Fix typo in deprecation documentation
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-12-20 12:25:22 +00:00
Philip Withnall
5029f3aae9
gio: Fix a link to a specifications document
If only someone would go ahead and invent a whole section of the list of
HTTP status codes which could be used to inform a client of where a
document has been moved to.

For the sake of argument, let’s say it could be status codes 300–399,
since they appear to be completely unused at the moment.

😩

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-12-19 23:09:17 +00:00
FeRD (Frank Dana)
9f016e5de4 Fix pointer-to-paramref syntax in docs
The documentation for GLib and Gio contains a number of documentation
comment blocks where a parameter reference (e.g. `@err`) is also
discussed in its dereferenced pointer form, which is generally
annotated as `*@err`. This inevitably confuses the MarkDown parser,
which sees the `*` as the beginning of an italicized text span.

To avoid this, replace all `*@foo` with <code>`*foo`</code>, which
loses the `@`-sigil linking it to the `@foo` parameter, but formats
correctly in the rendered documentation. (`@foo` is automatically
formatted like <code>`foo`</code>, so the resulting appearance in
the docs is as intended.)
2024-12-15 18:51:26 -05:00