Commit Graph

31720 Commits

Author SHA1 Message Date
Philip Withnall
be8c76c98c Merge branch 'networkmonitor-jail' into 'main'
Fix GNetworkMonitorNetlink operation under a FreeBSD jail with shared network stack

See merge request GNOME/glib!4603
2025-04-21 22:28:49 +00:00
Gleb Popov
b479d14371 Fix GNetworkMonitorNetlink operation under a FreeBSD jail with shared network stack 2025-04-21 22:28:49 +00:00
Philip Withnall
80e3ea1e1d Merge branch 'larma/cocoa-notification-bytes-icon' into 'main'
cocoa: add support for GBytesIcon in notification backend

See merge request GNOME/glib!4604
2025-04-21 21:39:33 +00:00
Marvin W
cf44fb0d2a cocoa: add support for GBytesIcon in notification backend 2025-04-18 14:36:34 +02:00
Thomas Haller
88f5db3e75 gobject/docs: remove wrong paragraph from GWeakRef docs
The "without first having or creating a strong reference" part is wrong.

While we invoke the dispose() method, we always still hold the last
reference. The calling thread called g_object_unref() with a strong
reference that we are about to give up, but at the point where we call
dispose(), we didn't yet decrement the ref count to zero. Doing so would
be a fatal bug.

As such, during dispose() the object is still healthy and still has a
strong pointer. You can call `g_weak_ref_set()` on that pointer without
taking an additional strong reference. Of course, if you don't actually
take a strong reference (and thus don't resurrect the object), then
right afterwards, the last reference is dropped to zero, and the
GWeakRef gets reset again.

But there is no need to claim that you need to take another strong
reference to set a GWeakRef during dispose(). This was always the case.

Also, reword the previous paragraph. I think this is clearer.
2025-04-17 18:07:27 +02:00
Michael Catanzaro
e237ec6c81 Merge branch 'get-binding-data-caller-allocates' into 'main'
gtlsconnection: Fix annotation

See merge request GNOME/glib!4598
2025-04-14 17:28:24 +00:00
Michael Catanzaro
ca99d65867 Merge branch 'contributing-tests' into 'main'
docs: Mention how to run the test suite in CONTRIBUTING.md

See merge request GNOME/glib!4596
2025-04-14 14:47:20 +00:00
Sergey Bugaev
bf266f4116 gtlsconnection: Fix annotation
The array is allocated by the *caller*, not the callee, and then filled
by the callee during the call.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2025-04-14 15:32:18 +03:00
Philip Withnall
c077153699 docs: Mention how to run the test suite in CONTRIBUTING.md
We don’t want `CONTRIBUTING.md` to become an exhaustive manual of how to
contribute to what is a fairly standard C project using Meson, but it is
a fairly helpful hint to mention how to run the test suite. Then people
can use `meson test --help` and the Meson documentation to learn more.

Pointed out on !4589.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-12 18:32:09 +01:00
Philip Withnall
841b565b8d Merge branch 'fix-wrong-typelib-path' into 'main'
Windows: fix wrong typelib path

Closes #3657

See merge request GNOME/glib!4582
2025-04-12 15:45:52 +00:00
Dan Yeaw
5f12b1b400 Windows: fix wrong typelib path 2025-04-12 15:45:51 +00:00
Philip Withnall
ecc1f86e92 gmodule: Fix a minor -Wsign-conversion error on Windows
Spotted by CI: https://gitlab.gnome.org/pwithnall/glib/-/jobs/4968919

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

Helps: #3405
2025-04-12 16:25:03 +01:00
Philip Withnall
21d8e246e7 girepository: More minor -Wsign-conversion fixes from CI
These didn’t occur on my local machine, interestingly.

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

Helps: #3405
2025-04-12 16:24:32 +01:00
Philip Withnall
3de99090d0 girepository: Enable -Wsign-conversion for girepository subdirectory
As with previous commits, we’re enabling `-Wsign-conversion` piecemeal
for all of glib.git.

The previous few commits have fixed all the `-Wsign-conversion` warnings
in libgirepository, so let’s enable the warning by default for that
directory to prevent regressions.

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

Helps: #3405
2025-04-11 23:56:49 +01:00
Philip Withnall
7c06269eef girparser: Limit the size of GIR files which can be parsed
Due to passing around file lengths variously as `gsize` or `gssize`,
we can’t reliably handle files with length greater than `G_MAXSSIZE`, as
some of the APIs in use need `-1` to indicate that their input is nul
terminated.

Add some checks for this, and gracefully return an error if an input
file is too big, rather than just exploding.

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

Helps: #3405
2025-04-11 23:56:44 +01:00
Philip Withnall
4a29abe9f7 girparser: Stop setting blob length to -1 when no length is set
When parsing a GIR or building a typelib, stop setting the array length
field to `-1` as a default. That field is unsigned, so setting it to
`-1` is actually equivalent to setting it to `G_MAXUINT`. I can’t find
anywhere which treats `G_MAXUINT` or `-1` as a magic value there, so
it’s probably better off left unset.

Given the lack of documentation for the typelib code, though, there is a
fair chance I’m making a mistake and this is actually an integral part
of the format. Let’s see what breaks.

This fixes a `-Wsign-conversion` warning, at least.

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

Helps: #3405
2025-04-11 23:56:39 +01:00
Philip Withnall
debb6a9cc0 tests: Add a basic test for GIIrParser type parsing
This follows up from the previous two commits to add a unit test.

It doesn’t attempt to cover the multitude of other possible type parsing
conditions; at the moment it’s just a regression test for the previous
two commits, and somewhere to hang new tests on in future.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 23:56:35 +01:00
Philip Withnall
cff7783a32 girparser: Fix error handling for type parsing
Reworking the code to add proper `GError` handling for type parsing,
rather than the existing `g_critical()`, turned out to actually be
fairly straightforward.

So now `gi_ir_parser_parse_string()` returns
`G_MARKUP_ERROR_INVALID_CONTENT` on unparseable types, just like it does
with various other bits of invalid GIR.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 23:56:30 +01:00
Philip Withnall
e6d34fa5a8 girparser: Fix a potential buffer overflow with g_strndup()
If parsing a generic type which has no closing `>`, there was no check
that the `strchr()` call succeeded, which could have resulted in a
negative length being passed to `g_strndup()`, which would result in a
long positive length after implicit type casting.

Fix that by bringing an old error handling path back into use. This
results in a `g_critical()` in the calling function, which is good
enough for now. Potentially all this code could be reworked to use
`GError`, but that’s a much bigger project (a lot more of the
`girparser.c` code would need to change).

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

Helps: #3405
2025-04-11 23:56:26 +01:00
Philip Withnall
8ab78a66a4 girepository: Fix -Wsign-conversion warnings with string arithmetic
There are a few `g_strndup()` calls which use a length calculated from
the return value of `strchr()` minus the original string. That’s fine,
as long as `strchr()` doesn’t return `NULL`. Add some asserts to ensure
that.

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

Helps: #3405
2025-04-11 23:56:21 +01:00
Philip Withnall
f44511bc54 girepository: Fix straightforward -Wsign-conversion warnings
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2025-04-11 23:56:17 +01:00
Philip Withnall
4b7f0a8f50 gthread: Enable -Wsign-conversion for gthread subdirectory
As with previous commits, we’re enabling `-Wsign-conversion` piecemeal
for all of glib.git.

It turns out that gthread didn’t have any `-Wsign-conversion` warnings
at all, so this was straightforward.

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

Helps: #3405
2025-04-11 23:56:12 +01:00
Philip Withnall
95fa8de2c3 gmodule: Enable -Wsign-conversion for gmodule subdirectory
There was only one `-Wsign-conversion` warning in the whole
subdirectory, so that was easy.

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

Helps: #3405
2025-04-11 23:56:08 +01:00
Philip Withnall
96178eb9c0 gobject: Fix a few more -Wsign-conversion warnings
These are all fairly straightforward, but I didn’t get them locally;
they only showed up on CI.

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

Helps: #3405
2025-04-11 23:48:23 +01:00
Philip Withnall
4ddea1f6c0 gobject: Enable -Wsign-conversion for gobject subdirectory
Fixing #3405 is going to take a lot of work, so let’s split it up into
pieces and work on them separately. The `gobject/` and `gobject/tests/`
directories now compile cleanly with `-Wsign-conversion` (see the
previous commits), so let’s enable the warning for those directories to
prevent regressions while we continue to work on the other directories.

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

Helps: #3405
2025-04-11 23:48:19 +01:00
Philip Withnall
e27d64e651 tests: Fix -Wsign-conversion warnings for random ints in gobject tests
There’s a painful inconsistency in the types of the
`g_{test_rand,random,rand}_int{,_range}()` functions, which vary
arbitrarily between `gint32` and `guint32`.

Unfortunately since those functions mention `int` explicitly in the name
(and then some of them return an `unsigned` integer), I don’t see a way
to make the APIs consistent without significant deprecations or
additions.

So, for the moment, to fix various `-Wsign-conversion` warnings, plaster
the tests with casts.

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

Helps: #3405
2025-04-11 23:48:14 +01:00
Philip Withnall
ba4f5ca44e tests: Explicitly cast src value in param conversion tests
This fixes a load of -Wsign-conversion warnings. The dest type setter
function is being used (presumably by design?) so there’s sometimes a
type mismatch (signed/unsigned, or size) with the constant value being
used by the test. This just makes the existing implicit casts explicit.

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

Helps: #3405
2025-04-11 23:48:09 +01:00
Philip Withnall
bad7a32504 tests: Fix various -Wsign-conversion warnings with flags in gobject tests
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2025-04-11 23:48:04 +01:00
Philip Withnall
ee2d25b57a tests: Fix various straightforward -Wsign-conversion warnings
In the gobject tests.

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

Helps: #3405
2025-04-11 23:48:00 +01:00
Philip Withnall
b3ebef609f tests: Fix various unsigned/signed comparisons in gobject tests
Fix all the instances where `-Wsign-conversion` was pointing out that
`g_assert_cmpint()` had been used on unsigned inputs, or vice-versa.

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

Helps: #3405
2025-04-11 23:47:56 +01:00
Philip Withnall
752c0787d6 gparamspecs: Fix -Wsign-conversion warnings for large constants
Not sure why these constants were chosen the way they were, but that’s
not a problem I’m going to investigate right now. This just makes the
implicit cast explicit to shut the compiler warning up.

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

Helps: #3405
2025-04-11 23:47:51 +01:00
Philip Withnall
633e49c8d1 gobject: Cast various inverted bitfield constants to unsigned
This fixes `-Wsign-conversion` warnings, though I’m not sure why the
compiler is emitting them. The signed/unsigned status of flag enum
members is not particularly well defined in the C standard (and even
less well understood by me), so just do what seems necessary to shut the
compiler up.

The benefits of enabling `-Wsign-conversion` across the codebase
hopefully outweighs this noise.

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

Helps: #3405
2025-04-11 23:47:47 +01:00
Philip Withnall
70ddc35340 gparamspecs: Fix some guint to gboolean conversion warnings
While we’re at it, rename the variables to make the intent a bit
clearer: these functions return a boolean indicating whether any of the
values were modified to make them valid. `n_changed` is a counter of the
number of modified values.

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

Helps: #3405
2025-04-11 23:47:42 +01:00
Philip Withnall
615cd4c10c gobject: Fix a guint to gboolean conversion warning
Make the conversion explicit. Fixes some `-Wsign-conversion` warnings.

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

Helps: #3405
2025-04-11 23:47:38 +01:00
Philip Withnall
636bbd1d63 gobject: Fix several int/unsigned conversions with atomics
Unfortunately the signatures of our atomic functions alternate between
using signed and unsigned integers across different functions, so we
can’t just use one type as input. Add some explicit casts to fix
harmless `-Wsign-conversion` warnings.

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

Helps: #3405
2025-04-11 23:47:33 +01:00
Philip Withnall
efed9028fa gobject: Fix various straightforward -Wsign-conversion warnings
None of these should have caused user-visible bugs.

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

Helps: #3405
2025-04-11 23:47:29 +01:00
Philip Withnall
b9d2719222 gboxed: Use new g_string_copy() as boxed copy for GString
Rather than reinventing it ourselves. The old version in `gboxed.c`
could lose the second half of very long strings, as it truncated the
`size_t` string length to the `ssize_t` accepted by
`g_string_new_len()`.

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

Helps: #3405
2025-04-11 23:47:24 +01:00
Philip Withnall
3048266aa3 gstring: Add a new g_string_copy() method
This does a deep copy on the `GString`.

It means we can eliminate the less-efficient version currently used for
`GBoxed`, which also has `-Wsign-conversion` problems. See the following
commit.

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

Helps: #3405
2025-04-11 23:47:19 +01:00
Philip Withnall
b6937c9b32 tests: Remove unnecessary prefix from GString test names
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 14:44:21 +01:00
Philip Withnall
2d66caf6cb Merge branch 'wsign-conversion' into 'main'
Various -Wsign-conversion warning fixes

See merge request GNOME/glib!4590
2025-04-11 13:35:16 +00:00
Philip Withnall
1cd4ace6a5 gchecksum: Add an internal helper to avoid signed conversion
Add an internal helper for `g_checksum_update()` to avoid having to take
its length as a `gssize` for internal users who already know the input
length.

Fixes a `-Wsign-conversion` warning.

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

Helps: #3405
2025-04-11 14:03:04 +01:00
Philip Withnall
7bcabd3900 gchecksum: Fix various -Wsign-conversion warnings
These are all fairly straightforward cases.

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

Helps: #3405
2025-04-11 14:02:59 +01:00
Philip Withnall
98ab3d7a87 xdgmime: Disable -Wsign-conversion warning inside xdgmime
The code wasn’t written for it, and we don’t want to diverge from
upstream for this, so disable -Wsign-conversion in case it was set for
the overall GLib build.

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

Helps: #3405
2025-04-11 14:02:55 +01:00
Philip Withnall
7aeb4d94f2 gcharset: Fix potential negative string offsets in g_get_locale_variants()
The parser was assuming that all three separators (`_@.`) were in order;
but the input might not contain them in order. In that case, the parser
would have passed negative values to `g_strndup()` which would have been
implicitly cast to large positive values, and potentially exposed a lot
of memory (until the first nul byte, which was probably quite soon).

Expand the existing `g_get_locale_variants()` test to cover some invalid
parsing, and add a fuzzing test too.

Spotted by `-Wsign-conversion`.

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

Helps: #3405
2025-04-11 14:02:51 +01:00
Philip Withnall
c6884c95f6 tests: Use g_assert_*() rather than g_assert() in utils tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 14:02:46 +01:00
Marco Trevisan
4f2be73c7e Merge branch 'gstring-gsize' into 'main'
gstring: Make len_unsigned unsigned

See merge request GNOME/glib!4592
2025-04-11 05:52:33 +00:00
Peter Bloomfield
4d435bb480 gstring: Make len_unsigned unsigned 2025-04-11 05:52:33 +00:00
Michael Catanzaro
5c48576223 Merge branch 'mcatanzaro/check-only-has-loopback-interfaces' into 'main'
gthreadedresolver: fix crash in loopback interface check

See merge request GNOME/glib!4591
2025-04-10 21:37:45 +00:00
Michael Catanzaro
defec7eef2 gthreadedresolver: fix crash in loopback interface check
It's expected that an interface may have a NULL socket address, so just
skip it and don't crash if so. In practice, this occurs for VPN
interfaces.

Fixes: fe0139ee98
2025-04-10 15:42:21 -05:00
Philip Withnall
07db5ba5f6 gcharset: Fix a trivial -Wsign-conversion warning
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2025-04-10 20:36:00 +01:00