Commit Graph

29187 Commits

Author SHA1 Message Date
Philip Withnall
c406c6de6b Merge branch '3148-stream-test' into 'main'
tests: Use a pipe rather than a socketpair in stream-rw_all test

Closes #3148

See merge request GNOME/glib!3691
2023-11-28 11:43:51 +00:00
Matthias Clasen
f79c53f953 gspawn: Stop spewing debug messages
My GTK testlogs are filled with

GLib-DEBUG: g_unix_open_pipe() called with FD_CLOEXEC; please migrate to using O_CLOEXEC instead

Lets take the hint, and migrate to using O_CLOEXEC.
2023-11-27 21:03:49 -05:00
Artur S0
20400bc503 Update Russian translation 2023-11-27 16:26:55 +00:00
Philip Withnall
cdc37f051c Merge branch 'wip/pwithnall/fix-bsd-string-test' into 'main'
tests: Fix string test failure on BSDs

See merge request GNOME/glib!3731
2023-11-27 16:24:25 +00:00
Philip Withnall
4c86a85eaf Merge branch 'app-command-line-done' into 'main'
gapplicationcommandline: add `.done()` method

Closes #596

See merge request GNOME/glib!3693
2023-11-27 14:15:36 +00:00
Aleksandr Mezin
c03c983d94 gapplicationcommandline: add .done() method
Fixes #596
2023-11-27 14:15:36 +00:00
Philip Withnall
5070f3fe80 Merge branch '3186-gpt-sniff-buffer' into 'main'
glocalfileinfo: Increase size of the content-type sniff buffer to 16KiB

Closes #3186

See merge request GNOME/glib!3730
2023-11-27 14:14:40 +00:00
Philip Withnall
2c4be841d7 tests: Fix string test failure on BSDs
As with `test-printf`, the `vasprintf()` placeholder checks on BSDs
(including macOS) are less strict than on Linux (glibc), so the expected
critical message is not seen.

Change the test to not expect it on BSDs.

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

Helps: #3187
2023-11-27 13:26:51 +00:00
Philip Withnall
01cdce7573 glocalfileinfo: Increase size of the content-type sniff buffer to 16KiB
It was previously 4KiB, but this isn’t enough for sniffing the
content-type of some GPT disk images (they use 4KiB sectors, and the
magic bytes are in the second sector). A buffer of 8KiB would work,
but 16KiB seems harmless and more future proof.

Most of the time, the buffer size should be set by xdgmime anyway, based
on the largest sniff buffer its database needs. Currently (with
shared-mime-info master) that’s 18730 bytes, so even with a 16KiB buffer
we’re going to potentially mis-identify a few file types.

Tested manually by modifying the example GPT image from shared-mime-info
(https://gitlab.freedesktop.org/xdg/shared-mime-info/-/blob/master/tests/mime-detection/disk.gpt)
to remove the magic at offset 0x200 and add it instead at offset 0x1000,
then running:
```
cp shared-mime-info.git/tests/mime-detection/disk.gpt ./disk-without-extension
gio info -a standard::content-type ./disk-without-extension
```

It should print `application/vnd.efi.img` rather than
`application/octet-stream`.

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

Fixes: #3186
2023-11-27 13:22:21 +00:00
Philip Withnall
062f1a888e Merge branch '3187-vasprintf-checks' into 'main'
gprintf: Fix invalid size allocation in `g_vasprintf()`

Closes #3187

See merge request GNOME/glib!3729
2023-11-27 13:09:16 +00:00
Philip Withnall
707ae4bd79 gstring: Add critical warning to g_string_append_vprintf()
It was previously possible for this to silently fail, which isn’t great
for program correctness. Instead, raise a critical warning so the
programmer knows to either validate their Unicode inputs, or fix their
format placeholders.

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

Helps: #3187
2023-11-27 12:20:50 +00:00
Philip Withnall
c56bc6d8d9 gstrfuncs: Add missing annotations to g_strdup_vprintf()
It’s possible for the function to fail for the same reasons
`g_vasprintf()` would fail.

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

Helps: #3187
2023-11-27 12:20:50 +00:00
Philip Withnall
3c6052f318 gprintf: Fix invalid size allocation in g_vasprintf()
As per the previous commit, it’s possible for
`g_printf_string_upper_bound()` to return an error. We need to catch and
handle that error in `g_vasprintf()` to avoid it trying to write to a
`NULL` string allocation and crashing.

So, call `g_vsnprintf()` directly instead of calling
`g_printf_string_upper_bound()`, so that the error case can be handled.

There was already a test for some of this behaviour
(`test_vasprintf_invalid_format_placeholder()`). Because it tested an
invalid format string, the `_g_vsprintf()` call bailed out before
checking whether the buffer it had been passed was `NULL`. The new test
has a valid format string, but an invalid arg.

When running the tests locally, I have disabled the `USE_SYSTEM_PRINTF`
and `HAVE_VASPRINTF` code paths in `g_vasprintf()`.

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

Fixes: #3187
2023-11-27 12:20:12 +00:00
Philip Withnall
e2cd0962c2 gmessages: Document error case for g_printf_string_upper_bound()
Spotted in https://gitlab.gnome.org/GNOME/glib/-/issues/3187.

In an ideal world, this API would have been designed with an error
return path to begin with — perhaps by returning a `GError` or a
`gssize`. We can’t change the API now, though, which leads to this
slightly awkward “0 indicates an error or success” pattern.

I think that’s justified in this case because:
 - This API does not see much use.
 - Format strings tend to be literals, and almost always are
   non-zero-length, so it tends to be statically possible to determine
   that the function won’t return zero on success.
 - If callers do need to differentiate the two zero return value cases,
   they can just call `g_vsnprintf()` directly instead.

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

Helps: #3187
2023-11-27 12:20:06 +00:00
Philip Withnall
40081f9b62 Merge branch 'collate-crash' into 'main'
collate: Don't segfault on bad input

Closes #3185

See merge request GNOME/glib!3725
2023-11-26 22:41:26 +00:00
Matthias Clasen
81ec27c33b collate: Don't segfault on bad input 2023-11-26 22:41:26 +00:00
Philip Withnall
e67a36c479 Merge branch 'wip/pwithnall/fix-ftruncate64' into 'main'
tests: Fix fileutils build on FreeBSD and macOS

See merge request GNOME/glib!3726
2023-11-26 22:23:36 +00:00
Philip Withnall
a8df4183e4 tests: Fix fileutils build on FreeBSD and macOS
The test needs to call `ftruncate64()` (not `ftruncate()`) to guarantee
it’s using the 64-bit version on Linux, but this doesn’t exist on other
platforms.

Test to see if it exists and, if not, skip the test.

Fixes commit cf5e371c67, and fixes CI
failures like https://gitlab.gnome.org/GNOME/glib/-/pipelines/602930.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-26 22:10:22 +00:00
Philip Withnall
50d432c77b gwin32: Un-hide symbols when building GIR
The win32-specific APIs in GLib are only defined when building for
Windows. Unfortunately, this means they can not show up in `GLib-2.0.gir`
if it’s build on Linux (which is what mostly happens).

Consequently, that means they’re not present in the API documentation,
which is a bit of a problem.

Make the symbols in the header available on other platforms
(particularly Linux) if building with `g-ir-scanner` (but not
otherwise). This means the win32 symbols show up in `GLib-2.0.gir` and
hence in the documentation.

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

Helps: #3037
2023-11-23 16:18:47 +00:00
Philip Withnall
9c9552309a Merge branch 'large-file-issue3' into 'main'
gfileutils: Fix g_file_get_contents() silent under-read of large files when off_t is wider than size_t

See merge request GNOME/glib!3713
2023-11-23 12:41:42 +00:00
Joseph Nuzman
cf5e371c67 gfileutils: Fix g_file_get_contents() silent under-read of large files
On certain platforms where file size (off_t) can be truncated when assigning to
gsize, get_contents_regfile() may use the truncated size as the size to read. Add
an explicit check to raise an error in such cases.

G_FILE_ERROR_FAILED will be raised in this case, aligning with behavior for other
cases.

This generally affects 32-bit non-Win32 platforms.
2023-11-23 12:41:41 +00:00
Philip Withnall
aec0f4d938 gstrvbuilder: Add a boxed type so it can be introspected properly
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-23 12:36:11 +00:00
Philip Withnall
40e6a09d37 gstdio: Ignore POSIX stdio wrappers under g-ir-scanner
Just as they were ignored under gtk-doc, ignore them when scanning the
sources using `g-ir-scanner`, and make it look at the full function
declarations instead.

This fixes inclusion of functions like `g_creat()` in the documentation.

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

Helps: #3037
2023-11-23 12:34:39 +00:00
Philip Withnall
3c42b9c3ee gdir: Add refcounting support and a boxed type
This allows the methods for `GDir` to be introspected. While we don’t
expect languages which use the introspection bindings to use `GDir`,
full introspection support is necessary for the `GDir` documentation to
be correctly built with gi-docgen.

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

Helps: #3037
2023-11-23 12:34:39 +00:00
Philip Withnall
f0032094d2 tests: Fix use of TMPDIR in utils test
All GLib tests normally respect `TMPDIR` for writing their temporary
files to. The utils test, however, contained a hack which overwrote
`TMPDIR` so that it could test the behaviour of `g_get_tmp_dir()` for
regressions.

Unfortunately, that hack affected the whole `utils` test suite, not just
the one regression test.

Use the new `g_test_trap_subprocess_with_envp()` API to allow the
regression test to be run as a subprocess with its environment modified,
which allows us to remove the hack affecting the rest of the test suite.

Spotted in
https://gitlab.gnome.org/GNOME/glib/-/issues/3179#note_1925161.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-23 12:18:21 +00:00
Philip Withnall
6a6b36bbc7 gtestutils: Add g_test_trap_subprocess_with_envp() for testing envs
This is a variant of `g_test_trap_subprocess()` which allows the
environment for the child process to be specified. This is quite useful
when you want to test code which reads environment variables, as it’s
not safe to set those after the start of `main()`.

This will be useful within and outwith GLib for testing such code.

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

Helps: #1618
2023-11-23 12:18:21 +00:00
Philip Withnall
c7a02280f5 Merge branch 'introduce-g_log_set_debug_domains' into 'main'
gmessages: introduce g_log_set_debug_domains()

See merge request GNOME/glib!3710
2023-11-22 10:45:01 +00:00
Philip Withnall
29200648da Merge branch 'circular-mime-inheritance' into 'main'
xdgmime: Handle buggy type definitions with circular inheritance

See merge request GNOME/glib!3714
2023-11-22 10:35:34 +00:00
Philip Withnall
0c4aff4cee Merge branch 'musl-reference-disable-test' into 'main'
tests: provide reason for disabling convert test under musl

See merge request GNOME/glib!3717
2023-11-22 10:24:39 +00:00
Pablo Correa Gómez
0cae984b2d
tests: provide reason for disabling convert test under musl 2023-11-22 00:24:45 +01:00
Alexander Slobodeniuk
e862f34dd8 gmessages: introduce g_log_writer_default_set_debug_domains()
The problem is that resetting the environment of a
proccess is not safe, this is mentioned in the man
pages of the setenv, and also by the concept:
when we get a constant string returned by the getenv,
we need to be guaranteed that this string will exist
during all that time we are using it. While setting
the same env var to another value destroys this string
inside of libc.

Now looking at the should_drop_message(), we can see
that it just gets the environment on every call. Getting
the environment is safe, but however there's no safe way
to switch the logging domains selection: setenv can't be
used because of the reasons listed above.

That is why g_log_writer_default_set_debug_domains() is
needed: it's just a safe replacement for the setenv in this case.

Now should_drop_message() still reads the environment, but
does so only on the first call, after that the domains are
stored internally, and can only be changed by
g_log_writer_default_set_debug_domains().

This also means that now resetting G_MESSAGES_DEBUG env
var in runtime has no effect. But in any case this is not
what the user should do, because resetting the environment
in runtime is not correct.
2023-11-21 20:49:37 +01:00
Alex Henrie
77902e1b1c xdgmime: Add continue statements after goto labels in_xdg_mime_(cache_)mime_type_subclass
To fix the Android build.
2023-11-21 11:14:58 -07:00
Philip Withnall
8f37874f90 Merge branch 'cmph-test-asserts' into 'main'
tests: Improve build of cmph tests in girepository

See merge request GNOME/glib!3716
2023-11-21 16:49:33 +00:00
Philip Withnall
059618956b Merge branch 'muslc-ci' into 'main'
add muslc ci

See merge request GNOME/glib!3524
2023-11-21 14:55:29 +00:00
Philip Withnall
2a7ff62417 tests: Improve build of cmph tests in girepository
They were still failing with `-Dglib_assert=false` because
`G_DISABLE_ASSERT` wasn’t being explicitly un-defined for the test.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/3309889

Also while we’re there, take the opportunity to correctly set the test
suite, protocol and environment.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-21 14:21:07 +00:00
Philip Withnall
ee94074463 Merge branch 'wip/smcv/goption-unknown' into 'main'
goption: Fix a typo

See merge request GNOME/glib!3715
2023-11-21 13:37:48 +00:00
Philip Withnall
f2d7e6af22 Merge branch 'migrate-to-gi-docgen11' into 'main'
Switch to using gi-docgen for docs (batch 11)

See merge request GNOME/glib!3712
2023-11-21 12:56:04 +00:00
Simon McVittie
c4a6ff6821 goption: Fix a typo
We presumably want the fallback string used when we cannot determine
the program name to contain balanced angle brackets, as it did before
commit 7098250e.

Fixes: 7098250e "gutils: avoid race setting prgname from g_option_context_parse()/g_application_run()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-21 12:55:55 +00:00
Philip Withnall
69b83a830c Merge branch 'hmac-introspection' into 'main'
ghmac: Add a boxed type for GHmac and fix introspection build accordingly

See merge request GNOME/glib!3711
2023-11-21 12:55:30 +00:00
Philip Withnall
74d786e8bf Merge branch 'fix_3303' into 'main'
mkenums: Allow , in a character literal

Closes #3103

See merge request GNOME/glib!3676
2023-11-21 11:54:43 +00:00
Lukáš Tyrychtr
a473d5aea0 mkenums: Allow , in a character literal
This required adding a higher precedence character literal choice.

Fixes #3103
2023-11-21 11:54:42 +00:00
Alex Henrie
d9c50cac5d xdgmime: Handle buggy type definitions with circular inheritance
This fixes a stack overflow reported by a user who had both the
definition of text/javascript from shared-mime-info 2.3 and the
definition of text/javascript from shared-mime-info 2.4 installed at the
same time. In 2.3, text/javascript is a subtype of
application/ecmascript, but in 2.4 application/ecmascript is a subtype
of text/javascript. Having both at the same time resulted in circular
inheritance.

The new logic keeps a list of all parents that have already been
checked, which is more comprehensive than the old workaround that was
implemented in commit 38869ece2 ("xdgmime: Prevent infinite loops from
badly-formed MIME registrations").

https://bugs.archlinux.org/task/80279
2023-11-20 09:46:51 -07:00
Philip Withnall
6d2f63ecf1 giotypes: Drop redundant duplicate documentation blocks
This fixes a load of warnings about ‘multiple comment blocks documenting
<something> identifier’.

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

Helps: #3037
2023-11-15 12:37:12 +00:00
Philip Withnall
6e4d50fa5c docs: Move the gunixmounts SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-15 11:48:23 +00:00
Philip Withnall
9c414d437e docs: Move the gpollableutils SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-15 11:48:23 +00:00
Philip Withnall
708de2fc12 docs: Move the gnetworking SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-15 11:48:23 +00:00
Philip Withnall
de8e39b344 docs: Move the gmenumodel SECTION
Move it to a separate page, since it doesn’t quite make sense to
incorporate into the `GDBusConnection` docs.

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

Helps: #3037
2023-11-15 11:48:23 +00:00
Philip Withnall
ef049cbaca docs: Move the GIOScheduler SECTION
Move it to a separate page, as there isn’t a `GIOScheduler` struct.
Ensure that all its functions/methods/types are correctly marked as
deprecated. Fix a few broken links about I/O priority which pointed to
it.

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

Helps: #3037
2023-11-15 11:48:23 +00:00
Philip Withnall
4ef365e5d0 ghmac: Add a boxed type so it can be introspected properly
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-15 11:09:39 +00:00
Philip Withnall
e594321ca4 docs: Move the GIOChannel SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-15 11:09:39 +00:00