Commit Graph

32050 Commits

Author SHA1 Message Date
Philip Withnall
8e39ad2660 tests: Add a basic test for g_scanner_sync_file_offset()
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269328

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 13:00:08 +00:00
Philip Withnall
020e58bac5 tests: Add basic tests for comments and FD input in GScanner
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269327

This is nowhere near a comprehensive test suite for `GScanner`, but it
at least means we have more of a basis for that, and a regression test
for the above change.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 13:00:04 +00:00
Philip Withnall
00f54b1bcc Merge branch 'fix-docs-links' into 'main'
docs: Fix invalid references and broken links

See merge request GNOME/glib!4475
2025-02-06 12:38:51 +00:00
Philip Withnall
84e26432c8 tests: Add a test for command line option parsing errors
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269326

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:35:41 +00:00
Philip Withnall
7dca1fb094 tests: Add a basic test for g_log_writer_journald()
While we can’t test that its functionality actually does anything, we
can call it and execute its code and see if it crashes.

This adds basic code coverage for it.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269325

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:26 +00:00
Philip Withnall
84bd676519 tests: Add a missing test for post-normalisation lowercasing in IDN
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4387#note_2269324

This adds a test to increase the code coverage of `nameprep()` in
`ghostutils.c`. It was previously missing coverage of the second
`tolower()` operation. The new test triggers this by using a Unicode
codepoint which cannot be converted to lowercase itself, but which
normalises (NFKC) to uppercase characters which can — a Unicode Roman
numeral.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:22 +00:00
Philip Withnall
72ca779e36 tests: Use g_assert_*() rather than g_assert() in option-context tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:17 +00:00
Philip Withnall
a6c36498ed ghostutils: Limit punycode decoding output length
It uses a `GArray` to build up the output, and the size of that is
limited to a `guint`, so add an assertion to make sure the code never
requests anything bigger.

Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:27:11 +00:00
Philip Withnall
e35aa61a55 ghostutils: Clarify string ownership transfers
Rename the `tmp` variable to `name_owned` to make its purpose clearer,
and more consistently assign to both it and `name` and `len` (which is
the length of `name`) every time any of them are modified.

This should make the function `const`-correct without the need for
casts, and introduce no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-06 12:27:03 +00:00
Philip Withnall
91b491241e ghostutils: Fix string length handling to use gssize
Rather than `gint`, which can overflow for long strings, although such
strings would probably have hit hostname length limits already.

This fixes a `-Wshorten-64-to-32` warning.

I looked at changing from `gssize` to `size_t` and handling the `len <
0` case with an explicit early call to `strlen()`, but it didn’t make
things simpler, as the code in `nameprep()` keeps changing the length of
the string as it processes it.

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

Helps: #3527
2025-02-06 12:26:59 +00:00
Philip Withnall
a5682aff2e goption: Fix string length handling to use size_t type
When parsing command line options, use `size_t` to hold string lengths.
This introduces no functional changes (any strings long enough to fit in
`size_t` but not in `int` will probably hit command line length limits),
but it does fix a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:54 +00:00
Philip Withnall
4d49fc8222 goption: Move a variable declaration to the scopes where it’s used
This introduces no functional changes, it just splits the declaration of
`j` into three smaller-scoped declarations of the same type. This will
make the following commit clearer.

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

Helps: #3527
2025-02-06 12:26:50 +00:00
Philip Withnall
664aca14a5 goption: Add explicit int cast in integer parsing code
The code uses `strtol()` to parse an integer from a string, then
correctly verifies its range, then it did an implicit cast to `int` to
return the parsed integer. This causes a spurious `-Wshorten-64-to-32`
warning, so add an explicit cast to make the code’s intention clear.

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

Helps: #3527
2025-02-06 12:26:45 +00:00
Philip Withnall
63af851f15 goption: Fix string length storage to use size_t rather than int
This moves all the string length handling in this part of `goption.c` to
use `size_t`. However, we need to assert that the string length is
at most `G_MAXINT` later on, as the length is passed to `printf()` to
add indentation, and it only accepts `int` for that kind of placeholder.

This introduces no functional changes, but does fix some
`-Wshorten-64-to-32` warnings.

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

Helps: #3527
2025-02-06 12:26:41 +00:00
Philip Withnall
30c47b059c glib-init: Fix type used for string length storage
This fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:36 +00:00
Philip Withnall
8c37608c0d gpattern: Fix use of narrow types to contain string offsets
When parsing the pattern in `g_pattern_spec_new()`, the offsets of
wildcards and jokers were stored in a `gint`. This could overflow with
exceptionally long patterns.

Split the sign out into a separate boolean for `hw_pos` and `hj_pos`
(it’s not necessary for `tw_pos` or `tj_pos` because their sign was
never queried), and use `size_t` to correctly store string offsets.

Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:29 +00:00
Philip Withnall
66f4a52bd6 grand: Add an explicit cast to silence a -Wshorten-64-to-32 warning
The seed is explicitly a `guint32`, so an implicit cast was already
happening. We don’t actually care if there’s a loss of precision here,
as it’s a pseudo-random seed value rather than an ordinal number, so add
an explicit cast to silence the warning.

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

Helps: #3527
2025-02-06 12:26:22 +00:00
Philip Withnall
b8e68db45b grand: Fix return type for fread() call
This fixes a `-Wshorten-64-to-32` warning, but there’s no underlying bug
here, as the maximum requested read size is 4 bytes anyway.

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

Helps: #3527
2025-02-06 12:26:14 +00:00
Philip Withnall
49d8185d03 gscanner: Fix -Wshorten-64-to-32 warning when reading an integer token
There’s already a documented explicit cast here, so let’s add the
explicit cast in C to match that. Fixes a `-Wshorten-64-to-32` warning.

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

Helps: #3527
2025-02-06 12:26:00 +00: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
Michael Catanzaro
f5eb3fd716 Merge branch 'sysprof-leak' into 'main'
glib.supp: Ignore once-per-thread leak from SysprofCollector

See merge request GNOME/glib!4471
2025-02-05 17:33:40 +00:00
Philip Withnall
aea78c9ac7 docs: Tweak release instructions around signing
Suggest to sign the release commit itself (to keep us in sync with the
Handbook; https://handbook.gnome.org/maintainers/making-a-release.html);
and allow `git tag -s` if `git evtag` is not available (also as per the
Handbook).

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

Fixes: #3424
2025-02-04 17:02:04 +00:00
Philip Withnall
7fffe59037 Merge branch 'wip/pwithnall/soft-c11-dependency' into 'main'
build: Add a soft dependency on C11

See merge request GNOME/glib!4473
2025-02-04 16:35:33 +00:00
Philip Withnall
0445d555e0 docs: Stop mentioning outdated C versions in various docs
Link to the toolchain requirements, which are kept up to date, rather
than duplicating them across multiple documents.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 16:01:44 +00:00
Philip Withnall
445eea668a build: Add a soft dependency on C11
This will warn if GLib is configured with a toolchain which doesn’t
support C11. We currently require C99. If nobody complains (as directed
by this warning) we will start to require C11 in the next unstable
release series (2.85).

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3574#note_1859924

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 15:59:51 +00:00
Philip Withnall
97fdba0d2f Merge branch 'cancellable-source-dispose-races' into 'main'
gcancellable: Ignore cancelled callback on disposed source

Closes #3448

See merge request GNOME/glib!4206
2025-02-04 14:40:56 +00: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
62c1ae7161 glib.supp: Ignore once-per-thread leak from SysprofCollector
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-04 10:47:43 +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
Philip Withnall
e96bc30c16 Merge branch 'ebassi/goption-flag-deprecated' into 'main'
Add G_OPTION_FLAG_DEPRECATED

See merge request GNOME/glib!4046
2025-02-03 15:37:23 +00:00
Emmanuele Bassi
b145330b75 Add G_OPTION_FLAG_DEPRECATED
Generate a deprecation notice in the `--help` output for deprecated
options. This helps with the documentation of command line utilities.

Put the deprecation notice near the argument, to allow application
developers to add a notice on the deprecation on their own, and
explain what to use instead.
2025-02-03 15:37:23 +00:00
Philip Withnall
b9a4039271 Merge branch 'main' into 'main'
Add support for QNX8.0

See merge request GNOME/glib!4466
2025-02-03 15:10:06 +00:00
Philip Withnall
cac9100960 Merge branch 'ebassi/gtype-refcount' into 'main'
Drop TypeNode reference counting

See merge request GNOME/glib!3255
2025-02-03 14:38:24 +00:00
Emmanuele Bassi
dc86ad1925 Drop TypeNode reference counting
We don't allow unloading types, both static and dynamic, since 2013. The
code that deals with reference counting is mostly dead code, and makes
reasoning about the type system more complicated than necessary.

Since type classes and interfaces can only be instantiated, we introduce
explicit getter functions that create a GTypeClass or a GTypeInterface
vtable; the ref() and unref() API gets a "soft" deprecation (explicitly
not using `GOBJECT_DEPRECATED_IN_*` yet), to allow people to
progressively port their code.
2025-02-03 14:38:24 +00: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
Philip Withnall
0621d0ddb8 Merge branch 'glib-function-pointer-requirements' into 'main'
Document function pointer cast requirements

Closes #3595

See merge request GNOME/glib!4469
2025-02-03 11:40:12 +00:00
Demi Obenour
9eb0828bd8 Document function pointer cast requirements
Helps: #3596
Fixes: #3595
2025-02-03 11:40:12 +00:00
Michael Catanzaro
9b1e0a583a Merge branch 'gi-static-vfuncs' into 'main'
Support static vfuncs in GIRepository

See merge request GNOME/glib!4457
2025-02-01 14:10:57 +00: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
Philip Withnall
9c7a57dcc5 Merge branch 'issue-3587-2' into 'main'
gosxappinfo: Fix leak

See merge request GNOME/glib!4464
2025-01-28 15:40:26 +00:00
Andre Miranda
62d8d0b6ec gosxappinfo: Fix leak
Slightly reworked by Philip Withnall (any mistakes his).
2025-01-28 12:03:10 +00:00
Philip Withnall
fcc610791b Merge branch 'issue-3587' into 'main'
gosxappinfo: Correctly launch list of files

Closes #3587

See merge request GNOME/glib!4462
2025-01-24 12:29:54 +00:00
Andre Miranda
8b64bb8751 gosxappinfo: Correctly launch list of files
Fixes #3587
2025-01-24 12:29:54 +00:00
Michael Catanzaro
0c38fd3c14 Merge branch 'docs-updates' into 'main'
docs: Update the release documentation for the new release workflow

See merge request GNOME/glib!4461
2025-01-23 16:00:56 +00:00