Commit Graph

30912 Commits

Author SHA1 Message Date
Julian Sparber
89488e98e9 gopenuriportal: Use task data instead of object data
The docs recommend using a small number of `keys` when setting data for an
object, the OpenURI portal uses three different `keys` that can easily be replaced
with `g_task_set_task_data()`.
2024-10-01 18:25:37 +02:00
Julian Sparber
ef064d625b gopenuriportal: Fix two memory leaks 2024-10-01 18:25:31 +02:00
Philip Withnall
f6d7878a54 Merge branch 'speed-up-query-exists' into 'main'
gio: Add a query_exists vfunc to GFile

See merge request GNOME/glib!4272
2024-10-01 15:45:04 +00:00
Philip Withnall
2b5d3b5831 Merge branch 'fake-document-portal-in-process' into 'main'
tests: Move fake-document-portal subprocess inside dbus-appinfo test

See merge request GNOME/glib!4311
2024-10-01 15:38:30 +00:00
Matthias Clasen
ab51ed0521 gio: Implement query_exists for resources
This avoids allocations for this frequently used method.
2024-10-01 16:35:54 +01:00
Matthias Clasen
65ad41d8a4 gio: Implement query_exists for local files
We can’t quite use `access()` for this, like `g_file_test()` does, as
`g_file_query_info()` considers a broken symlink to exist, so we need to
match that by passing `AT_SYMLINK_NOFOLLOW`.

We also use the `AT_EACCESS` flag, which makes the `faccessat()` call
cheaper on Hurd.

Systems without `faccessat()` will continue to use the
`g_file_query_info()`-based implementation of `g_file_query_exists()`.

(Commit message rewritten by Philip Withnall.)
2024-10-01 16:27:29 +01:00
Matthias Clasen
85ce99f4ad gio: Add a query_exists vfunc to GFile
g_file_query_exists looks like a simpler and faster api than
g_file_query_info. This vfunc lets us actually make it faster,
and avoid allocations in this frequently used code path.
2024-10-01 16:25:57 +01:00
Philip Withnall
e14a393d27 Merge branch '3483-mainloop-test' into 'main'
tests: Rework a mainloop test to use an explicit termination condition

Closes #3483

See merge request GNOME/glib!4324
2024-10-01 15:00:03 +00:00
Philip Withnall
9e73d9a15a Merge branch 'utf8-docs' into 'main'
gutf8: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4304
2024-10-01 14:53:53 +00:00
Philip Withnall
f8ba505dc1
gutf8: Clarify position of end returned from g_utf8_validate()
It wasn’t previously clear (to me) whether `end` was returned pointing
to the nul terminator, or to the byte immediately preceding it. Try and
clarify that.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 15:44:43 +01:00
Philip Withnall
7302c04e32
gutf8: Convert docs to gi-docgen linking syntax
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2024-10-01 15:44:36 +01:00
Philip Withnall
766f3414eb Merge branch 'steal-handle-id' into 'main'
utils: Add g_steal_handle_id() to complement g_clear_handle_id()

See merge request GNOME/glib!4308
2024-10-01 14:25:58 +00:00
Philip Withnall
6b2cc430e0
tests: Run dbus-appinfo tests with G_TEST_OPTION_ISOLATE_DIRS
Eliminate any possibility of them accidentally using the user’s
actual home directory.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 15:22:46 +01:00
Philip Withnall
d7e368f206
tests: Move fake-document-portal subprocess inside dbus-appinfo test
For the reasons given in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4176#note_2233317,
it’s best to not rely on subprocesses when writing tests. Spawning a
subprocess can go wrong, getting feedback and assertion data from a
subprocess is a pain, and making sure the subprocess is killed properly
at the end of the test is hard to get right.

For tests where we are trying to mock a D-Bus service, it’s much more
reliable to run that service in-process (either in the main thread or in
a separate thread).

So, do that for the `fake-document-portal` former subprocess in the
`dbus-appinfo` test: move it to a worker thread.

This speeds the test up, simplifies the build slightly, and should make
the test run more reliable.

In particular, it provides a pattern for future `fake-*-portal` tests to
be built off. This is particularly useful for more complex portals,
where data needs to be relayed back from the mock portal service to the
unit test to check that the code under test has behaved properly. That’s
a pain to do from a subprocess.

Delete the `org.freedesktop.portal.Documents.service` file because we no
longer need to rely on D-Bus service activation within the test, as
we’re setting up the mock service thread explicitly now.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 15:22:40 +01:00
Michael Catanzaro
04543594d4 Merge branch 'gbytes-double-free' into 'main'
gbytes: Add an assertion to placate static analysis

See merge request GNOME/glib!4323
2024-10-01 14:04:13 +00:00
Michael Catanzaro
637ec98f2e Merge branch 'disable-assert-fix' into 'main'
gvariant: Fix unused variables when G_DISABLE_ASSERT is defined

See merge request GNOME/glib!4322
2024-10-01 13:57:04 +00:00
Philip Withnall
dfb0ea737b
gstdio: Move doc comment for g_clear_fd() to be next to the code
Nobody’s going to keep it up to date if it’s floating about in an
unrelated place, not next to the code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 14:29:31 +01:00
Philip Withnall
f9d1f614a9
gmain: Move doc comment for g_steal_fd() to be next to the code
Nobody’s going to keep it up to date if it’s floating about in an
unrelated place, not next to the code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 14:29:25 +01:00
Philip Withnall
a960725b5d
glib: Add declarations for public static inline methods
This is needed in order to expose them in the GIR, and hence for their
documentation to work.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4308#note_2236525

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 14:29:18 +01:00
Philip Withnall
431e75fa36
utils: Add g_steal_handle_id() to complement g_clear_handle_id()
Just like we have `g_steal_pointer()` and `g_clear_pointer()`, it would
be useful to have a ‘steal’ version of `g_clear_handle_id()`.

Particularly in situations where a clear function can’t be represented
as a `GClearHandleFunc`, such as
`g_dbus_connection_signal_unsubscribe()` (there’s no way of passing the
`GDBusConnection` to it) — or in situations where a handle ID isn’t
being released, but is being passed from one struct to another or from a
local scope to a struct or vice-versa.

Includes unit tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 14:29:05 +01:00
Philip Withnall
a40a33dfe0
tests: Rework a mainloop test to use an explicit termination condition
And to not assume that every main context iteration will provide
progress on the sources that the test is interested in. It’s possible
that other sources may be attached to the `GMainContext` which get
dispatched instead of the pipe sources on an iteration.

I don’t know if this will fix #3483, but it will certainly make this
test a little tidier. It doesn’t affect test run time.

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

Fixes: #3483
2024-10-01 13:32:29 +01:00
Philip Withnall
df8592268a
gbytes: Add an assertion to placate static analysis
Otherwise `scan-build` thinks it’s possible for the `GBytes` to be
double-freed, which would indeed happen if `try_steal_and_unref()` were
to return `NULL` on this branch.

It’s not actually possible for it to return `NULL` here though, as if
`bytes->data` were `NULL`, the function would have already returned
higher up.

Fixes this `scan-build` failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/4359929

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 13:15:15 +01:00
Philip Withnall
cc2b78ec47 Merge branch 'string-replace-tests' into 'main'
fuzzing: Add simple fuzz test for g_string_replace()

See merge request GNOME/glib!4315
2024-10-01 12:00:43 +00:00
Philip Withnall
a083ae415b Merge branch 'wip/chergert/gvariant-padding' into 'main'
gvariant: Add portable alignment fix for GVariant suffix

Closes #3486

See merge request GNOME/glib!4320
2024-10-01 11:42:27 +00:00
Philip Withnall
c920d2257b
gvariant: Fix unused variables when G_DISABLE_ASSERT is defined
This fixes commit 9eb9df2396, which I really should have noticed at the
time would cause a load of unused variables to be declared if compiled
with `G_DISABLE_ASSERT`. That’s what the original `#ifdef`s were to
protect against.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-10-01 12:24:30 +01:00
Christian Hergert
4db378a739 gvariant: Add portable alignment fix for GVariant suffix
We want to keep the suffix aligned to 8 bytes on 32-bit too. This makes
sure we do that in a way that is portable across our supported compilers.

Fixes: #3486
2024-10-01 12:19:26 +01:00
Philip Withnall
e4f5c2e9c5 Merge branch 'gvariant-32bit-msvc' into 'main'
gvariant-core.c: Fix suffix alignment on 32-bit MSVC builds

See merge request GNOME/glib!4321
2024-10-01 11:11:45 +00:00
Chun-wei Fan
1b9d3964f5 gvariant-core.c: Fix suffix alignment on 32-bit MSVC builds
With a similar rationale to commit d50102f2, this avoids the static
assert from failing on 32-bit Visual Studio builds.
2024-10-01 17:25:37 +08:00
Philip Withnall
c96cd22cf9 Merge branch '3042-msys2-still-intermittent' into 'main'
Revert "CI: Mark msys2-mingw32 as allowing failures"

Closes #3042

See merge request GNOME/glib!4190
2024-09-29 12:56:15 +00:00
Philip Withnall
fe8e4eb6db
ci: Clarify msys2 allow-failure policy
See the previous commit and discussion on #3420.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-29 13:36:03 +01:00
Philip Withnall
53f20d79b8
Revert "CI: Mark msys2-mingw32 as allowing failures"
This reverts commit 16819a4024.

The failure this was added for is intermittent and has been going on a
long time; it’s not a new failure caused by msys2 dependency/packaging
changes, so the policy in .gitlab-ci.yml doesn’t apply.

It would be great if someone fixed #3042, but un-gating GLib from msys2
testing is not the right tradeoff for it.

See: #3042
2024-09-29 13:35:57 +01:00
Philip Withnall
034d528348 Merge branch 'fix-msys2-mingw32-ci' into 'main'
ci: Only build gobject-introspection if the system version is too old

Closes #3464

See merge request GNOME/glib!4317
2024-09-29 12:33:08 +00:00
Philip Withnall
d50102f2d8
gvariant: Fix suffix alignment on 32-bit machines
This fixes commit 0b083e3d8c. The static assertion added in that commit
fails on 32-bit machines.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-29 13:12:31 +01:00
Philip Withnall
d3e0d4fbde
gpoll: Remove unused variable
Fixes commit 3baf1f1a73.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-29 12:30:53 +01:00
Philip Withnall
96652e7def
ci: Only build gobject-introspection if the system version is too old
We want to build GLib against a matched version of
gobject-introspection, and this version will probably be bumped quite
often as the two are developed in tandem.

However, if the CI system provides a newer version, we should probably
use that, otherwise we’re essentially downgrading part of the OS on the
CI system, and that probably will result in issues. In particular,
gobject-introspection <1.82 has a bug on MSYS2 which means it doesn’t
build (see issue #3464).

So, build gobject-introspection manually if the CI system version is too
old, otherwise use the system version. Do this programmatically so we
don’t have to repeatedly add and remove the gobject-introspection build
commands from the CI configuration as versions are bumped.

Fixes: #3464
2024-09-29 12:25:35 +01:00
Philip Withnall
e115eafb8a
lcov: Fix use of deprecated lcov_branch_coverage option
This option was renamed to `branch_coverage` in more recent versions of
lcov. This might explain why branch coverage is not being collected by
CI at the moment.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-28 22:38:00 +01:00
Philip Withnall
4136db0a8c
fuzzing: Add simple fuzz test for g_string_replace()
Now that the implementation of it is significantly more complex,
involving pointer arithmetic, it should probably be fuzzed. It’s not an
API which is obviously used to handle untrusted input, but some users of
GLib might do so.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-28 22:37:53 +01:00
Philip Withnall
303f04286e Merge branch 'feature' into 'main'
remove quadratic behavior in g_string_replace

See merge request GNOME/glib!4313
2024-09-28 21:09:53 +00:00
James Tirta
e8517e7776 remove quadratic behavior in g_string_replace
Current implementation replaces find in string with replace
one-at-a-time and replacement is done in O(n^2) time. The new
implementation is O(n). Memory allocation is done once instead of
incrementally.

In the old implementation, every replacement will move the whole
rest of the string from the current position to make space for
the replace string and then insert the replace string.

In the new implementation, when the replace string is shorter or equal
to the find string, it will move the characters in-place and requires no
additional memory. When the replace string is longer, find the required
size needed for the new string and preallocate a new string to copy the
original string to with its replacements. When the replace string is an
empty string use the old implementation to handle the special case.
2024-09-28 21:09:53 +00:00
Philip Withnall
e1af498896 Merge branch 'amolenaar/fix-macos-url-launcher' into 'main'
macos: Fix URL launcher

Closes #3484

See merge request GNOME/glib!4312
2024-09-28 17:20:51 +00:00
Arjan Molenaar
fd6c1f34da macos: Fix URL launcher
URLs should be provided to the AppInfo.launch_uris() function.
2024-09-27 21:45:33 +02:00
Philip Withnall
d7bb4664e7
tests: Add a way to get the mock session bus address in tests
This is better than using `g_getenv ("DBUS_SESSION_BUS_ADDRESS")` as it
will fail more explicitly if the mock bus somehow isn’t running.

This will be used in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-27 17:08:21 +01:00
Philip Withnall
019de2cbbc Merge branch 'wip/chergert/gvariant-inline-suffix-data' into 'main'
glib/gvariant: Inline small gvariant data using C99 flexible arrays

See merge request GNOME/glib!4301
2024-09-27 12:35:05 +00:00
Philip Withnall
0a9573b53b Merge branch 'wip/lantw/tests-FreeBSD-doesn't-use-glibc' into 'main'
tests: FreeBSD doesn't use glibc

See merge request GNOME/glib!4310
2024-09-27 11:34:36 +00:00
Ting-Wei Lan
095fd5a06b tests: FreeBSD doesn't use glibc
FreeBSD has its own libc implementation. It is maintained as a part of
the operating system, not a copy of glibc.
2024-09-27 11:41:33 +08:00
Christian Hergert
0b083e3d8c glib/gvariant: Avoid many GBytes allocation
Previously, all GVariants would allocate a GBytes for the buffered
contents. This presents a challenge for small GVariant type created
during the building process of GVariantBuilder as that results in an
allocation for the GVariant, GBytes, and the byte buffer.

Recent changes for GBytes may reduce those 3 allocations to 2, but even
that is quite substantial overhead for a 32-bit integer.

This changeset switches GVariant to use g_new/g_free allocators instead
of g_slice_new/free. When benchmarked alone, this presented no
measurable difference in overhead with the standard glibc allocator.

With that change in place, allocations may then become variable in size
to contain small allocations at the end of the GVariant reducing things
to a single allocation (plus the GVariantTypeInfo reference).

The size of GVariant is already 1 cacheline @ 64-bytes on x86_64. This
uses that to guarantee our alignment of data maintains the 8-bytes
guarantee of GVariant, and also extends it to match malloc().

On 32-bit systems, we are similarly aligned but reduce the amount we
will inline to 32 bytes so we have a total of 1 cacheline.

This is all asserted at compile-time to enforce the guarantee.

In the end, this changeset reduces the wallclock time of building many
GVariant in a loop using GVariantBuilder by 10% beyond the 10% already
gained through GBytes doing the same thing.
2024-09-26 14:28:41 -07:00
Michael Catanzaro
0012d1921d Merge branch 'main' into 'main'
fix https://gitlab.gnome.org/GNOME/glib/-/issues/3444

Closes #3444

See merge request GNOME/glib!4309
2024-09-26 21:01:20 +00:00
stefan11111
89480c2e0a fix https://gitlab.gnome.org/GNOME/glib/-/issues/3444 2024-09-26 22:47:30 +03:00
Philip Withnall
c2a5bd2c65 Merge branch 'wip/chergert/no-copy-gvarianttype-stack-builder' into 'main'
glib/gvariant: avoid GVariantType copy for stack builders

See merge request GNOME/glib!4286
2024-09-26 11:57:26 +00:00
Christian Hergert
0f95b18a7b gio: use g_variant_builder_init_static()
All uses of g_variant_builder_init() in gio are safe to translate to the
new g_variant_builder_init_static() alternative as the type will outlive
the call to g_variant_builder_end() (or is already static in nature).
2024-09-26 12:48:16 +01:00