Commit Graph

7636 Commits

Author SHA1 Message Date
James Hilliard
d0b9ebbaac meson: fix build without cpp toolchain
We don't need a cpp toolchain for building glib so lets just
automatically disable tests requiring one when not available.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-07-15 12:58:41 -06:00
Marco Trevisan (Treviño)
399f46f8bf giomodule: Use g_once_init_enter/leave to register extensions and load dirs
There's no much change in behavior, but let's take advantages of the tools
we already have to handle these cases.
2022-07-13 00:47:31 +02:00
Marco Trevisan
c752b63143 Merge branch 'wait-for-async-uri-handler-called' into 'main'
gio/tests/desktop-app-info: Wait until the callback is called

See merge request GNOME/glib!2809
2022-07-12 15:46:14 +00:00
Marco Trevisan (Treviño)
ecaa5b5b7a gio/tests/desktop-app-info: Wait until the callback is called
The test was flacky because we were only relying on the presence of a
file, while the callback could have not been called yet, while ensure
for both assumptions to be true before stop iterating the loop.
2022-07-12 17:33:15 +02:00
Philip Withnall
e2639ce56e gsocketclient: Fix passing NULL to g_task_get_cancellable()
Fix a regression from commit abddb42d14, where it could pass `NULL` to
`g_task_get_cancellable()`, triggering a critical warning. This could
happen because the lifetime of `data->task` is not as long as the
lifetime of the `ConnectionAttempt`, but the code assumed it was.

Fix the problem by keeping a strong ref to that `GCancellable` around
until the `ConnectionAttempt` is finished being destroyed.

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

Fixes: #2687
2022-07-12 16:07:23 +01:00
Marco Trevisan (Treviño)
a5390002fc gio-tool-mount: Exit with error in case we can't read from stdin
It's a fatal situation so we can just exit without caring much.
2022-07-06 16:05:33 +02:00
Philip Withnall
59fc26cbaa gio: Add some missing license and copyright headers
These headers have all been written manually, by looking through the git
log for each file and noting the copyright of each significant
contribution.

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

Helps: #1415
2022-07-05 12:30:46 +01:00
Philip Withnall
41691cc4c8 Merge branch 'more-spdx' into 'main'
Add more SPDX license headers

See merge request GNOME/glib!2706
2022-07-05 11:06:49 +00:00
Marco Trevisan
777f0975f9 Merge branch 'content-type-locking' into 'main'
gcontenttype: Fix a potential use-after-free of xdgmime data

See merge request GNOME/glib!2786
2022-06-30 15:01:41 +00:00
Philip Withnall
ecec522835 gcontenttype: Clarify some ownership transfers
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-30 14:21:37 +01:00
Philip Withnall
45d4c52501 gcontenttype: Fix a potential use-after-free of xdgmime data
While `gio_xdgmime` is unlocked, the data which `type` points to in the
xdgmime cache might get invalidated, leaving `type` as a dangling
pointer. That would not bode well for the `g_strdup (type)` call to
insert a new entry into the `type_comment_cache` once `gio_xdgmime` is
re-acquired.

This was spotted using static analysis, and the symptoms have not
knowingly been seen in the wild.

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

Coverity CID: #1474702
2022-06-30 14:21:18 +01:00
Philip Withnall
bd56345f23 Merge branch 'move_assert-msg-test' into 'main'
Convert tests/assert-msg-test* to glib/tests/assert-msg-test*

Closes #1434

See merge request GNOME/glib!2767
2022-06-28 10:41:59 +00:00
Philip Withnall
164d3759fb Merge branch 'mcatanzaro/#2597' into 'main'
Avoid crashing when GProxyResolver returns weird results, and related fixes

Closes #2597

See merge request GNOME/glib!2742
2022-06-28 10:33:33 +00:00
Emmanuel Fleury
5699b7b169 Fix some coding style issues in python tests pointed out by black and flake8 2022-06-28 11:19:21 +01:00
Michael Catanzaro
8e29865112 gproxyresolver: add asserts to ensure error is set
This will catch buggy implementations of GProxyResolver before they are
able to return bogus results to higher level code. In particular, if
g_proxy_resolver_lookup() returns NULL, it'd better set an error to
explain why.
2022-06-27 15:10:25 -05:00
Michael Catanzaro
1738fad172 proxyaddressenumerator: set error parameter more thoughtfully
It doesn't make sense for a proxy resolver to return NULL without an
error on the first call. Whereas a DNS resolver would do this to
indicate that a query completed successfully but found no results, a
proxy resolver should return "direct://" instead. Therefore, if we are
going to return NULL, we ought to have an error as well. Let's make sure
this actually happens by adding some fallback errors just in case
GProxyResolver feeds us weird results.

Additionally, we should not return any errors except
G_IO_ERROR_CANCELLED after the very first iteration. This is an API
contract of GSocketAddressEnumerator. Let's add some checks to ensure
this.

Note that we have inadequate test coverage for GProxyAddressEnumerator.
It's tested here only via GSocketClient. We could do a bit better by
testing it directly as well. For example, I've added tests to see what
happens when GProxyResolver returns both a valid and an invalid URI, but
it's not so interesting here because GSocketClient always uses the valid
result and ignores the error from GProxyAddressEnumerator.

Fixes #2597
2022-06-27 15:10:05 -05:00
Michael Catanzaro
6f83f45db4 gsimpleproxyresolver: ensure default proxy is valid
It should be either a valid URI, or NULL. Passing empty strings or other
invalid URIs is no bueno.
2022-06-27 14:23:51 -05:00
Michael Catanzaro
8a1f087a31 gsimpleproxyresolver: default_proxy should be consistently nullable
Currently it's nullable in g_simple_proxy_resolver_new(), but not in
g_simple_proxy_resolver_set_default_proxy() nor the property. Fix these.
2022-06-27 14:23:51 -05:00
Michael Catanzaro
4667f5980a proxy-test: fix check for simple:// URI scheme
This has no practical impact, since it's only a test, and none of the
test code would have hit this bug, but the GTestProxyResolver's check to
see if the URI scheme is simple:// currently only compares the first
four bytes of the string, so it's actually only checking for the "simp"
and would match anything else after that, e.g. "simpleton://". This is
surely not intended.
2022-06-27 14:23:51 -05:00
Philip Withnall
087272777b tests: Fix incorrect basename comparison in gsubprocess test
This was causing intermittent failures on macOS, depending on whether
the tmpdir ended with a `/` or `/some-dir`. `g_strrstr()` is not the
right function to use to extract a basename from a path, for this
reason.

When it failed, the macOS test was failing with:
```
ok 16 /gsubprocess/env
Bail out! GLib-GIO:ERROR:../gio/tests/gsubprocess.c:1507:test_cwd: assertion failed (basename == tmp_lineend_basename): ("/T\n" == "/\n")
```

The test now passes reliably, which means that it can be removed from
the list of expected failures on macOS.

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

Helps: #1392
2022-06-27 15:02:55 +01:00
Philip Withnall
6d381c9668 Merge branch 'getfsent_lock' into 'main'
Add lock in _g_get_unix_mount_points() around *fsent() functions

See merge request GNOME/glib!1717
2022-06-27 11:20:49 +00:00
Rozhuk Ivan
f43cf34151 [PATCH] Add lock in _g_get_unix_mount_points() around *fsent() functions 2022-06-25 19:22:06 +03:00
Rozhuk Ivan
02d0d6497b [PATCH] _g_get_unix_mount_points(): reduce syscalls inside loop 2022-06-25 19:01:30 +03:00
Philip Withnall
059a5fd4da tests: Skip various default handler tests on macOS
They are not currently supported by `gosxappinfo.m`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:43:18 +01:00
Philip Withnall
dbdc9ca995 gosxappinfo: Correctly return an error from create_from_commandline()
Creating a `GAppInfo` from a commandline isn’t currently supported on
macOS, but the implementation was incorrectly returning `NULL` without
setting the `GError`.

This was being caught by the new tests in `gio/tests/file.c`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:27:45 +01:00
Philip Withnall
a98bd895d5 tests: Fix a path comparison in the file tests
On macOS the comparison was failing as one of the paths had a trailing
slash while the other didn’t.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-24 12:27:45 +01:00
Philip Withnall
191923ce61 Merge branch 'wip/smcv/none-flags' into 'main'
Add a NONE or DEFAULT member to most flags-sets

See merge request GNOME/glib!2576
2022-06-23 16:09:38 +00:00
Philip Withnall
5655af6ada Merge branch 'more-async-gfile' into 'main'
gfile (and GAppInfo): Add some missing async APIs and ensure async calls always use them

See merge request GNOME/glib!2717
2022-06-23 11:49:55 +00:00
Simon McVittie
879b9cd669 gregex: Add G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:39 +01:00
Simon McVittie
0d4e401ede gmarkup: Add G_MARKUP_PARSE_FLAGS_NONE
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:27 +01:00
Simon McVittie
cc528f6c2e giomodule test: Don't pass a magic number to g_test_trap_subprocess()
This worked, but seems like bad style.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:19 +01:00
Simon McVittie
de8672fe0b gtestutils: Add G_TEST_SUBPROCESS_DEFAULT, G_TEST_TRAP_DEFAULT
This makes calls to test subprocesses with default behaviour more
self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:13 +01:00
Simon McVittie
f59e02a143 gioenums: Add G_TLS_CERTIFICATE_FLAGS_NONE
This makes the absence of flags (in other words, a valid certificate)
more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:05 +01:00
Simon McVittie
7045260c22 gsignal: Add G_CONNECT_DEFAULT
This makes calls to g_signal_connect_data() and g_signal_connect_object()
with default flags more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:46:45 +01:00
Marco Trevisan
cb0cc996ee Merge branch 'test-suite-fixes' into 'main'
tests: Various fixes for TAP output of tests

See merge request GNOME/glib!2749
2022-06-22 18:48:59 +00:00
Marco Trevisan (Treviño)
5b04d23fc4 gfile: Make g_query_default_handler_async really Async
Despite the name, the call was still doing blocking operations when
looking for app handlers via GAppInfo. Now it's possible to use fully
async calls.

Together with previous commit, the API is now fully async.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
8a880e1379 GAppInfo: Make g_app_info_launch_default_for_uri_async fully async
Despite the name, we still used blocking calls to get the default app
for URI, now that we have an async implementation of the API to get the
default implementation for URI scheme, we can remove the blocking calls.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
8aee5fc628 GAppInfo: Add async API to get default Application for URI scheme
Make possible to fetch the default application for URI scheme in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
73b29e8f6e gio/tests: Add test case for g_app_info_launch_default_for_uri
We did not check whether this function worked before, so add a simple
test case for it, providing some test functions to make it possible to
reply the same behavior
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
eee15225c7 GDesktopAppInfo: Ignore flushing the session bus when there's not
In some cases (such as in our CI tests) we may not have any dbus session
set after launching, but we always assumed so.

In case we have not a session bus set, we only have to return early.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
6fef60b65c GDesktopAppInfo: Ensure that URI scheme is a valid argument 2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
c87602451c gfile: Use async API to get the default GAppInfo for type
In both callbacks of g_file_query_default_handler_async() we were
actually using I/O blocking APIs making it not fully async.

Now that such API is provided, we can use it.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
44dbd43170 GAppInfo: Add async API to get default Application for content type
Make possible to fetch the Application for default content type in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
abae8c1f05 gio/tests: Add test cases for g_file_query_default_handler[_async]
Simulating having default handlers, however this is tested only in unix
as windows may behave differently, so let's just skip it for now.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
22e951e6ac gfile: Add Async API to create a temporary directory and return as GFile
While it's possible to create a directory synchronously via
g_dir_make_tmp(), there's no such API that performs it asynchronously.

So implement it using GFile, using a thread to perform such task.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
fa24391529 gfile: Add API to create a new temporary file asynchronously
Make possible to create a new gfile with a temporary name in async
way, using the same API of g_file_new_tmp().
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
2a05fd0cb0 gioerror: Rely on GFileError to compute GIOErrorEnum from errno
Avoid re defining cases for GIoErrorEnum when we already handle them
through GFileError, so remove code duplication and just rely on
g_file_error_from_errno() to compute the file error and then use
g_io_error_from_file_error() to get the possible IOError.

In case it's something not handled as GFileError, we can use the same
logic as before.

This is now a safe change to do as we have covered all the supported
cases in tests.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
b64fd312da gerror: Add an utility function to get the GIO Error from GFileError
When GIO functions are using GLib file utils functions we expect to
return a GIO Error, so provide a way to map such error values.
2022-06-22 20:07:25 +02:00
Emmanuele Bassi
55a5a82655 Merge branch 'tls-certificate-refs' into 'main'
gtlscertificate: Hold a ref on the root certificate when building chains

See merge request GNOME/glib!2761
2022-06-21 12:09:22 +00:00
Philip Withnall
75a39114d8 tests: Fix non-TAP output from socket test
This was breaking strict TAP parsers, such as Meson’s.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00