Commit Graph

30173 Commits

Author SHA1 Message Date
Michael Catanzaro
3b22daf758 Merge branch 'backport-4110-dns-ref-glib-2-80' into 'glib-2-80'
Backport !4110 “gthreadedresolver: ref-sink returned records in lookup_records()” to glib-2-80

See merge request GNOME/glib!4141
2024-07-05 12:18:18 +00:00
Andy Holmes
bf7a270970 tests: ensure DNS records are full-reference variants
For each test expected to return valid DNS records, test that the
record variants are not floating references.

Also add an test which checks this explicitly for a simple TXT record.
2024-07-05 07:28:48 +01:00
Andy Holmes
b8aaa10a91 gthreadedresolver: ref-sink returned records in lookup_records()
The return value to `lookup_records()` methods is set as `transfer full`
but the code path in `g_resolver_records_from_res_query()` doesn't
sink the GVariant.

Add the `g_variant_ref_sink()` call when prepending the record, so
the list hold a full reference on each records.

closes #3393
2024-07-05 07:28:48 +01:00
Emmanuele Bassi
9b6af495cf Merge branch 'backport-4122-gir-deps-glib-2-80' into 'glib-2-80'
Backport !4020 and !4122: fixes to GIR install locations and build race fixes

See merge request GNOME/glib!4124
2024-06-27 09:55:02 +00:00
Philip Withnall
e8d11b0dbd
introspection: Add libgirepository as a dep to all generate_gir() calls
libgirepository is not needed by most of the modules, but it is needed
by the `g-ir-scanner` generated dumper program. If we don’t explicitly
include the local version of it here, Meson will implicitly link against
it anyway, and that might pull in a different version, or try to link
against a half-built local version as the build ordering dependency tree
won’t reflect this relationship.

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

Fixes: #3401
2024-06-27 10:32:05 +01:00
Alexander Kanavin
1402132d63
girepository/introspection: correctly install .gir files into custom locations
There is a meson option (gir_dir_prefix), but without being passed in here
the files would always get installed into the default location (datadir).

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
2024-06-27 10:31:48 +01:00
Michael Catanzaro
5d70340412 Merge branch 'wip/pwithnall/backport-3373-file-load-4gb-glib-2-80' into 'glib-2-80'
Backport !3373 and !4117 “Handle files >4GB in g_file_load_contents()“ to glib-2-80

See merge request GNOME/glib!4118
2024-06-18 22:09:21 +00:00
Philip Withnall
b4085620c6
tests: Improve 4GB file loading test to work on i386
This should test the limits of loading 4GB files on i386 platforms, such
as the Hurd CI runner. On such platforms, `sizeof(size_t) == 4`.

This should fix the compiler warning from
https://gitlab.gnome.org/GNOME/glib/-/jobs/3989442:
```
../gio/tests/file.c:2931:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
 2931 | static const gsize testfile_4gb_size = ((gsize) 1 << 32) + (1 << 16); /* 4GB + a bit */
      |                                                   ^~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 21:25:12 +01:00
Philip Withnall
724709f022
tests: Skip >4GB file tests unless running tests in slow/thorough mode
They take too long to include in a normal test run. They’ll still be run
in CI once a week as part of our scheduled slow test job.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 21:25:06 +01:00
Benjamin Otte
7ad4384af1 tests: Add test for >4GB reads with g_file_load_contents()
The tests - one for sync, one for async - create a sparse file for
this purpose, so this should be cheap on the fileystem.

Of course, the test still allocates >4GB of memory for the data that it
returns from g_file_load_contents(), I hope the CI test runners can deal
with that.
2024-06-18 21:24:39 +01:00
Benjamin Otte
84f3b1ab9e tests: Use g_clear_fd() 2024-06-18 21:24:39 +01:00
Benjamin Otte
c2b3a6c557 gfile: Rewrite load_contents() to use realloc()
GByteArray is limited to 4GB in size and the current code silently
overflows when that happens.

Replace both load_contents() and load_contents_async() implementations
with a version that uses realloc() and gsize to maintain the array.
2024-06-18 21:24:39 +01:00
Benjamin Otte
1cf39a3000 array: Abort on overflow
This is a precautionary assert that will probably only trigger on 32bit
OSes. But g_nearest_pow() can overflow.
2024-06-18 21:24:39 +01:00
Michael Catanzaro
e1d1c78fc8 Merge branch 'backport-4111-eaddrnotavail-macos-glib-2-80' into 'glib-2-80'
Backport !4111 “gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED” to glib-2-80

See merge request GNOME/glib!4112
2024-06-13 20:55:47 +00:00
Philip Withnall
a2000e2b36
gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED
Previously it was mapped (as a default) to `G_IO_ERROR_FAILED`.

It’s the error that macOS returns when trying to connect to a socket which
is bound but not listened to. Linux returns `ECONNREFUSED` in this case.
It’s helpful if they both map to the same `GIOError` value.

This should fix the `/socket-client/connection-fail` test on macOS,
which is currently
[failing](https://gitlab.gnome.org/GNOME/glib/-/jobs/3970547) with:
```
 # GLib-GIO-DEBUG: GSocketClient: Starting TCP connection attempt
 # GLib-GIO-DEBUG: GSocketClient: Connection attempt failed: Can't assign requested address
 # GLib-GIO-DEBUG: GSocketClient: Starting new address enumeration
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration completed (out of addresses)
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration failed: (null)
 # GLib-GIO-DEBUG: GSocketClient: Connection failed: Could not connect to localhost: Can't assign requested address
not ok /socket-client/connection-fail - GLib-GIO:ERROR:../gio/tests/gsocketclient-slow.c:231:test_connection_failed: assertion failed (local_error == (g-io-error-quark, 39)): Could not connect to localhost: Can't assign requested address (g-io-error-quark, 0)
Bail out!
```

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

See: #3184
Fixes: #3394
2024-06-13 20:59:43 +01:00
Philip Withnall
8f3ed07701
2.80.3
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-10 12:22:09 +01:00
Emmanuele Bassi
14a26f969f Merge branch 'backport-4033-girepository-typelib-determinicity-glib-2-80' into 'glib-2-80'
Backport !4033 “girepository: Keep an ordered list of the loaded typelibs” to glib-2-80

See merge request GNOME/glib!4080
2024-06-10 10:27:29 +00:00
Jose Riha
0835b7df97 Update Slovak translation 2024-06-09 09:20:30 +00:00
Michael Catanzaro
c7f556596e Merge branch 'backport-4104-socket-client-leak-glib-2-80' into 'glib-2-80'
Backport !4104 “gsocketclient: Fix a leak of the task data on an error path” to glib-2-80

See merge request GNOME/glib!4105
2024-06-05 12:47:12 +00:00
Johan Sternerup
9fccda086a gsocketclient: Add unit test for leak of task data in error path
The unit test cover the error path that causes the leak described in
https://gitlab.gnome.org/GNOME/glib/-/issues/3184.
2024-06-05 12:57:59 +01:00
Philip Withnall
1942dd5b5c
gsocketclient: Fix a leak of the task data on an error path
Once the task is completed (and `g_task_return_*()` has been called),
the task is no longer needed. It would make more sense to unref it in
`complete_connection_with_error()`, where `g_task_return_*()` is called,
but that complicates other call sites significantly, so I didn’t do it.

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

Fixes: #3184
2024-06-05 12:57:49 +01:00
Jordi Mas i Hernandez
0043895879 Update Catalan translation 2024-05-27 14:56:31 +00:00
Michael Catanzaro
197e2690ef Merge branch 'backport-4078-clang-discarded-qualifiers-glib-2-80' into 'glib-2-80'
Backport !4078 “tests: Fix clang compilation failure due to unrecognised option in pragma” to glib-2-80

See merge request GNOME/glib!4079
2024-05-16 23:59:09 +00:00
Philip Withnall
3858b8b815
girepository: Make gi_repository_get_loaded_namespaces() deterministic
As with the previous two commits, the results of calling
`gi_repository_get_loaded_namespaces()` were previously
non-deterministic due to being generated by iterating over a hash table,
which has a non-deterministic iteration order.

Fix that by using the new `ordered_typelibs` and `ordered_lazy_typelibs`
arrays to provide deterministic ordering.

At the same time, significantly reduce the number of allocations needed
to build the return value — previously the results would be built as a
linked list before being turned into an array. The linked list is now
banished to history.

Add some more unit tests to maximise test coverage of this method.

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

Fixes: #3303
2024-05-16 23:32:15 +01:00
Philip Withnall
400fac7c4a
girepository: Make gi_repository_find_by_error_domain() deterministic
As with the previous commit, finding a `GIBaseInfo` matching the given
error domain was non-deterministic because it iterated through a hash
table of typelibs. Hash table iteration is non-deterministic.

Change the method to instead use the `ordered_typelibs` and
`ordered_lazy_typelibs` arrays to give deterministic iteration order.

Add a unit test, although it can’t test the interesting case of an error
domain which is present in both `GioUnix`/`GioWin32` and `Gio`, because
no such error domain exists.

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

Helps: #3303
2024-05-16 23:32:09 +01:00
Philip Withnall
48988a4098
girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 23:32:02 +01:00
Philip Withnall
25b7ecf895
gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

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

Helps: #3303
2024-05-16 23:31:56 +01:00
Philip Withnall
04bdf50c68
girepository: Fix a typo in a code comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 23:31:49 +01:00
Philip Withnall
7e3ec9a8ae
girepository: Keep an ordered list of the loaded typelibs
There are various places where the set of typelibs is iterated over or
returned in an ordered way. In order to keep results deterministic and
reproducible, we need to keep this set ordered.

Keep a `GPtrArray` of the typelibs (one for fully-loaded ones and one
for lazy ones) alongside the existing hash tables. This will be used for
iteration in the next few commits.

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

Helps: #3303
2024-05-16 23:31:43 +01:00
Philip Withnall
c98805e5a1
ci: Temporarily run the FreeBSD on a schedule rather than every commit
The runner is currently offline and we can’t have that blocking
development.

See: https://gitlab.gnome.org/Infrastructure/Infrastructure/-/issues/1503

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:42:16 +01:00
Philip Withnall
7548b4865f
tests: Fix clang compilation failure due to unrecognised option in pragma
Sigh.

```
../glib/tests/atomic.c:139:32: error: unknown warning group '-Wdiscarded-qualifiers', ignored [-Werror,-Wunknown-warning-option]
\#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
                               ^
1 error generated.
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:42:02 +01:00
Philip Withnall
2c379a35ba Merge branch 'backport-4065-girepository-bitfield-glib-2-80' into 'glib-2-80'
Backport !4065 “girepository: Don't assume a bitfield has a fixed size” to glib-2-80

See merge request GNOME/glib!4074
2024-05-16 21:38:28 +00:00
Emmanuele Bassi
2d60dc1539 Merge branch 'backport-4073-dbus-export-glib-2-80' into 'glib-2-80'
Backport !4073 “gmenuexporter: Fix a NULL pointer dereference on an error handling path” to glib-2-80

See merge request GNOME/glib!4077
2024-05-16 12:08:26 +00:00
Philip Withnall
043a06debb
gactiongroupexporter: Fix memory problems on an error handling path
Almost identically to the previous commit, fix a similar latent bug in
`g_dbus_connection_export_action_group()`, which was not ready to handle
the fledgling `GActionGroupExporter` being freed early on an error
handling path.

See the previous commit message for details of the approach.

This includes a unit test.

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

Fixes: #3366
2024-05-16 12:20:07 +01:00
Philip Withnall
5f5667b2a0
gmenuexporter: Fix a NULL pointer dereference on an error handling path
This latent bug wasn’t triggered until commit 3f30ec86c (or its
cherry-pick onto `glib-2-80`, 747e3af99, which was first released in
2.80.1).

That change means that `g_menu_exporter_free()` is now called on the
registration failure path by `g_dbus_connection_register_object()`
before it returns. The caller then tries to call `g_slice_free()` on the
exporter again. The call to `g_menu_exporter_free()` tries to
dereference/free members of the exporter which it expects to be
initialised — but because this is happening in an error handling path,
they are not initialised.

If it were to get any further, the `g_slice_free()` would then be a
double-free on the exporter allocation.

Fix that by making `g_menu_exporter_free()` robust to some of the
exporter members being `NULL`, and moving some of the initialisation
code higher in `g_dbus_connection_export_menu_model()`, and removing the
duplicate free code on the error handling path.

This includes a unit test.

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

Fixes: #3366
2024-05-16 12:19:57 +01:00
Philip Withnall
c2ec54d641 Merge branch 'backport-4059-leak-fixes-glib-2-80' into 'glib-2-80'
Partially backport !4059 “tests: Fix various memory leaks and valgrind / ASAN errors” to glib-2-80

See merge request GNOME/glib!4070
2024-05-15 13:55:16 +00:00
Marco Trevisan (Treviño)
9c611f6ef9
glib/tests/mapping: Unref the mapped file on exit 2024-05-15 13:00:01 +01:00
Marco Trevisan (Treviño)
116312f089
glib/tests/mapping: Check the exit status of the child process
In this way if it fails for some memory error we can track it
2024-05-15 12:59:55 +01:00
Marco Trevisan (Treviño)
5fc08f60b5
girepository/introspection: Properly check for sanitizer value
The sanitizer option is set to 'none' when not used
2024-05-15 12:59:48 +01:00
Marco Trevisan (Treviño)
c6770f964c
glib/tests/gutils-user-database: Add test dependency on preload library
We do preload the library but that's not set as test dependency and so
it may not be built
2024-05-15 12:59:42 +01:00
Marco Trevisan (Treviño)
a2111bec69
glib/tests/unicode: Cleanup allocated old locale if tests is skipped 2024-05-15 12:59:35 +01:00
Marco Trevisan (Treviño)
e4d369d5f4
gio/tests/gsettings: Cleanup allocated new locales 2024-05-15 12:59:28 +01:00
Marco Trevisan (Treviño)
5201650b21
glocalfile: Trash, free values when done avoiding leaks on early returns
In glocalfile we're allocating some temporary strings but we don't free
them on early returns, so free them once done and unset the variables
to prevent them being used incorrectly.
2024-05-15 12:59:22 +01:00
Adam Sampson
62b11360da
girepository: Don't assume a bitfield has a fixed size
The type used when declaring a bitfield member of a struct doesn't
affect the amount of space allocated for it - only whether it's signed
or unsigned. In standard C99 (6.2.7.1), only _Bool, signed int and
unsigned int or typedefs to them are allowed as bitfield types, but GCC
allows other integer types as an extension.

In this case, the GIBaseInfo and GIBaseInfoStack structs are meant to
have identical layout. However, type_is_embedded was declared as an
unsigned bitfield in the former and a uint32_t in the latter. This was
harmless on most platforms because the following member is an aligned
pointer, but (for example) on m68k-linux-gnu pointers only need to be
16-bit aligned, so GCC only allocates 16 bits for the bitfield.

Change the type in the declaration to unsigned int, and add an padding
bitfield following it to ensure there's space for 32 bits on all
platforms in the future.

Signed-off-by: Adam Sampson <ats@offog.org>
2024-05-15 12:57:44 +01:00
Emmanuele Bassi
71a143f32f Merge branch 'backport-4066-msys2-ci-fix-glib-2-80' into 'glib-2-80'
Backport !4066 “Fix several GCC 14 warnings to please msys2-mingw32 CI” to glib-2-80

See merge request GNOME/glib!4072
2024-05-15 11:20:40 +00:00
Philip Withnall
88e0dca208
tests: Fix transposed arguments to g_aligned_alloc()
Spotted by GCC 14’s `-Werror=calloc-transposed-args`. Thanks, GCC 14.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-15 11:57:16 +01:00
Philip Withnall
8714b87dbe
tests: Ignore -Wdiscarded-qualifiers with volatile atomics tests
GCC 14 now emits this warning with the tests:
```
In file included from ../glib/gthread.h:34,
                 from ../glib/gasyncqueue.h:34,
                 from ../glib/glib.h:34,
                 from ../glib/tests/atomic.c:14:
../glib/tests/atomic.c: In function 'test_types':
../glib/gatomic.h:140:5: error: argument 2 of '__atomic_store' discards 'volatile' qualifier [-Werror=discarded-qualifiers]
  140 |     __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST); \
      |     ^~~~~~~~~~~~~~
../glib/tests/atomic.c:139:3: note: in expansion of macro 'g_atomic_pointer_set'
  139 |   g_atomic_pointer_set (&vp_str_vol, NULL);
      |   ^~~~~~~~~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
```

I can’t think of a way to cast around this in the definition of
`g_atomic_pointer_set()` without making the behaviour worse (less type
safe) for modern non-volatile atomic variables.

We would like to strongly nudge users of GLib away from declaring atomic
variables as `volatile`, so letting another compiler warning be emitted
when they do is not the end of the world. As long as it doesn’t stop old
code compiling (without `-Werror`).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-15 11:57:10 +01:00
Marco Trevisan (Treviño)
2f35c32c34
vsaprintf: Use proper size for mp_limb_t to please msys2-mingw32 CI 2024-05-15 11:57:03 +01:00
Marco Trevisan
adb57fb40f Merge branch 'backport-4058-gir-test-deps-glib-2-80' into 'glib-2-80'
Backport !4058 “Tests: Build fixes when running `meson test` without previous builds“ to glib-2-80

See merge request GNOME/glib!4061
2024-05-09 15:20:50 +00:00
Marco Trevisan (Treviño)
b48b7b2a84
girrepository/tests: Add full gir dependencies on tests
Tests may have runtime dependencies that are related to the typelib
dependencies, so we need to satify them or the tests will fail at
runtime if we're not building their prerequisite for other reasons.

That's saying that the tests are currently failing when explicitly
running as standalone in meson.

Co-Authored-By: Philip Withnall <philip@tecnocode.co.uk>
2024-05-09 15:36:54 +01:00