Commit Graph

8875 Commits

Author SHA1 Message Date
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
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
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
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
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
Christian Hergert
bfac590364 gio/gdbus-codegen: use g_variant_builder_init_static()
Make the generated GDBus-based code use GVariantBuilder with a static
GVariantType to avoid copying the GVariantType on each use.

This is gated behind a GLib 2.83.0 check.
2024-09-26 12:48:16 +01:00
Philip Withnall
2691c5e24e
gdbusdaemon: Fix check for G_ANALYZER_ANALYZING
As with the previous commit, this is _always_ defined in `gmacros.h`
and therefore the `#ifndef` will always be 0 even if disabled.
Just use `#if` instead.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-25 14:30:48 +01:00
Michael Catanzaro
25833cefda gsocks4aproxy: Fix a single byte buffer overflow in connect messages
`SOCKS4_CONN_MSG_LEN` failed to account for the length of the final nul
byte in the connect message, which is an addition in SOCKSv4a vs
SOCKSv4.

This means that the buffer for building and transmitting the connect
message could be overflowed if the username and hostname are both
`SOCKS4_MAX_LEN` (255) bytes long.

Proxy configurations are normally statically configured, so the username
is very unlikely to be near its maximum length, and hence this overflow
is unlikely to be triggered in practice.

(Commit message by Philip Withnall, diagnosis and fix by Michael
Catanzaro.)

Fixes: #3461
2024-09-19 21:08:15 +01:00
Philip Withnall
1adc303f47 Merge branch 'inotify-kqueue' into 'main'
Introduce a new GFileMonitor backend: libinotify-kqueue

See merge request GNOME/glib!3657
2024-09-19 10:13:33 +00:00
Gleb Popov
30dfc99c94 inotify: Optimize consecutive g_hash_table_{lookup,remove} calls 2024-09-19 10:55:39 +03:00
Gleb Popov
697118dfd5 Adapt testfilemonitor.c for libinotify-kqueue backend
The backend mimics inotify but is still subject to kevent idionsyncracies.
2024-09-19 09:55:01 +03:00
Gleb Popov
7460faf861 giomodule: Adapt to the GFileMintor backend selection changes
Instead of relying on some headers/functions presence, the buildsystem now
tells us what backend we're using.
2024-09-19 09:55:01 +03:00
Gleb Popov
dae3b8bd15 Introduce a special mode of operating for the inotify GFileMonitor backend
libinotify-kqueue is a library that implements inotify interface in terms of
kqueue/kevent API available on Mac OS and *BSD systems. The original kqueue
backend seems to be a predecessor version of the code that is currently present
in libinotify-kqueue. Under the hood the library implements a sophisticated
filesystem changes detection algorithm that is derived from the glib backend
code.

Updating the native glib kqueue backend requires substantial work, because code
bases have diverged greatly. Another approach is taken, instead. libinotify-kqueue
can serve as a drop-in replacement for Linux inotify API, thus allowing to
reuse the inotify backend code. The compatibility, however, comes at cost, since
the library has to emulate the inotify descriptor via an unix domain socket.
This means that delivering an event involves copying the data into the kernel
and then pulling it back.

The recent libinotify-kqueue release adds a new mode of operation called "direct".
In this mode the socket pipe is replaced with another kqueue that is used to
deliver events via a kevent(EVFILT_USER) call.
Employing the direct mode requires minor changes to the client code compared
to using plain inotify API, but in return it allows for reusing libinotify's
algorithms without a performance penalty. Luckily, all required changes are
consolidated in one file called inotify-kernel.c

This puts us in the best of possible worlds. On one hand we share a lot of code
with glib inotify backend, which is far more thoroughly tested and widely used.
On the other we support a range of non-Linux systems and consolidate the business
logic in one library. I plan to do the same trick for QFileSystemWatcher which
will give us the same behaviour between Gtk and Qt applications.

The glib test suite passes for both old kqueue backend and new libinotify-kqueue
one. However, the AppStream FileMonitor tests are failing with the old backend,
but pass with the new one, so this is still an observable improvement.

Relevant libinotify-kqueue PR: https://github.com/libinotify-kqueue/libinotify-kqueue/pull/19
2024-09-19 09:54:56 +03:00
Simon McVittie
cb185c22bc GDBus: Don't log a message for G_DBUS_CONNECTION_FLAGS_CROSS_NAMESPACE
This was intended to make it feasible to debug connection failures where
a modern GDBus client connects to a GDBusServer that is missing
glib!2826, but those GDBusServers should be increasingly rare: we have
had the fixed version of GDBusServer for 5 GNOME stable releases
(2 years), long enough to get into stable releases of Debian and Ubuntu
and a service-pack release of SUSE.

This debug message can be very noisy, especially when unit-testing
GLib code (which is frequently done with G_MESSAGES_DEBUG=all) or when
a third-party GLogFunc ignores the log_level parameter and logs all
messages as though they indicated a serious problem. I think it has
served its purpose now.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-09-18 14:04:09 +01:00
Simon McVittie
f1140eceb7 GDBus: Note distros whose GDBusServers require an initial response
Ideally, we would eventually move to always using the
cross-namespace-friendly authentication handshake and never sending an
initial response with the Unix uid or Windows SID, but that's blocked
on waiting for various LTS OS distributions to become unsupported or
otherwise irrelevant. Make a note of some major LTS distributions that
still have an old version that is missing glib!2826.

In the RHEL/CentOS family, CentOS Stream 10 has a fixed version, so
presumably RHEL 10 will have a fixed version when it is released.

In the Debian family, Debian 12 and Ubuntu 24.04 are stable releases
that contain a fixed version.

In the SUSE family, openSUSE 15.6 contains a fixed version, so
presumably so does SLES 15.6.

Faster-moving distributions like Fedora are not a concern here and
can be ignored: it's always the slow-moving and/or LTS distributions
that are going to be holding back interoperability breaks.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-09-18 13:57:22 +01:00
Gleb Popov
c7e2ae30f0 Add Meson option that allows selecting GFileMonitor's backend implementation
The option defaults to 'auto' which keeps the current selection behavior, but
also allows user to override the choice.

Also make the chosen backend is reported to the code via CPP defines.
2024-09-18 12:01:27 +03:00
Philip Withnall
9cb0e9464e
gapplication: Fix a -Wfloat-conversion warning
This introduces no functional changes, but does squash a false positive
warning from `-Wfloat-conversion`:
```
../gio/gapplication.c:462:15: error: implicit conversion turns floating-point number into integer: 'gdouble' (aka 'double') to '_Bool' [-Werror,-Wfloat-conversion]
          if (*(gdouble *) entry->arg_data)
          ~~  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-17 23:55:02 +01:00
Philip Withnall
e888e7d497
tests: Add some explicit float → int casts
This avoids some false positive warnings from `-Wfloat-conversion`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-17 23:54:55 +01:00
Philip Withnall
7a7d8d548a Merge branch 'wfloat-conversion' into 'main'
build: Enable -Wfloat-conversion and fix warnings

See merge request GNOME/glib!4126
2024-09-17 17:57:11 +00:00
Philip Withnall
5197d2856c
gresource: Convert docs to gi-docgen linking syntax
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2024-09-17 14:37:00 +01:00
Philip Withnall
acd4a78173 Merge branch '3465-gresource-error-allocations' into 'main'
gresource: Reduce allocations in g_resources_*() functions

Closes #3465

See merge request GNOME/glib!4242
2024-09-17 13:34:06 +00:00
Philip Withnall
6d408ea76e Merge branch 'macos_arm' into 'main'
Move macOS CI to Apple Silicon runner

Closes #3289

See merge request GNOME/glib!3965
2024-09-12 22:28:10 +00:00
Philip Withnall
b5cab7c6b9
tests: Add g_resource_has_children() test for empty path
To get the code branch coverage up to 100% because it’s not that hard.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-12 22:53:26 +01:00
René de Hesselle
f9b7898fb7 Move to Apple Silicon based runner
Remove cmake as we no longer need to build ninja. We can use the
official wheel now since the runner's Python is 3.9 (before: 3.8).

Use the same comment regarding '--wrap-mode' as in the other jobs.

Download and use official ccache binary.

Add myself to the 'only' section in .gitlab-ci.yml so I can have
CI in my fork.

Disable a few deprecation warnings due to the much newer SDK of
the Apple Silicon machine.
2024-09-12 23:17:23 +02:00
Matthias Clasen
46fdbb43fa resourcefile: Avoid an allocation
Instead of enumerating the children only to throw them away,
use the new g_resources_has_children() api.
2024-09-12 21:15:55 +01:00
Matthias Clasen
a14241c895 resource: Add g_resource[s]_has_children
These functions avoid allocating the children array when it is
not needed.
2024-09-12 21:15:55 +01:00
Matthias Clasen
cb5209282b resource: Small refactoring
Break out a helper function so we can reuse it in the next commit.
2024-09-12 21:15:55 +01:00
Benjamin Gilbert
51e3e7d9ae build: Bump Meson dependency to 1.4.0
Meson 1.5.1 is available in the fd.o SDK and in Debian testing, so the
glib Meson policy says we can update.  Update the minimum only as far as
1.4.0 because we don't yet have a need for 1.5.0.

This allows us to:

- Use file.full_path() to avoid deprecation warnings on str.format(file).
- Set c_std=gnu99,c99 to avoid deprecation warnings with gnu99 on MSVC.

Update all the CI builds to use the latest 1.4.x patch release, 1.4.2.

The FreeBSD runner cannot be updated via `gitlab-ci.yml`, so will be
broken for now.

Similarly, the macOS build will not work unless `-Dc_std=gnu99` is
specified at configure time, due to
https://github.com/mesonbuild/meson/issues/13639.
2024-09-12 19:15:05 +01:00
Philip Withnall
26f2d54840
gresource: Avoid a gettext lookup on a hot error path
See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4242#note_2215991

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

Helps: #3465
2024-09-12 14:42:28 +01:00
Benjamin Gilbert
b7203e9406 build: Drop redundant install_tag arguments for headers
All supported versions of Meson will autodetect the tag.
2024-09-11 22:04:39 -07:00
Silvio Lazzeretti
cfdb60d11d gsocket windows: check event before calling WSAEnumNetworkEvents
The WSAEnumNetworkEvents API is called every time the socket
needs to be checked for status changes. Doing this in an application
with several sockets could generate a high cpu usage since
this call is done for each socket at each iteration of the main loop.
Since there is also a WSAEvent that gets signaled when there is
a change in the status of the socket, checking its status and
calling the WSAEnumNetworkEvents API only if the event is signaled,
can reduce the overall cpu usage.
2024-09-10 09:05:19 +02:00
Philip Withnall
b2d8394f17
tests: Add more coverage for GResource overlays
Test more API entry points with overlays.

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

Helps: #3465
2024-09-09 17:39:39 +01:00
Philip Withnall
c5e196f0c0
tests: Add more G_RESOURCE_ERROR_NOT_FOUND unit tests
Add coverage for handling of this situation for more API entry points.

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

Helps: #3465
2024-09-09 17:38:55 +01:00
Philip Withnall
7ed386a10b
tests: Add test for decompression failure in GResource
This was one of the code paths not currently covered by unit tests, so
let’s add a test for it.

This tests what happens when a structurally valid GResource file, but
with a corrupt entry for a compressed file, is loaded.

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

Helps: #3465
2024-09-09 17:37:52 +01:00
Philip Withnall
f1c639c7dc
tests: Re-indent block in resources test
It was slightly over-indented.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-09 17:36:24 +01:00
Philip Withnall
8b13f8854a
gresource: Remove unnecessary errors from g_resources_lookup_data()
This is slightly more involved than the previous couple of commits, as
`g_resource_lookup_data()` can return two errors: one if the resource is
not found, and another if decompression fails.

We want to avoid allocating the `G_RESOURCE_ERROR_NOT_FOUND` error, as
`g_resources_lookup_data()` will be looping through multiple
`GResource`s trying to find the given path, and all but one of them will
return `G_RESOURCE_ERROR_NOT_FOUND`. For a large application, this can
amount to a lot of `GError`s allocated and then immediately freed on
startup.

Use the split from the previous commit to replace the call to
`g_resource_lookup_data()` with its two constituent parts. We can then
handle errors from them separately, ignoring the `NOT_FOUND` error from
`do_lookup()`, while paying attention to any errors from
`resource_to_bytes()`.

This should result in no functional difference to
`g_resources_lookup_data()`, but fewer allocations overall.

Spotted by Christian Hergert.

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

Helps: #3465
2024-09-09 17:36:18 +01:00
Guido Günther
10910cc896 gio: Improve linking for g_io_input_stream_read_all*
Signed-off-by: Guido Günther <agx@sigxcpu.org>
2024-09-08 10:19:07 +02:00
Guido Günther
cdd807aaa8 gio: Fix overindented docstring of buffer argument
Otherwise it'll be rendered as verbatim block

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2024-09-08 10:18:44 +02:00
Philip Withnall
68a9b9d3ca
gresource: Split g_resource_lookup_data() into two internal helpers
It’s now a call to `do_lookup()` followed by a call to
`resource_to_bytes()`. This makes no functional changes, but will be
useful in the following commit.

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

Helps: #3465
2024-09-05 12:14:15 +01:00
Philip Withnall
87af31604b
gresource: Remove unnecessary errors from g_resources_get_info()
As with the previous commit:

The error here can only ever be `G_RESOURCE_ERROR_NOT_FOUND`, which
`g_resources_get_info()` immediately frees. So let’s avoid allocating
the error in the first place.

Spotted by Christian Hergert.

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

Helps: #3465
2024-09-05 12:09:21 +01:00
Philip Withnall
77ba62c832
gresource: Remove unnecessary errors from g_resources_open_stream()
The error here can only ever be `G_RESOURCE_ERROR_NOT_FOUND`, which
`g_resources_open_stream()` immediately frees. So let’s avoid allocating
the error in the first place.

Spotted by Christian Hergert.

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

Helps: #3465
2024-09-05 12:03:18 +01:00
Philip Withnall
a839737fc8
gresource: Factor out common error setting code
This makes it a bit easier to make sure all the translatable strings are
kept in sync. It introduces no functional changes.

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

Helps: #3465
2024-09-05 12:01:14 +01:00
Philip Withnall
27c02a0be4
tests: Test against a sample mtab file in unix-mounts for getmntent()
The test in `unix-mounts` to see whether `g_unix_mounts_get_from_file()`
can parse an example file was working fine when GLib is built with
libmount, but not when built without it (and hence typically using
`getmntent()`).

This is because libmount supports mountinfo files (like
`/proc/self/mountinfo`), but `getmntent()` only supports mount files
(like `/proc/mounts`). The test was written only with the former.

So, change the test to use mount files when GLib is built without
libmount support.

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

Fixes: #3456
2024-08-27 12:13:35 +01:00
Philip Withnall
dfed38ef03
gmenumodel: Acknowledge in docs that the UI used in the example is old
This kind of deeply nested menu is definitely no longer good UI practice
for most apps (deeply nested menus make things hard to find, and require
good mouse control to navigate). However, it does serve as a good
demonstration of the concepts in `GMenuModel`, so keep it, with a
sentence to acknowledge that it’s not a good UI.

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

Fixes: #3451
2024-08-25 15:34:32 +01:00