31576 Commits

Author SHA1 Message Date
Patrick Griffis
fe0139ee98 threadedresolver: Return valid addresses when only having loopback interfaces
The AI_ADDRCONFIG flag filters out addresses for invalid interfaces. This causes it to resolve nothing when only having loopback interfaces.

So we can detect if you only have loopback interfaces, request all addresses, and filter out non-loopback results.

Closes #3641
2025-03-24 09:44:55 -05:00
Patrick Griffis
752b6447d8 socketaddress: Use more clear GSocketFamily type
The value of them should be identical, but it feels odd to
not pass the expected enum type.
2025-03-24 09:43:42 -05:00
Patrick Griffis
bbba92630b threadedresolver: Clean up variable scope
Keep the scope limited.
2025-03-24 09:43:42 -05:00
Philip Withnall
913a1bfd85 Merge branch 'main' into 'main'
Fix LGPL in header

See merge request GNOME/glib!4565
2025-03-21 17:40:54 +00:00
Sebastian Wilhelmi
247e7b6995 Fix LGPL in header of gvarianttype-private.h 2025-03-21 17:40:53 +00:00
Philip Withnall
be031cf2a5 Merge branch 'test-path-fixes' into 'main'
tests: Various fixes to create temporary files in /tmp rather than the build directory

See merge request GNOME/glib!4561
2025-03-21 15:30:53 +00:00
Philip Withnall
ee4b93bff4
tests: Port spawn-test tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:16 +00:00
Philip Withnall
e4fca24a06
tests: Add missing shell argument quoting in spawn-test
It’s not currently needed, because the filename being passed to the
subprocess is hard-coded and doesn’t contain anything which would need
escaping. But the following commit is going to change that (to avoid
filename collisions), so let’s fix the quoting first.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:11 +00:00
Philip Withnall
a795dede46
tests: Port mapping tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:07 +00:00
Philip Withnall
484fb416c6
tests: Factor out hard-coded file names in mapping test
So the filename we delete at the end of the test is definitely the same
one we created at the start of the test.

This introduces no functional changes, but will make a refactor in the
following commit simpler.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:03:03 +00:00
Philip Withnall
9f75cdc2bc
tests: Port keyfile tests to use G_TEST_OPTION_ISOLATE_DIRS
This ensures they’re not writing files to the build directory, which
avoids race conditions when running multiple invocations of the tests.

This is not entirely trivial, because the tests for
`g_key_file_load_from_data_dirs()` are affected by the overridden
`$XDG_DATA_HOME` directory. Mitigate that by copying the file they want
to that directory (and relying on `G_TEST_OPTION_ISOLATE_DIRS` to delete
it again afterwards).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:58 +00:00
Philip Withnall
87cc9f2b6d
gkeyfile: Better document search algorithm for g_key_file_load_from_data_dirs()
Today I learned that it magically turns `-` into `/` to search
subdirectories for key files. Turns out that wasn’t documented at all.

i.e. it’ll search for `$datadir/some-key-file.ini` and, if that’s not
found, will then try `$datadir/some/key-file.ini` and then
`$datadir/some/key/file.ini`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:54 +00:00
Philip Withnall
e7b820d66c
tests: Move various test paths to g_get_tmp_dir()
Rather than creating files in the current directory. This is a bit
neater, and avoids races between parallel invocations of the unit tests
if the file names aren’t guaranteed to be unique (e.g. by using
`g_mkstemp()`).

Add `G_TEST_OPTION_ISOLATE_DIRS` too, to make sure we use a unique
subdirectory of `g_get_tmp_dir()`. This means that paths like
`g_get_tmp_dir() / some-file` are guaranteed to be race-free even if the
filename is not unique, because the test tmp dir now is.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:49 +00:00
Philip Withnall
4d2b873211
tests: Use g_build_filename() rather than g_strdup_printf()
In the `g-file-info-filesystem-readonly` test.

This doesn’t introduce any functional changes, but makes the code a
little easier to read (because the parts of the path are now in
hierarchical order) and makes it a bit clearer that we’re building a
path rather than an arbitrary string.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:45 +00:00
Philip Withnall
447fa26205
gfileutils: Clarify that g_mkstemp() and friends act in the current directory
Otherwise it’s easy to assume that they create a file in the system
temporary directory, if they’re only called with a filename template
(without a path).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:41 +00:00
Philip Withnall
4345eb2756
tests: Only use g_mkstemp() in /tmp rather than current directory
It’s not entirely clear from the documentation, but `g_mkstemp()` (and
`g_mkdtemp()`) operate in the current directory, rather than the system
temporary directory.

This meant these tests were all writing files to the build directory.
This is messy, though thankfully not a correctness issue or a race
because `g_mkstemp()` guarantees to return a unique file for each
caller.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:36 +00:00
Philip Withnall
581a0b1285
gfile: Document that g_file_make_directory() returns G_IO_ERROR_EXISTS
if the directory already exists.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:32 +00:00
Philip Withnall
d77bff0bef
tests: Use standard g_test_message() logging in fileutils tests
Rather than a custom combination of `g_test_verbose()` and
`g_printerr()`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:27 +00:00
Philip Withnall
918c4bd467
tests: Use g_assert_*() rather than g_assert() in fileutils tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:23 +00:00
Philip Withnall
aae1743284
tests: Test directories inside /tmp rather than arbitrary paths
This probably wasn’t causing any problems since it was a self-contained
read only access of a non-existent path. But it’s a bit tidier to
contain this all inside `/tmp`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:18 +00:00
Michael Catanzaro
08489deb06 Merge branch 'epoll-create' into 'main'
giounix-private: Fix macro for checking for epoll_create1()

See merge request GNOME/glib!4563
2025-03-20 12:33:50 +00:00
Philip Withnall
20f083ea7c
giounix-private: Fix macro for checking for epoll_create1()
Like many things I touch, I broke this in
fd8ede0b661aa67032bbc3e7afc88aff22d7984a.

Spotted by Sebastian Wilhelmi in
fd8ede0b66 (note_2385263).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-20 11:12:58 +00:00
Philip Withnall
da12657e8b
gdbusnameowning: 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-03-19 20:41:47 +00:00
Philip Withnall
88e8ee515c Merge branch 'settings-docs' into 'main'
gsettings: Port docs to gi-docgen format, add missing annotations and make various improvements

See merge request GNOME/glib!4541
2025-03-19 20:18:34 +00:00
Philip Withnall
b0568c845d Merge branch 'file-info-docs' into 'main'
gfileinfo: Slightly expand docs for g_file_info_get_attribute_as_string()

See merge request GNOME/glib!4557
2025-03-19 20:05:06 +00:00
Philip Withnall
7ea8543f7e Merge branch 'fix_3636' into 'main'
gio-tool: Fix handling of the trash original path

Closes #3636

See merge request GNOME/glib!4556
2025-03-19 17:37:36 +00:00
Philip Withnall
93ad1d9773 Merge branch 'bilelmoussaoui/gi-docs' into 'main'
gi: Dynamically set doc-format

See merge request GNOME/glib!4558
2025-03-19 11:49:48 +00:00
Lukáš Tyrychtr
aaf8097b73 Ensure we're printing UTF-8 2025-03-17 13:38:13 +01:00
Bilal Elmoussaoui
5e50167da5 gi: Dynamically set doc-format 2025-03-15 10:27:13 +01:00
Philip Withnall
787f47f091
gfileinfo: Slightly expand docs for g_file_info_get_attribute_as_string()
Inspired by !4556.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-14 15:27:08 +00:00
Lukáš Tyrychtr
6b2187b5ef gio-tool: Fix handling of the trash original path
Previously, we were getting the string representation. However, this
representation gets escaped, which breaks non-ascii characters, because we
were counting on the path being the original path, which was not true in
these cases.

Retrieve it rather as the byte string which it is.

Fixes #3636.
2025-03-14 13:46:55 +01:00
Philip Withnall
ccc6748ca9 Merge branch 'such-a-cold-test' into 'main'
tests: Add a test for g_object_freeze_notify() being called too often

See merge request GNOME/glib!4555
2025-03-13 16:29:50 +00:00
Thomas Haller
67fa02bdcf gobject: destroy closure watches one by one
Previously, we would call

  g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);

which called destroy_closure_array() on the CArray.

At that point, it would iterate over the CArray, and invalidate all
closures. But note that this invokes external callbacks, which in turn
can destroy other closures, which can call object_remove_closure().
But now that closure can no longer be found and an assertion fails.

Instead of removing the entire CArray at once, remove each closure one
by one in a loop.

This problem is similar to issue 1002, except here it's about closure
watches instead of GWeakNotify.

Note that now we destroy closures one-by-one in a loop, and we iterate
the loop as long as we have closures. That makes a difference when a new
closure gets registered while we destroy them all. Previously, newly
registered closures would survive. It would be possible to implement the
previous behavior, but I think the new behavior is better. It is anyway
a very remote use case.
2025-03-13 17:23:55 +01:00
Philip Withnall
9fe6d8b5f0
tests: Disable socket-listener mock tests on macOS
Its symbol interposition works differently to that of Linux, so our
approach using `dlsym(RTLD_NEXT)` to inject syscalls (and still allow
chaining up to the version from libc) doesn’t work on macOS.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/4861349 for an example
failure.

It would be lovely to have these tests working on macOS, but I am not a
macOS developer, and have spent enough time fixing this leak (#1250)
already. It can wait for follow-up work.

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

Helps: #1250
2025-03-13 13:25:19 +00:00
Philip Withnall
007c525d61
gsocketlistener: Minor cleanups to use g_clear_object() and friends
This should introduce no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-13 13:25:13 +00:00
Philip Withnall
05e529f3f8
tests: Add tests for g_socket_listener_add_any_inet_port() algorithm
The algorithm that `g_socket_listener_add_any_inet_port()` and
`g_socket_listener_add_inet_port()` use to try to connect to IPv4 and/or
IPv6 ports are a bit complex (especially when port allocation has to
happen in the former method). So far they’ve not really been unit
tested, which is unfortunate, and has left latent bugs.

Add some unit tests for both methods, by providing mock `socket()` (and
friends) functions to override those from libc, and using those to cause
specific syscalls to fail according to the test’s needs.

These tests demonstrate the fix for #1250 works, as the tests can be run
under memcheck and show no memory leaks. They’ve revealed a follow-up
issue, though — `g_socket_listener_add_any_inet_port()` doesn’t try a
fallback IPv4-only socket if it tries an IPv6 socket and that socket
accepts IPv4 but then fails to `listen()`. I’ve filed issue #3604 for
that.

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

Helps: #1250
2025-03-13 13:25:06 +00:00
Philip Withnall
ff94b4b665
tests: Add a test for g_object_freeze_notify() being called too often
This tests the `g_critical()` path in it, to make sure we handle errors
acceptably there.

Prompted by https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4185#note_2377037

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-13 11:48:10 +00:00
Philip Withnall
435dd378fd
tests: Use g_assert_*() rather than g_assert() in properties tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-13 11:47:48 +00:00
Philip Withnall
a2904b611e Merge branch 'l10n-id' into 'main'
Update Indonesian translation

See merge request GNOME/glib!4554
2025-03-13 00:38:09 +00:00
Andika Triwidada
fe330b0b31 Update Indonesian translation 2025-03-12 11:40:53 +00:00
Philip Withnall
89983f33b0 Merge branch 'ebassi/signal-flags-docs' into 'main'
docs: Document GSignalFlags members added after 2.0

See merge request GNOME/glib!4553
2025-03-12 11:16:06 +00:00
Emmanuele Bassi
3de213b622 docs: Document GSignalFlags members added after 2.0
Use separate doc blocks, to ensure that the "Since" tag is parsed and
reflected in the introspection data.
2025-03-12 11:34:30 +01:00
Philip Withnall
34608c9426 Merge branch 'Persian' into 'main'
Update Persian translation

See merge request GNOME/glib!4552
2025-03-12 09:51:42 +00:00
Thomas Haller
4845314c01 gobject: add internal g_destroy_notify_assert_not_reached() helper
This is a GDestoryNotify that asserts not to be called. Obviously, this
is only for testing and asserting (defensive programming).

It is private API inside "libgobject-2.0.so.0". If unused, we rely that
the linker can strip it out.
2025-03-12 08:27:15 +01:00
Thomas Haller
dec3ba69e8 gobject: avoid potential race and use g_datalist_id_update_atomic() for closure array
There are two calls to

  g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);

that don't take a OPTIONAL_BIT_LOCK_CLOSURE_ARRAY lock. These are inside
g_object_real_dispose() and right before finalize(). The one before
finalize() is fine, becase we are already in a situation where nobody
else holds a reference on object.

However not so with g_object_real_dispose().  That is called after we
checked that there is only one strong reference left and we are inside
the call to dispose(). However, at that point (before chaining up
g_object_real_dispose()) the callee is able can pass the reference
to another thread. That other thread could create a Closure and destroy it
again. This calles object_remove_closure() (accessing CArray) which now
races against g_object_real_dispose() (destroying CArray).

Granted, this is very unlikely to happen. But let's try to avoid such
races in principle.

We can avoid this problem with less overhead by doing everything while
holding the GData lock, using g_datalist_id_update_atomic().  This is
probably even faster, as we don't need the additional
OPTIONAL_BIT_LOCK_CLOSURE_ARRAY lock.

Also free the empty closure data during object_remove_closure(). This
frees some unused memory.
2025-03-12 08:22:52 +01:00
Philip Withnall
986d1c8d69 Merge branch 'update-danish-translation' into 'main'
Updated Danish translation

See merge request GNOME/glib!4551
2025-03-11 23:26:22 +00:00
Danial Behzadi
688b431db7
Update Persian translation. 2025-03-12 02:37:00 +03:30
Ask Hjorth Larsen
07c5268f64 Updated Danish translation 2025-03-11 16:26:09 +01:00
Michael Catanzaro
444aa3e999 Merge branch 'wip/3v1n0/gobject-atomic-pspec' into 'main'
gobject: Be consistent in using atomic logic to handle the GParamSpecPool

See merge request GNOME/glib!4489
2025-03-11 15:13:53 +00:00
Marco Trevisan (Treviño)
5b0ce18dcd gobject: Add single function to check G_ENABLE_DIAGNOSTIC
It was duplicated, and racing too
2025-03-11 01:07:20 +01:00