Commit Graph

9191 Commits

Author SHA1 Message Date
Xavier Claessens
a4edf1e3ae GDateTime: Add usec precision API for unix time 2023-12-20 07:48:10 -05:00
Philip Withnall
4608b87469 Merge branch 'wryun-gregex-handle-multiple-failed-optimise-matches-with-fallback' into 'main'
gregex: clean up usage of _GRegex.jit_status

Closes #2824

See merge request GNOME/glib!3750
2023-12-18 11:23:56 +00:00
James Haggerty
71ea08d5fa gregex: clean up usage of _GRegex.jit_status 2023-12-18 11:23:56 +00:00
Philip Withnall
00b75eb95c gerror: Fix an old allow-none annotation
It’s now best described as both nullable and optional.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-12-14 01:26:42 +00:00
Pablo Correa Gómez
2b4e667209
glit: tests: enable regex test under musl
This was an alpine packaging problem, that is no fixed in the new
release

Fixes #3159
2023-12-08 17:28:10 +01:00
António Fernandes
c9cd385b17 hash: Explicitly annotate key in iter_next as nullable
There is no reason for key and value to have different annotations.
Both may return NULL as a valid value.

gpointer typed parameters are nullable by convention, so there is
no change here. The (nullable) annotation is just for humans really.
2023-12-04 09:53:35 +00:00
Philip Withnall
58208c4ace gvarianttype: Add a missing argument name
To make it match its definition and documentation comment. This fixes a
g-ir-scanner warning.

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

Helps: #3037
2023-11-29 12:03:34 +00:00
Philip Withnall
81d96f5898 gmarkup: Add a missing (element-type) annotation
Fixes a g-ir-scanner warning.

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

Helps: #3037
2023-11-29 12:03:15 +00:00
Philip Withnall
02725b9bbd ghashtable: Add various missing (transfer) annotations
Fixes some g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 12:02:49 +00:00
Philip Withnall
c7dfd218ea gerror: Add missing (scope forever) annotations
Extended error domains can never be unregistered, so these closures
have to be around forever.

Fixes some g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 12:02:04 +00:00
Philip Withnall
c1547f62bc gbytearray: Add missing (transfer) annotations
`GByteArray` is a bit odd in that it allows call-chaining. All the
instances of that were missing a `(transfer none)` annotation though.

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

Helps: #3037
2023-11-29 12:01:12 +00:00
Philip Withnall
8f08c1a038 gthread: Make some argument names match up
This fixes a warning from g-ir-scanner as the declaration and
documentation comment didn’t match.

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

Helps: #3037
2023-11-29 12:00:35 +00:00
Philip Withnall
f14cd8de14 gcompletion: Make argument names match up
This fixes some warnings from g-ir-scanner.

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

Helps: #3037
2023-11-29 12:00:14 +00:00
Philip Withnall
d07c59ed4e glib: Add (scope call) to a load of sort/equal callbacks
This fixes a load of g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 11:59:47 +00:00
Philip Withnall
8ee00cbad8 gdatetime: Disable ERA support on platforms which don’t support this
So far, that’s BSD: it supports `nl_langinfo()`, but not `ERA`.

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

Helps: #3119
2023-11-28 23:56:22 +00:00
Philip Withnall
9eda0b2fcd gdatetime: Fix typo in comment
This was pointed out in the review for !3696 but owing to a mistake by
me, the fix was not included in the version of the MR which was merged.

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

Helps: #3119
2023-11-28 23:14:40 +00:00
Philip Withnall
c8e3302007 gdatetime: Fix copyright/author information on recent GDateTime changes
I wrote the changes before clarifying the copyright status of my
contract with the GNOME Foundation, and forgot to update them.

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

Helps: #3119
2023-11-28 23:13:27 +00:00
Philip Withnall
517a3ac861 tests: Set locale to C.UTF-8 in datetime tests
It was previously set (by default) to `C`, so this commit doesn’t change
the locale behaviour of the tests, but does ensure that messages printed
by the tests are correctly formatted in UTF-8 rather than transliterated
to ASCII.

That makes interpreting test output easier.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
09fe2aa78d gdatetime: Fix a minor leak on changing locale
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
454064f82d gdate: Fix some typos in a documentation comment
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
df4aea7620 gdatetime: Add support for %E modifier to g_date_time_format()
The `%E` modifier causes dates to be formatted using an alternative era
representation for years. This doesn’t do anything for most dates, but
in locales such as Thai and Japanese it causes years to be printed using
era names.

In Thai, this means the Thai solar calendar
(https://en.wikipedia.org/wiki/Thai_solar_calendar). In Japanese, this
means Japanese era names
(https://en.wikipedia.org/wiki/Japanese_era_name).

The `%E` modifier syntax follows what’s supported in glibc — see
nl_langinfo(3).

Supporting this is quite involved, as it means loading the `ERA`
description from libc and parsing it.

Unit tests are included.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Fixes: #3119
2023-11-28 19:32:02 +00:00
Philip Withnall
2c4a0c83e1 docs: Drop the regex-syntax page
Point people to the official PCRE documentation instead, which is going
to be more up to date. This saves us periodically having to copy in and
reformat the PCRE documentation.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
6a22d58f6b docs: Move the types SECTION
Move it to a mega separate file.

This has been a journey.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
33c10e8711 docs: Move the windows SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
3532e3ca1c docs: Move the warnings SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
877b0affb6 docs: Move the numerical SECTION
Move it to a separate Markdown file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
3957b47e59 docs: Move the checkedmath SECTION
Move it to a separate Markdown file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
b93e35dc17 docs: Move the datalist and dataset SECTIONs
Move them to a separate page as they don’t really have a ‘class’ struct
each to hang docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
790131687c docs: Move the unix SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
244721baf9 docs: Move the misc_utils SECTION
Move it to a separate page, with a massive great list of all the misc
utils. Not a great documentation page, but equivalent to what we had
before, and it can be improved in future.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
74de872bb9 docs: Move the spawn SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
6dca578f9d docs: Move the memory SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
cbbd06fee7 docs: Drop the SECTION for tracing
All this API is internal to GLib, so the section was never actually
exposed in the public API documentation. Keep the documentation, just
don’t tag it as a SECTION.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
25a4205d9d docs: Move the ghostutils SECTION
Sadly, this is about hostnames rather than ghosts. 😞

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
425731f766 docs: Move the string_utils SECTION
Move it to a mega separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
cf52727f03 docs: Move the shell SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
214853d6df docs: Move the GVariant SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
229b76a388 docs: Move the version SECTION
Move it to a separate documentation file, since most of what’s covered
isn’t introspectable.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
194db3f096 docs: Move the GVariantType SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
359c1034e0 docs: Move the GUuid SECTION
Move it to a separate page as there’s no public struct to hang the
docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
be783fdc2a docs: Move the GUri SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
43588fcdd9 docs: Move the grand SECTION
Move it to a separate page so the difference between `g_rand_*()` and
`g_random_*()` can be explained.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
8179688c07 docs: Move the GTrashStack SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
1625c24d58 docs: Drop the hooks SECTION
It was one paragraph which mentioned `GHookList` and `GHook`, both of
which have their own adequate documentation sections.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
158ec5be34 docs: Move the gfileutils SECTION
Move it to a separate page so more detail can be provided about all the
groups of API.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
c850d25d67 docs: Move the gatomic SECTION
Move it to a standalone page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
ac91b8f4a2 docs: Move the base64 SECTION
Move it to a separate file as there is no struct to hang the docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
552f62a059 docs: Move the threads-deprecated SECTION
Move it to a separate page so an overview of the deprecated threading
API can be given.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
f8122da6c9 Merge branch 'migrate-to-gi-docgen13' into 'main'
gwin32: Un-hide symbols when building GIR

See merge request GNOME/glib!3723
2023-11-28 13:49:42 +00:00
Philip Withnall
8f6f382940 Merge branch 'test-trap-subprocess-envp' into 'main'
gtestutils: Add g_test_trap_subprocess_with_envp() for testing envs

See merge request GNOME/glib!3721
2023-11-28 11:49:11 +00:00
Philip Withnall
e4fe837bae Merge branch 'migrate-to-gi-docgen12' into 'main'
gdir, gstrvbuilder: Add refcounting support and a boxed type

See merge request GNOME/glib!3722
2023-11-28 11:47:11 +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
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
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
Matthias Clasen
81ec27c33b collate: Don't segfault on bad input 2023-11-26 22:41:26 +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
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
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
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
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
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
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
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
Philip Withnall
7d5b6e1a85 docs: Move the GHmac 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
Philip Withnall
09b728b2da Merge branch 'migrate-to-gi-docgen10' into 'main'
Switch to using gi-docgen for docs (batch 10)

See merge request GNOME/glib!3709
2023-11-14 15:46:30 +00:00
Philip Withnall
924e164a73 docs: Move the GRelation SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
3981c1c704 docs: Move the GCompletion SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
a11d3604c2 docs: Move the GCache SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
1a979ab494 gutils: Fix an unlikely minor leak in g_build_user_data_dir()
A leak can happen if the `data_dir` is the empty string.

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

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-14 11:00:21 +00:00
Pablo Correa Gómez
8901ffeffe
ci: add muslc CI 2023-11-12 15:39:14 +01:00
Thomas Haller
7098250e7a gutils: avoid race setting prgname from g_option_context_parse()/g_application_run()
g_option_context_parse()/g_application_run()/g_test_init() for
convenience also call g_set_prgname(), when the prgname is unset at this
point. This was racy.

Fix the race by using an atomic compare-and-exchange and only reset the
value, if it is unset still.
2023-11-08 16:36:14 +01:00
Thomas Haller
54e0b2d75b gutils: use atomic pointers for g_application_name
The mutex is not necessary to guard a single pointer.
2023-11-08 16:36:14 +01:00
Thomas Haller
0d61895ef1 gutils: assert against calling g_set_application_name()
g_set_application_name() guards against being reset, but it doesn't
remember whether it was set, it only checks whether g_application_name
was set to non-NULL. When allowing g_set_application_name(NULL) that leads
to odd behaviors, like:

    g_set_application_name(NULL);
    g_set_application_name("foo");

would not warn.

Disallow that and assert against a NULL application_name.

Note that application_name argument is also not marked as "(nullable)".
2023-11-08 16:36:14 +01:00
Thomas Haller
167deee94d gutils: use atomic pointers for g_prgname
The mutex is not necessary to guard a single pointer.
2023-11-08 16:36:14 +01:00
Philip Withnall
e87f8e9c5a Merge branch '3158-info-critical' into 'main'
gio-tool-info: Fix critical warning when --attributes are specified and add basic unit tests

Closes #3158

See merge request GNOME/glib!3684
2023-11-07 14:37:11 +00:00
Philip Withnall
077104e63b tests: Run processes under test with G_DEBUG=fatal-warnings
Modify all the similar Python test wrappers to set
`G_DEBUG=fatal-warnings` in the environment of the program being tested,
so we can catch unexpected warnings/criticals.

Adding this because I noticed it was missing, not because I noticed a
warning/critical was being ignored.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-07 13:51:56 +00:00
Philip Withnall
c17090275c Merge branch 'th/main-sources-dict-as-set' into 'main'
gmain: optimize "context->sources" hash table to use as set

See merge request GNOME/glib!3664
2023-11-06 15:05:43 +00:00
Philip Withnall
a766945766 Merge branch 'main' into 'main'
fix: about libproc.h and PROC_PIDLISTFD_SIZE

See merge request GNOME/glib!3687
2023-11-06 14:46:52 +00:00
CaiJingLong
7b80f73d29 fix: about libproc.h and PROC_PIDLISTFD_SIZE 2023-11-06 14:46:52 +00:00
Philip Withnall
113063e413 Merge branch 'socket-ready-fixes' into 'main'
Socket & readiness fixes

See merge request GNOME/glib!3668
2023-11-06 14:35:23 +00:00
Sergey Bugaev
a3d02ad565 gmain: Correct g_source_get_ready_time () doc
Mention that ready time being equal to the current time means the source
will fire immediately.

Related to https://gitlab.gnome.org/GNOME/glib/-/issues/3148

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-11-06 15:14:07 +03:00
Thomas Haller
b067c43b00 gmain: optimize "context->sources" hash table to use as set
Instead of tracking a "(guint,GSource*)" tuple in the "context->sources"
dictionary, only track pointers to the "source_id".

With this we use the GHashTable as Set (g_hash_table_add()), which is
optimized and avoids storing a separate value array.

It's simple enough to do, because there are literally 5 references to
"context->sources". It's easy to review those usages and reason that the
handling is correct.

While at it, in g_main_context_find_source_by_id() move the check for
SOURCE_DESTROYED() inside the lock. It's not obvious that doing this
without a lock was correct in every case. But doing the check with
a lock should be fast enough to not worry about whether it's absolutely
necessary.
2023-11-06 08:48:12 +01:00
Thomas Haller
501bdb51e4 glib: add internal G_CONTAINER_OF() macro
"container_of()" is a popular macro that works together with
G_STRUCT_OFFSET()/offsetof().

For internal use only.
2023-11-06 08:48:12 +01:00
Thomas Haller
3c09257ea1 glib: add internal g_uint_hash()/g_uint_equal()
We have g_int_hash()/g_int_equal(), which in practice might also work
with with pointers to unsigned integers. However, according to strict
interpretation of C, I think it is not valid to conflate the two.

Even if it were valid in all cases that we want to support, we should
still have separate g_uint_{hash,equal} functions (e.g. by just #define
them to their underlying g_int_{hash,equal} implementations).

Add instead internal hash/equal functions for guint.
2023-11-06 08:48:12 +01:00
Philip Withnall
32e8a73efb tests: Refactor thread-pool-slow to separate test functions
Previously thread-pool-slow ran a single test which encoded a state
machine and polling timer to run 8 different sub-tests and check for
their exit conditions.

This was a bit ugly, and since the timer ran at 1s granularity, several
of the tests completed quite fast and then hang around for most of 1s
before finishing and moving to the next test.

Split the test functions up into separate GTest tests, and split the
state machine up between the test functions. All of the `GMainLoop`
handling is actually only needed for the `test_threadpool_idle_time()`
test.

This reduces the overall test runtime from 36s to 19s on my machine,
with 17s of that being spent in `test_threadpool_idle_time()`.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #2810
2023-11-03 12:10:49 +00:00
Philip Withnall
1195a7a638 tests: Move some global variables into local scope in thread-pool-slow
This makes things a bit more maintainable, as there’s less global state
to worry about.

It introduces no functional changes.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-03 11:40:44 +00:00
Philip Withnall
f0dbf6fe7c tests: Remove dead code from thread-pool-slow
This variable was never modified.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-03 11:38:41 +00:00
Philip Withnall
0b45f6208b tests: Fix a race in thread-pool-slow
The race was already acknowledged in the code (via `last_failed`): the
thread pool starts dequeuing jobs as soon as it’s created, so it’s
dequeuing the sorted thread IDs while they’re still being enqueued and
sorted. This can lead to them being dequeued out of the expected order
if new thread IDs are enqueued out of order, which is possible because
they’re randomly generated.

The test tried to handle this by allowing one out-of-order dequeue, but
it looks like the race can race hard enough that multiple out-of-order
dequeues are possible.

Fix that by only starting to dequeue the jobs from the thread pool once
they’ve all been enqueued and put in a total order.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Fixes: #2810
2023-11-03 11:14:51 +00:00
Philip Withnall
0fe15f9b9b docs: Move the GChecksum SECTION
Move it to the struct docs.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3037
2023-11-02 16:30:23 +00:00
Alexander Slobodeniuk
ae8018d360 gmessages: fix dropping irrelevant log domains
If the string of one log domain is contained in
another, it was printing both.

For example, if G_MESSAGES_DEBUG is "Gtkspecial",
it would also keep the logs of the "Gtk" domain
2023-11-01 22:24:45 +00:00
Philip Withnall
3b4846611d glib: Disable dynamic asan loading on macOS
The weak symbol resolution doesn’t seem to work (see
https://gitlab.gnome.org/GNOME/glib/-/jobs/3265405):
```
Undefined symbols for architecture x86_64:
  "___lsan_enable", referenced from:
      _g_leak_sanitizer_is_supported in gutils.c.o
  "___lsan_ignore_object", referenced from:
      _g_ignore_leak in gquark.c.o
      _g_ignore_leak in gthreadpool.c.o
      _g_ignore_leak in gutils.c.o
      _g_leak_sanitizer_is_supported in gutils.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

See !3672

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-01 14:34:37 +00:00
Seppi Wilhelmi
fc3d3a5499 Make GQuark register intentional leaks 2023-10-31 16:53:40 +01:00
Marco Trevisan (Treviño)
fb58d55187 glib-private: Check for LSAN support at runtime when controlling it
GLib ignores various leaks that we don't consider as such (like the
default gio modules) via the LSAN public interface, however those cases
are always ignored when using a non-ASAN compiled glib is used by an
ASAN-compiled binary.

This makes all the GLib-related programs to fail because of false
positive leaks.

To avoid this, use the gcc extension for weak linking so that we can
control ASAN and LSAN only if the symbols they provide are actually
available at runtime.
2023-10-27 18:31:53 +02:00
Marco Trevisan (Treviño)
d354b2f55e gmacros: Add fallback definition for weak attribute 2023-10-27 17:19:08 +02:00
Michael Catanzaro
eadbdb439e Merge branch 'meson-version-bump' into 'main'
build: Bump Meson dependency to 1.2.0

See merge request GNOME/glib!3666
2023-10-25 13:23:53 +00:00
Alex Richardson
d0e03f0930 GType: introduce GTYPE_TO_POINTER/GPOINTER_TO_TYPE
On CHERI-enabled systems we use uintptr_t as the underlying storage for
GType and therefore casting to gsize strips the upper bits from a pointer.
Fix this by casting via uintptr_t instead and introduce a new set of
macros to convert between GType and pointers.
2023-10-25 12:01:02 +01:00
Philip Withnall
7fd9045065 build: Drop pkgconfig.generate variables for builtin directories
Meson has added these automatically since 0.62. This fixes a Meson
warning.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-10-25 11:21:24 +01:00
Philip Withnall
70c66766f7 Merge branch 'atomic-uintptr' into 'main'
gatomic: Use g(u)intptr where appropriate

See merge request GNOME/glib!3143
2023-10-24 10:49:30 +00:00
Emmanuele Bassi
fe32c3f5c5 Generate introspection data
Currently, the introspection data for GLib and its sub-libraries is
generated by gobject-introspection, to avoid the cyclic dependency
between the two projects.

Since gobject-introspection is generally available on installed systems,
we can check for its presence, and generate the introspection data
directly from GLib.

This does introduce a cyclic dependency, which is why it's possible to
build GLib without introspection, then build gobject-introspection, and
finally rebuild GLib.

By having introspection data available during the GLib build, we can do
things like generating documentation; validating newly added API; and
close the loop between adding new API and it becoming available to non-C
consumers of the C ABI (i.e. language bindings).
2023-10-23 11:26:53 +01:00
Emmanuele Bassi
5e7c512609 docs: Fix various invalid links 2023-10-23 10:25:31 +01:00
Emmanuele Bassi
c86f469c1e Ignore autocleanups when generating introspection data 2023-10-23 10:25:30 +01:00
Emmanuele Bassi
c5eb130175 Fix broken annotation in GIOChannel
Missing separator between annotation and description.
2023-10-23 10:25:30 +01:00
Michael Catanzaro
ceca2dc5bc Merge branch '3144-file-set-contents-truncation' into 'main'
gfileutils: Add a missing ftruncate() call when writing files

Closes #3144

See merge request GNOME/glib!3650
2023-10-22 22:41:56 +00:00
Michael Catanzaro
7a9f8eec35 Merge branch 'alt-digits-locale-change' into 'main'
gdatetime: Fix incorrect alt-digits being used after changing locale

See merge request GNOME/glib!3655
2023-10-22 22:32:34 +00:00
Philip Withnall
afd8dde13f gdatetime: Fix incorrect alt-digits being used after changing locale
The alt-digits are loaded from `nl_langinfo()` in a `GOnce` section,
which means `nl_langinfo()` is not re-queried after the process changes
locale (if that happens).

So, change the `GOnce` to a mutex and store the locale of the alt-digits
alongside them. This will introduce contention when calling
`format_number()` is called, but how often are multiple threads trying
to format dates at the same time?

If this does get highlighted as a performance problem, the other
approach I considered was a `GPrivate` struct containing all the
locale-specific cached data. That comes at the cost of using a
`GPrivate` slot (although that’s only particularly expensive on Windows,
and the locale code is quite different for Windows, so perhaps that
could be avoided entirely). It does mean that all locale printing could
be lock-free and still safely update cached data on a locale change.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-22 22:10:07 +01:00
Philip Withnall
3f705ffa12 gfileutils: Add a missing ftruncate() call when writing files
When calling `g_file_set_contents_full()` without
`G_FILE_SET_CONTENTS_CONSISTENT`, the file is written by opening it,
`write()`ing to it, then closing it.

This is fine as long as the file is not longer than the new content you
want to set its contents to. If it is, the last bit of the old content
remains, because `g_file_set_contents_full()` was missing an
`ftruncate()` call.

Fix that, and change the tests to catch truncation failures in future.

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

Fixes: #3144
2023-10-22 21:37:28 +01:00
Marco Trevisan
ca57acd71b Merge branch '3112-unicode-15.1' into 'main'
gunicode: Update to Unicode 15.1.0

Closes #3112

See merge request GNOME/glib!3651
2023-10-19 17:02:37 +00:00
Philip Withnall
b1ae8fb85f gdatetime: Fix minor leaks from strup/strdown calls
These were accidentally introduced in commit 0b114b2687.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-18 15:54:33 +01:00
Philip Withnall
17145fab35 gunicode: Update to Unicode 15.1.0
All changes mechanically generated with:
```
./tools/update-unicode-data.sh ~/Downloads/UCD 15.1.0
```

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

Fixes: #3112
2023-10-17 22:59:27 +01:00
Philip Withnall
80aea8e0a6 gen-unicode-tables: Fix indentation at the start of the first row
It was annoying Marco.

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

Helps: #3112
2023-10-17 22:59:27 +01:00
Philip Withnall
cc350774bf gen-unicode-tables: Strip whitespace off parsed fields
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-17 22:45:55 +01:00
Philip Withnall
9770d7ba31 gunicode: Fix a minor typo in a documentation comment
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-17 22:45:55 +01:00
Philip Withnall
444a313b1f gunicode: Add new line-break types from Unicode 15.1.0
See https://unicode.org/reports/tr14/

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

Helps: #3112
2023-10-17 22:45:55 +01:00
Philip Withnall
fa165204ae Merge branch 'fix-warnings-clang-windows' into 'main'
Fix warnings with Clang on Windows and enable --Werror in CI

See merge request GNOME/glib!3635
2023-10-16 21:29:09 +00:00
Luca Bacci
4aa051cafb valgrind.h: Fix macro definition for Windows x64
The Windows x64 ABI follows the LLP64 model, so unsigned long int is 32 bits

Fixes the following warnings when compiling for Windows x64:

  ../glib/gobject/gatomicarray.c:85:3: warning: cast to smaller integer type 'unsigned long' from 'gpointer' (aka 'void *') [-Wvoid-pointer-to-int-cast]
    VALGRIND_MALLOCLIKE_BLOCK (mem, real_size - sizeof (GAtomicArrayMetadata),
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:6479:5: note: expanded from macro 'VALGRIND_MALLOCLIKE_BLOCK'
      VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK,       \
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:203:15: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUEST_STMT'
    do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                        \
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:417:20: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUEST_EXPR'
      _zzq_args[1] = (unsigned long int)(_zzq_arg1);                \
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

See https://bugs.kde.org/show_bug.cgi?id=427146
2023-10-16 15:02:03 +02:00
Philip Withnall
481839c190 Merge branch 'win32-unicode-api' into 'main'
Windows: Compile with the UNICODE / _UNICODE macros

See merge request GNOME/glib!3623
2023-10-16 08:58:41 +00:00
Philip Withnall
b8e805b8c6 Merge branch 'update-bit-symbol' into 'main'
gutils: Use international symbol for bits

See merge request GNOME/glib!3552
2023-10-16 08:25:03 +00:00
getsnoopy
5422d2fdb8 gutils: Use international symbol for bits 2023-10-16 08:25:03 +00:00
Guido Günther
bc4ba05d34 gstrvbuilder: Add g_strv_builder_take
g_strv_builder_take() allows to transfer ownership of the passed in
string.

This can be useful to avoid additional allocations when using functions
that transfer ownership to the caller like g_strdup_printf().

The testcase uses g_strv_builder_take and g_strv_builder_add to demo
that calls can be mixed.
2023-10-15 15:45:58 +02:00
Luca Bacci
dfeb671c36 tests/win32: Initialize DWORD with the right constant
We were initializing a DWORD (unsigned 32 bit) with a constant
of bigger rank (G_MAXSIZE) on 64 bit systems.

Fixes the following warnings on CLang when compiling for x64:

  ../glib/glib/tests/win32.c:47:14: warning: implicit conversion from 'unsigned long long' to 'DWORD' (aka 'unsigned long') changes value from 18446744073709551615 to 4294967295 [-Wconstant-conversion]
    DWORD bp = G_MAXSIZE;
          ~~   ^~~~~~~~~
  glib/glibconfig.h:88:19: note: expanded from macro 'G_MAXSIZE'
  #define G_MAXSIZE       G_MAXUINT64
                          ^~~~~~~~~~~
  ../glib/glib/gtypes.h:107:21: note: expanded from macro 'G_MAXUINT64'
  #define G_MAXUINT64     G_GUINT64_CONSTANT(0xffffffffffffffff)
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  glib/glibconfig.h:69:52: note: expanded from macro 'G_GUINT64_CONSTANT'
  #define G_GUINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##ULL))
                                                     ^~~~~~~~
  <scratch space>:96:1: note: expanded from here
  0xffffffffffffffffULL
  ^~~~~~~~~~~~~~~~~~~~~
2023-10-12 11:45:33 +02:00
Luca Bacci
8264b13737 tests/cxx: Do not assume that NULL is a pointer type starting with C++11
Many toolchain did not change the definition of NULL to avoid introducing
breaking changes in existing codebases. For example, on Windows NULL is
0 (int) regardless of the C++ standard in use.

Fixes the following warnings on CLang when compiling for Windows:

  ../glib/glib/tests/cxx.cpp:539:34: warning: missing sentinel in function call [-Wsentinel]
    g_test_init (&argc, &argv, NULL);
                                   ^
                                   , nullptr
  ../glib/glib/gtestutils.h:298:9: note: function has been explicitly marked sentinel here
  void    g_test_init                     (int            *argc,
          ^

  ../glib/gio/tests/cxx.cpp:62:34: warning: missing sentinel in function call [-Wsentinel]
    g_test_init (&argc, &argv, NULL);
                                   ^
                                   , nullptr
  ../glib/glib/gtestutils.h:298:9: note: function has been explicitly marked sentinel here
  void    g_test_init                     (int            *argc,
          ^
2023-10-12 11:45:03 +02:00
Luca Bacci
107311afce glib/gtimezone.c: Declare Unix-only functions under G_OS_UNIX
Fixes the following warnings on CLang when compiling for Windows:

  ../glib/glib/gtimezone.c:95:22: warning: unused function 'gint64_from_be' [-Wunused-function]
  static inline gint64 gint64_from_be (const gint64_be be) {
                       ^
  ../glib/glib/gtimezone.c:99:22: warning: unused function 'gint32_from_be' [-Wunused-function]
  static inline gint32 gint32_from_be (const gint32_be be) {
                       ^
  ../glib/glib/gtimezone.c:103:23: warning: unused function 'guint32_from_be' [-Wunused-function]
  static inline guint32 guint32_from_be (const guint32_be be) {
                        ^
2023-10-12 11:44:59 +02:00
Luca Bacci
5400f4e128 glib/gmessages.c: Remove unused function
Fixes the follwing warning on CLang:

  ../glib/glib/gmessages.c:433:1: warning: unused function 'dowrite' [-Wunused-function]
  dowrite (int          fd,
  ^
2023-10-12 11:44:56 +02:00
Luca Bacci
f075db637a glib/giowin32.c: Add G_GNUC_FALLTHROUGH annotation
Fixes the following warning on CLang:

  ../glib/glib/giowin32.c:1665:7: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
        default:
        ^
  ../glib/glib/giowin32.c:1665:7: note: insert '__attribute__((fallthrough));' to silence this warning
        default:
        ^
        __attribute__((fallthrough));
  ../glib/glib/giowin32.c:1665:7: note: insert 'break;' to avoid fall-through
        default:
        ^
        break;
2023-10-12 11:44:48 +02:00
Luca Bacci
337912072a Windows: Compile with the UNICODE / _UNICODE macros
It's the recommended way to build C/C++ projects on Windows, see
https://learn.microsoft.com/en-us/windows/win32/intl/conventions-for-function-prototypes
2023-10-12 11:32:03 +02:00
Matthias Clasen
f679a784d2 docs: Drop the GQuark SECTION
Move the content to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
5a2a0aeaf9 docs: Move the GStringChunk SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
57219c14a0 docs: Move the GTimer SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
a47bdb2638 docs: Move GRegex SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
45f6f43fc6 docs: Mark all GWakeup docs as private
This is not public API.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
ccfedf08cb docs: Move the GPatternSpec SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
f2b1e4d936 docs: Move the GKeyFile SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
f27af99233 docs: Move the unicode SECTION
Move the content to the new unicode.md file.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
6052639a5c docs: Update Unicode version history
Unicode 14 and 15 were missing from this list.
2023-10-11 17:38:31 +01:00
Matthias Clasen
55a844a465 docs: Move the GDate SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
1dae4fc618 docs: Move the GPathBuf SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
be9a463a10 docs: Move the GStrvBuilder SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
c50f94e41e docs: Move the GScanner SECTION
Not much here to begin with.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
5a415ee93f docs: Move the GTimeZone SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
7b4d00e0a4 docs: Move GDateTime SECTION
Move the contents to the struct comment.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
7fd50be9d0 docs: Move bookmarkfile SECTION
Move the content to the struct docs.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
d028759903 docs: Drop the threadpool SECTION
Move the contents to the GThreadPool struct docs.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
2e47610560 docs: Drop the GString SECTION
Move the contents to the GString struct docs.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
97cb9fa220 docs: Move the refstring SECTION
Move the contents to the data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
8164220213 docs: Move the sequence SECTION
Add the contents to the data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
c226088028 docs: Move the GNode SECTION
Move the contents to the data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
2191c6024a docs: Move the tree SECTION
Move the content to the new data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
0ce33a6fee docs: Move the asyncqueue SECTION
Move the contents to the new data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
25aeddd2a7 docs: Move the queue SECTION
Add the content to the new data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
f88d96e2ad docs: Move the GHashTable SECTION
Move the content to the new data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
ed1bc3228b docs: Move list SECTIONs
Move the content to the data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
09733b6531 docs: Move the array SECTIONs
Move the content to the new data-structures.md file.

Helps: #3037
2023-10-11 17:38:30 +01:00
Philip Withnall
c140f83922 Merge branch 'migrate-to-gi-docgen' into 'main'
Switch to using gi-docgen for docs (batch 1)

See merge request GNOME/glib!3591
2023-10-11 15:21:10 +00:00
Matthias Clasen
ab066d4856 docs: Move the GOption SECTION
Move the content to the new goption.md file.

Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
8b9c4cfb87 docs: Move the GMarkup SECTION
Move the content to the new markup.md file.

Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
7c5fc4eb26 docs: Move the GSlice documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
1a090564d2 docs: Move GTest/test framework documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
d8b25ecda3 docs: Move GMainLoop documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
6c6337aa27 docs: Move macros documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
48c70b557e docs: Move logging documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
7b954a8d15 docs: Move i18n documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
46eed6009b docs: Move GError documentation to Markdown
Helps: #3037
2023-10-11 14:01:29 +01:00
Matthias Clasen
a73d3d7b8f docs: Move byte conversion macro documentation to Markdown
Helps: #3037
2023-10-11 14:01:28 +01:00
Matthias Clasen
9725c012b1 docs: Move character set conversion docs to Markdown
Helps: #3037
2023-10-11 14:01:28 +01:00
Matthias Clasen
0b56387ad5 docs: Move GThread documentation to Markdown
Helps: #3037
2023-10-11 14:01:28 +01:00
Matthias Clasen
c3713e1b67 docs: Move GRcBox/GArcBox and refcounting docs to Markdown
Helps: #3037
2023-10-11 14:01:28 +01:00
Alex Richardson
ab7e584e9f Cast via guintptr when adding/removing bitsflags on pointers
Round-tripping pointers via gsize is not guaranteed to work (the C standard
only requires this for (u)inptr_t) and in fact breaks on CHERI-enabled
systems such as Arm Morello where pointers are 128-bits but size_t is 64.
This means the current casts would strip the high bits of the pointer and
return a non-dereferenceable value. Fix this by casting the operand that
holds the pointer to guintptr instead of gsize.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-10 08:30:46 -07:00
Alex Richardson
c762d51134 gatomic: Use g(u)intptr where appropriate
This is required for CHERI systems such as Arm Morello, where gsize is
not large enough to hold a pointer. For all other architectures this
should not result in any functional changes since gsize is already the
same size (and I believe for most architectures even the same type)
as guintptr.

This is fully ABI compatible with all currently supported architectures
and should also be fully API compatible except for some rather unlikely
examples such as someone happening to use something like
`decltype(g_atomic_pointer_add(&a, 0))` in a C++ context where it
changes name mangling of some function.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-10 08:30:46 -07:00
Alex Richardson
877c575cd9 gbitlock: don't assume sizeof(gsize) == sizeof(gpointer)
Use a gpointer* instead of a gsize* as the g_atomic_pointer_* argument.
This is required for architectures such as Arm Morello where gsize is
64 bits but gpointer is 128 bits.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-10 08:30:46 -07:00
Philip Withnall
f7d2a58be6 Merge branch 'tests_meson_targets' into 'main'
glib/tests/meson.build: remove identical build targets

See merge request GNOME/glib!3629
2023-10-10 09:51:36 +00:00
Hannes Müller
5a1300db0a glib/tests/meson.build: remove identical build targets
If no error with -Werror=sign-conversion, the resulting object file
does not differ from compilation without -Werror=sign-conversion.
So the -Werror argument is now applied directly to string.c and testing.c.
Finally, the currently specific -Werror targets string-macro and
testing-macro are removed.
2023-10-10 11:16:25 +02:00
Philip Withnall
2191b5aa05 glib-unix: Use full path to gstdio.h include
This fixes use of `glib-unix.h` from outside the GLib build path.

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

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3457#note_1864368
2023-10-09 22:18:18 +01:00
Philip Withnall
9b51346237 Merge branch 'wip/smcv/auto-unix-pipe' into 'main'
glib-unix: Add convenience API for pipes

See merge request GNOME/glib!3457
2023-10-09 18:00:36 +00:00
Simon McVittie
e80b0c4e4b gspawn: Use GUnixPipe on Unix
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-09 18:44:38 +01:00
Simon McVittie
9e20a7d0e7 tests: Exercise GUnixPipe
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-09 18:44:38 +01:00
Simon McVittie
26c7b308ba tests: Break out assert_fd_was_closed() into a header
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-09 18:44:38 +01:00
Simon McVittie
f31db7d370 glib-unix: Add convenience API for pipes
We can't easily use g_autofd with g_unix_open_pipe, because its
parameter is an array of two fds that both need closing. Add an inline
convenience wrapper providing the obvious semantics.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-09 18:44:38 +01:00
Philip Withnall
240156d174 Merge branch '3098-keyfile-escaping' into 'main'
Revert "gkeyfile: Temporarily re-allow invalid escapes when parsing strings"

Closes #3098

See merge request GNOME/glib!3618
2023-10-09 16:50:56 +00:00
Simon McVittie
6fd1037361 gspawn: Use g_clear_fd() instead of reinventing it
g_clear_fd() is documented to be async-signal safe whenever the
fd is either negative or valid (which it should be here) and the error
is NULL (which it always is here).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-09 17:42:04 +01:00
Ray Strode
7bbd4328f6 wakeup: Fix g_wakeup_acknowledge if signal comes in
It's not very likely, but there is a small chance that an
incoming signal could disturb the non-blocking read calls in
g_wakeup_acknowledge, leading to a subsequent spurious wake up.

This commit addresses the problem by doing the usual EINTR
loop (which is already present on the write side incidentally)
2023-10-05 09:55:49 -04:00
Philip Withnall
24f5711287 Merge branch 'wip/chergert/fix-eventfd-overreads' into 'main'
wakeup: do single read when using eventfd()

See merge request GNOME/glib!3621
2023-10-05 09:38:15 +00:00
Philip Withnall
4863561a46 Merge branch 'once-init-annotations' into 'main'
gthread: Fix optional/nullable annotations for g_once_init_*()

See merge request GNOME/glib!3581
2023-10-04 22:43:49 +00:00
Philip Withnall
da278bdd0b Merge branch 'wip/chergert/queue-for-sourcelist' into 'main'
gmain: avoid a GList traversal when removing source

See merge request GNOME/glib!3620
2023-10-04 22:40:58 +00:00
Philip Withnall
57b41b8fec Merge branch 'g-once-enter-ptr' into 'main'
gthread: introduce g_once_init_{enter,leave}_pointer

See merge request GNOME/glib!3577
2023-10-04 22:22:54 +00:00
Christian Hergert
de79831e3c wakeup: do single read when using eventfd()
Previously, this would loop as long as read() got the expected number of
bytes back, which is 8. That means every successful read() of the eventfd
would perform an additional syscall() as a followup.

This is not ideal because eventfd (unless used as an EFD_SEMAPHORE) will
reset the counter as part of the read(). So that means that we either do
an additional throw-away syscall() or potentially race against a producer
generating new events before this change.
2023-10-04 14:01:23 -07:00
Christian Hergert
5e96ed64c9 gmain: avoid a GList traversal when removing source
Currently the GSourceList has it's own allocation plus a secondary
allocation for the GList which contains it (from GMainContext). Not only
are these a pointer chase, but they are on separate cachelines too. Without
changing the code much we can at least keep things on the same cacheline
so that the pointer chase matters less.

Since the GList becomes embedded in the GSourceList you can use a
g_queue_unlink() directly removing the link without traversing the GList
like was done before.

Furthermore, we can simplify some code with g_queue_push_tail_link()
instead of some extra branching.
2023-10-04 13:37:06 -07:00
Alex Richardson
a1dfecf11f Use g_once_init_{enter,leave}_pointer where appropriate
This should not result in any functional changes, but will eventually
allow glib to be functional on CHERI-enabled systems such as Morello.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-04 13:57:16 +01:00
Alex Richardson
726eca7c89 gthread: introduce g_once_init_{enter,leave}_pointer
These functions can be used to initalize pointer-type variables rather
than a gsize. This is required to support CHERI-enabled platforms where
gsize cannot be used to store pointers. Follow-up changes will migrate
the uses of g_once_init that store pointers to the new API

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-04 13:57:16 +01:00
Luca Bacci
c287e69c0a tests/constructor: Fix "unknown pragma ignored" warning on clang 2023-10-04 13:43:05 +01:00
Philip Withnall
9c81ff46a2 Merge branch 'fix-z-format-tests' into 'main'
tests: Fix gdatetime test on non-UTC systems

See merge request GNOME/glib!3613
2023-10-04 12:41:30 +00:00
Philip Withnall
ef28253e57 tests: Separate invalid escaping tests for GKeyFile
One test key was serving two purposes, which meant tests for it couldn’t
be separated out. It was testing escape-at-end-of-line and also
invalid-escape.

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

Helps: #3098
2023-10-04 11:30:02 +01:00
Philip Withnall
76d77cf623 Revert "gkeyfile: Temporarily re-allow invalid escapes when parsing strings"
This reverts commit 4a96727642.

It was a temporary workaround to prevent disruption to apps late on in
the 2.78 cycle. Since we’re now early in the 2.80 cycle, let’s revert
the workaround and allow apps more time to fix their error handling for
`GKeyFile`.

Fixes: #3098
2023-10-04 11:01:35 +01:00
Philip Withnall
62c33e653f tests: Fix gdatetime test on non-UTC systems
Commit 0b114b2687 accidentally made the
tests only pass on systems running in a UTC timezone, as it checked the
local timezone `%Z` format against `UTC`.

This happens to pass on all the GLib CI runners except the macOS one,
which is running under CET.

Make the formatting tests timezone-independent by running them with UTC
datetimes. There’s already a separate test for checking that `%Z` works
correctly in a non-UTC timezone (`test_z`).

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

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3611#note_1859208
2023-10-04 10:14:20 +01:00
Philip Withnall
31e96edbdd Merge branch 'glib-2.78.0-g_assert_cmpint' into 'main'
gtestutils.h: Fix warning with -Wsign-conversion caused by g_assert_cmpint

See merge request GNOME/glib!3590
2023-10-04 08:30:43 +00:00
Philip Withnall
9f6b42af6e Merge branch 'vectored-exception-handlers' into 'main'
Small fixes and cleanups for Vectored Exception Handlers

See merge request GNOME/glib!3569
2023-10-04 08:19:57 +00:00
Philip Withnall
fdfaa993e6 Merge branch 'fix-unaligned-dirent64' into 'main'
Buffer needs to be aligned correctly to receive linux_dirent64.

See merge request GNOME/glib!3582
2023-10-03 17:43:13 +00:00
Sebastian Wilhelmi
9a48cbf27b Buffer needs to be aligned correctly to receive linux_dirent64. 2023-10-03 17:43:12 +00:00
badcel
85d2a7549d
Update GStrv annotations 2023-10-03 16:09:03 +02:00
Philip Withnall
b4e6a834a2 Merge branch 'tls-callbacks' into 'main'
Make use of TLS callbacks for static builds on Windows

Closes #3087

See merge request GNOME/glib!3560
2023-10-03 10:00:44 +00:00
Philip Withnall
d8be7a9a41 Merge branch 'update-grand-annotations' into 'main'
Update GRand annotations

See merge request GNOME/glib!3572
2023-10-03 09:27:37 +00:00
Philip Withnall
83218add7d Merge branch 'upate-gstringchunk-annotations' into 'main'
Update GStringChunk annotations

See merge request GNOME/glib!3571
2023-10-03 09:26:30 +00:00
Philip Withnall
2f7b20538f Merge branch 'update-hmac-annotations' into 'main'
Update annotations for GHmac

See merge request GNOME/glib!3567
2023-10-03 09:16:54 +00:00
Philip Withnall
ee56c7697b Merge branch 'update-annotations' into 'main'
Update annotations for GAsyncQueue and GDir

See merge request GNOME/glib!3566
2023-10-03 09:11:42 +00:00
Luca Bacci
c4c39ea52a tests/constructor: Support systems where dlclose is a no-op
POSIX allows dlclose() implementations that are no-ops,
and in such case library destructors run at application
exit rather than dlclose().

That's the case, for example, of UNIX systems with the
Musl LibC.
2023-10-03 11:07:16 +02:00
Luca Bacci
85e21ff757 tests/constructor: Test all destructors
Previously we were only testing destructors that run on
dlclose, now we also test destructors running at application
exit.
2023-10-03 11:07:11 +02:00
Philip Withnall
57169dd92f Merge branch 'update-gtimer-annotations' into 'main'
Update GTimer annotations

See merge request GNOME/glib!3573
2023-10-03 08:46:20 +00:00
Philip Withnall
8adc39a870 Merge branch 'update-goption-annotations' into 'main'
Update GOptionContext annotations

See merge request GNOME/glib!3568
2023-10-03 08:43:54 +00:00
Luca Bacci
f23a31ee26 Use helper shared library for the constructor test 2023-10-03 10:43:34 +02:00
Philip Withnall
a9f2ffe788 Merge branch 'new_datetime_mods' into 'main'
Add support for case modifiers to DateTime

Closes #3115

See merge request GNOME/glib!3584
2023-10-03 08:43:03 +00:00
Rick Calixte
0b114b2687 Add support for case modifiers to DateTime 2023-10-03 08:43:03 +00:00
Luca Bacci
683991d836 Add test for module constructors, destructors and TLS callbacks 2023-10-03 10:33:42 +02:00
Luca Bacci
0bbe3c8447 gconstructorprivate.h: Add seamless support for C++
G_DEFINE_TLS_CALLBACK could be made public in the future
2023-10-03 10:26:10 +02:00
Luca Bacci
f916621d72 gthread-win32: Clean up GPrivate data in all cases 2023-10-03 10:26:10 +02:00
Luca Bacci
8436785a5f Make use of TLS callbacks for static builds on Windows
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3087
2023-10-03 10:26:10 +02:00
Luca Bacci
51cbb63cd5 Add support for TLS callbacks on Windows 2023-10-03 10:25:06 +02:00
Chun-wei Fan
b60d97f428 gconstructor.h: Ensure [c|d]tor prototypes are present for MSVC
This way, the generated GResource code won't choke if no prototypes are found
when being built by clang-cl, which also goes the _MSC_VER >= 1500 route.

Fixes clang-cl build of generated GResources code when building the appstream
git checkout, which supported Windows recently, as the build there demands
'-Werror,-Wmissing-prototypes'.

Part-of: <https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3589>
2023-10-02 18:26:19 +01:00
Luca Bacci
991cb9ef8c tests/gutils-user-database: Fix test on macOS
Use DYLD interposing on macOS
2023-09-27 16:19:44 +02:00
Luca Bacci
91b41f5234 tests/gutils-user-database: do not hardcode library name
Use build_tgt.full_path() and import('fs').name()
2023-09-26 12:10:47 +02:00
Hannes Müller
3cb79ee261 gtestutils.h: Fix warning with -Wsign-conversion caused by g_assert_cmpint
With gcc and clang using -Wsign-conversion a related warning is generated
if code using glib 2.78.0 contains function g_assert_cmpint().

Warning is fixed by adding related casts. Related tests have been also
updated and will be also compiled with -Wsign-conversion to detect
related problems in future.
2023-09-22 08:57:40 +02:00
Philip Withnall
56daac02d1 gthread: Fix optional/nullable annotations for g_once_init_*()
The pointer argument must not be `NULL` (though it can point to a
location which is zero/null-valued), so this should be `(not optional)`
not `(not nullable)`.

Spotted in !3577.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-09-13 14:18:55 +01:00
Luca Bacci
13c5256fd7 gthread-win32: Fix size argument passed to RaiseException
https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022#set-a-thread-name-by-throwing-an-exception
2023-09-13 14:04:26 +02:00
Luca Bacci
19d06340cf gthread-win32: Check for specific exception code
https://learn.microsoft.com/en-us/cpp/code-quality/c6320?view=msvc-170
2023-09-13 14:04:26 +02:00
Luca Bacci
f4b53cacbf gthread-win32: No need to raise thread name exception if the debugger is not present
As outlined in [1], raising the exception without a debugger attached
isn't of any use, as the thread name won't be stored anywhere.
The system doesn't trap such exception, only debuggers.

This also fixes a TOCTTOU issue between the IsDebuggerPresent() check
and the RaiseException() call.

References:
 [1] - https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022#set-a-thread-name-by-throwing-an-exception
2023-09-13 14:04:26 +02:00
Luca Bacci
fb3f1733c3 gthread-win32: Print critical if we cannot register fallback handler for the thread name exception 2023-09-13 14:04:26 +02:00
Luca Bacci
d60ca9aa38 gthread-win32: Register fallback handler for thread name as last
Many ASAN implementations install Vectored Exception Handlers that
must be the first in the sequence. As we don't really care about
ordering, let's place our handler as last.

References:
 - https://developercommunity.visualstudio.com/t/asan-problems-when-manual-exception-handling/1242524
 - https://source.chromium.org/chromium/chromium/src/+/main:components/browser_watcher/extended_crash_reporting.cc;l=150;drc=4ced8912
2023-09-13 14:04:11 +02:00
Philip Withnall
f51f40c440 Merge branch 'find-test-program-freebsd' into 'main'
Fix test_find_program on FreeBSD

See merge request GNOME/glib!3580
2023-09-13 11:21:07 +00:00
Alex Richardson
25ae9f59e8 Fix test_find_program on FreeBSD
On FreeBSD /home is generally a symlink to /usr/home, so the relative
resolves to /usr/bin instead of /bin and `sh` can only be found in /bin
on FreeBSD. Fix this by resolving symlinks in the CWD first.
2023-09-12 21:51:15 -07:00
Alex Richardson
403f7a10dc GSIZE_TO_POINTER(): appease stricter compilers
Some compilers (e.g. CHERI LLVM) warn when casting a non-intptr_t integer
type to a pointer. The GSIZE_TO_POINTER() macro thus triggers warnings
which can be silence by casting to guintptr before gpointer.

NB: This macro must not be used to create valid pointers from a integer.
2023-09-12 10:23:20 -07:00
Alex Richardson
ed6cc1ddb2 guniprop.c: Avoid creating (temporarily) out-of-bounds pointers
This is detected by UBSan on CHERI systems (e.g. Arm Morello) and could
result in non-derefenceable pointers when compiled without optimizations.
2023-09-11 22:50:05 -07:00
badcel
784b8f5cc9
Update GOptionContext annotations 2023-09-11 13:42:10 +02:00
badcel
7ae41b9427
Update GDir annotations 2023-09-11 13:38:26 +02:00
badcel
01b1570bb5
Update GAsyncQueue annotations 2023-09-11 13:38:03 +02:00
badcel
f5860b0f4a
Update annotations for GHmac 2023-09-11 13:31:39 +02:00
badcel
5546757b2f
Update GStringChunk annotations 2023-09-11 12:52:39 +02:00
badcel
bd7bd87c8e
Update GTimer annotations 2023-09-11 11:55:45 +02:00
badcel
47c7eda5e0
Update GRand annotations 2023-09-11 11:33:47 +02:00
Luca Bacci
a76de5e039 gconstructor.h: Drop support for Visual C++ 2005
It's not supported anymore, remove dedicated code
2023-09-07 14:52:11 +02:00
Michael Catanzaro
a366189062 Merge branch 'keyfile-invalid-escapes' into 'main'
gkeyfile: Temporarily re-allow invalid escapes when parsing strings

Closes #3095

See merge request GNOME/glib!3565
2023-09-06 14:02:58 +00:00
Sebastian Wilhelmi
f7d930a58b Fix gutils-user-database unit test
The gutils-user-database.c is broken in two ways and currently doesn't test anything:

* It only overrides getpwuid, where the implementation used getpwnam_r if it exist, which should be every system for at least 20 years.
* It only partly cargo-culted setting the environment for the local and installed tests, but failed to actually set the environment for either.
2023-09-06 12:11:49 +00:00
Philip Withnall
4a96727642 gkeyfile: Temporarily re-allow invalid escapes when parsing strings
Before commit 71b7efd08a, `GKeyFile`
incorrectly allowed invalid escape sequences: it would treat the
sequence as a literal, set a `GError`, but not return failure from the
function. So if a caller was explicitly checking for returned `GError`s,
they could detect the invalid escape; but if they were just checking the
function’s return value, they’d miss it.

This is not correct use of `GError`, and the [Desktop Entry
Spec](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s04.html)
doesn’t allow for invalid escape sequences to be accepted. So it’s wrong
in both ways.

However, the commit above changed this behaviour without realising it,
quite close to the 2.78 stable release deadline. There are numerous key
files in the wild which use invalid escape sequences, and it’s too late
in the cycle to ‘break’ parsing of all of them.

So, for now, revert to the old behaviour for invalid escape sequences,
and give people another cycle to adapt to the changes. This will likely
mean they end up calling `g_key_file_get_value()` rather than
`g_key_file_get_string()`. See
https://gitlab.gnome.org/GNOME/glib/-/issues/3098 for tracking
re-enabling the error handling for invalid escape sequences.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Fixes: #3095
See: #3098
2023-09-06 12:08:56 +01:00
Philip Withnall
37309f165e Merge branch 'gdbplugin' into 'main'
gdb: Workaround optimized out quark_seq_id

See merge request GNOME/glib!3559
2023-09-04 11:29:57 +00:00
Thibault Saunier
033b472432 gdb: Workaround optimized out quark_seq_id 2023-09-04 11:29:57 +00:00
Philip Chimento
a10f42dad8 gthread: Annotate g_thread_exit() with G_NORETURN
pthread_exit() is also marked noreturn, and the function does not in
fact return.

For win32, I can't find a copy of the header file to check if
_endthreadex() is marked with __declspec(noreturn), but its
documentation does say that it never returns.
2023-09-01 23:49:25 -07:00
Jan Luebbe
71b7efd08a gkeyfile: Fix overwriting of GError
When parsing a line of "key3=foo\i\" in a keyfile,
g_key_file_parse_value_as_string currently first sets the error to
'contains invalid escape' and later to 'contains escape character at end
of line'.

This leaks the first GError and causes the following warning message:
  Error set over the top of a previous GError or uninitialized memory.
  This indicates a bug in someone's code. You must ensure an error is
  NULL before it's set. The overwriting error message was: Key file
  contains escape character at end of line

Fix this by returning when an error is detected. As we may have
collected data in pieces, we instead collect to a tmp_pieces GSList and
free it on error.
2023-08-30 19:17:44 +02:00
Alexander Kanavin
9bdb19b821 glib/tests/asyncqueue.c: skip test_async_queue_timed in 2038 or later 2023-08-24 19:45:09 +00:00
Alexander Kanavin
285db475ec glib/gfileutils.c: use 64 bits for value in get_tmp_file()
On 32 bit systems 'long' value will overflow in 2038 and become negative.
As it is used to index into letters array, and % operation preserves signs,
data corruption will then occur.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
2023-08-23 14:50:41 +02:00
Michael Catanzaro
8754a57d95 Merge branch '3083-option-docs-list' into 'main'
goption: Fix list formatting in documentation comment

Closes #3083

See merge request GNOME/glib!3546
2023-08-21 13:36:58 +00:00
Philip Withnall
8673c3f757 Merge branch 'rybalkin-gregex-jit-stack-overflow-fallback' into 'main'
gregex: if JIT stack limit is reached, fall back to interpretive matching

See merge request GNOME/glib!3545
2023-08-21 10:39:29 +00:00
Aleksei Rybalkin
5921ea112d gregex: if JIT stack limit is reached, fall back to interpretive matching
Helps: #2824
2023-08-21 10:39:27 +00:00
Philip Withnall
22752a51c5 goption: Fix list formatting in documentation comment
Not actually tested, but hopefully this will work.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Fixes: #3083
2023-08-21 11:34:27 +01:00
Thomas Haller
84c9d887ee glib: avoid non-reentrant localtime() in g_log_writer_format_fields() 2023-08-21 08:54:31 +02:00
Thomas Haller
471188abdb gdate: add internal helper function _g_localtime() for localtime()/localtime_r()
The point of to be able to call localtime()/localtime_r() from another
place inside glib (without reimplementing the #ifdef).

- also handles failures from localtime_r(). It is documented that it
  might fail, so detect the failure.

- in case of failures of localtime(), still initialize the GDate.
  Previously, we may error out with a g_critical() assertion before.
  However, now that failures from localtime_r() are also caught, I think
  we should make an effort to initialize the GDate to something. It
  either way it not supposed to happen.
2023-08-21 08:53:43 +02:00
Thomas Haller
89b55fa9bc gmain: improve g_warning() for failure in g_child_watch_dispatch()
Print the PID, the errno and the pidfd in case of an unexpected failure
in g_child_watch_dispatch().

This is always(?) caused by a bug in the user application. Also hint to
g_child_watch_source_new() documentation for possible causes.

Also use G_PID_FORMAT for printing GPid values.
2023-08-17 19:12:23 +02:00
Philip Withnall
15022cab15 gtestutils: Mention not ignoring SIGCHLD in g_test_trap_subprocess() docs
Prompted by #3071, this clarifies that `g_test_trap_subprocess()` uses
`g_child_watch_source_new()` internally, so it will not work if any of
the preconditions for using that API are not met. In particular, if
`SIGCHLD` is ignored, things will break.

This documentation is not meant to be an API guarantee which constrains
the implementation of `g_test_trap_subprocess()` in future, just a tip
to people currently using the API.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3071
2023-08-17 14:59:28 +01:00
Philip Withnall
07c4b6c68e glib: Pass O_CLOEXEC rather than FD_CLOEXEC to g_unix_open_pipe()
See the previous commit.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-08-16 14:31:40 +01:00
Philip Withnall
d0dc7171d6 glib-unix: Accept O_CLOEXEC as well as FD_CLOEXEC in g_unix_open_pipe()
This is one step towards rectifying the mistake of using `FD_CLOEXEC` in
the first place. Eventually we may deprecate support for `FD_CLOEXEC`,
as the `O_*` flags better match the underlying `pipe()` API.

See discussion on
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3459#note_1779264

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-08-16 14:31:40 +01:00
Simon McVittie
de6cebb5f6 glib-unix: Don't fall back from O_NONBLOCK to O_NDELAY
Since 5c65437d "glib-unix: Add O_NONBLOCK support to g_unix_open_pipe()"
we have been using O_NONBLOCK unconditionally, so we might as well drop
the fallback here as well. This commit should be reverted if someone
reports a significant/supported platform that genuinely doesn't have
O_NONBLOCK.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-16 14:02:35 +01:00
Simon McVittie
40508b35b9 glib-unix: Assert that O_NONBLOCK and FD_CLOEXEC are numerically distinct
Since 5c65437d "glib-unix: Add O_NONBLOCK support to g_unix_open_pipe()"
we have effectively been assuming that these two flags are
distinguishable. If that's an assumption we want to make, we should make
it a static assertion, so that GLib will fail to compile on platforms
where it isn't true.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-16 14:02:35 +01:00
Philip Withnall
9b15842ec1 Merge branch 'rybalkin-gregex-jit-increase-stack-size' into 'main'
gregex: set default max stack size for PCRE2 JIT compiler to 512KiB

See merge request GNOME/glib!3530
2023-08-15 13:26:43 +00:00
Aleksei Rybalkin
c3ff5b8eb3 gregex: set default max stack size for PCRE2 JIT compiler to 512KiB
Previous default used was 32KiB (the library default) which caused some
complex patterns to fail, see #2824. The memory will not be allocated
unless used.
2023-08-14 20:43:15 +02:00
Aleksei Rybalkin
842a105464 gregex: remove redundant call to enable_jit_with_match_options
There is no point to enable jit in g_regex_new, since JIT will be only
used when we do a first match, and at that point
enable_jit_with_match_options will be called again already and will
update the options set in g_regex_new. Instead just run it at first
match for the first time, to the same end result.
2023-08-14 20:32:48 +02:00
Emmanuele Bassi
a7c34b431b Merge branch 'tree-asserts' into 'main'
tests: Use g_assert_*() rather than g_assert() in tree tests

See merge request GNOME/glib!3527
2023-08-14 12:45:21 +00:00
Philip Withnall
400a335fe2 Merge branch 'wip/pidfd-exit-status' into 'main'
main: Don't treat si_pid from pidfd as child exiting

Closes #3071

See merge request GNOME/glib!3433
2023-08-12 20:05:09 +00:00
Philip Withnall
ca9723f951 tests: Use g_assert_*() rather than g_assert() in tree tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-08-12 19:41:26 +01:00
Philip Withnall
3029f08ed8 Merge branch 'gtree-overflow' into 'main'
GTree: Handle node counter overflow and return it as an unsigned value

See merge request GNOME/glib!3521
2023-08-12 18:35:17 +00:00
Jonas Ådahl
8d78fa7887 main: Don't treat si_pid from pidfd as child exiting
We might repeatedly get si_pid == 0 for a child that hasn't exited,
meaning we won't get a correct exit status. This seems to happen when
the glib application tracks a ptrace():ed child process; the correct
exit status of the process using e.g. a BPF program, where one can
observe that glib appears to get it wrong.

Fixes: #3071
2023-08-12 19:08:46 +01:00
Marco Trevisan (Treviño)
694eb3aa02 gspawn: Mark child setup in g_spawn_sync() as call scope
While it's only called one time, this is something that can only happen
during the function call, so it's more correct to mark it as call scope,
so that bindings don't have to wait for the callback invocation to
cleanup the data.
2023-08-10 23:37:48 +02:00
Marco Trevisan (Treviño)
ff23b24254 gspawn, gdataset: Restore nullable callback functions
As per commit 5d738ddc some callbacks are not nullable anymore even
though they should be.

This breaks the introspection as some arguments won't be considered
nullable anymore.

You can notice this in https://gitlab.gnome.org/3v1n0/gjs/-/pipelines/558839
where some some tests are running against stable g-i version and others
(the failing ones) against the devel one.
2023-08-10 23:37:14 +02:00
Maciej S. Szmigiero
faa11d0910 GTree: Add a G_STATIC_ASSERT for MAX_GTREE_HEIGHT
Makes sure we don't accidentally set it too small and overflow a tree path
array.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
2023-08-09 15:15:13 +02:00
Maciej S. Szmigiero
f08191e398 GTree: Check for node counter overflow when adding new elements
Currently, when adding new elements to GTree we blindly increment the node
counter, which is only of guint size (so 32-bit even on 64-bit Unix
platforms).

This is even more problematic because the only way to check whether
particular GTree is empty is to check whether its node count is zero.
This will obviously give wrong answer if this counter overflows.

Let's fix this by adding an appropriate check when adding a new node.

For the recently added g_tree_{insert,replace}_node () API we can simply
return NULL in such case.

However, the older g_tree_{insert,replace} () API doesn't have any ability
to return an error so for them we follow the example of
g_ptr_array_extend () and g_ptr_array_set_size () by calling g_error ()
when this happens.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
2023-08-09 15:15:09 +02:00
Maciej S. Szmigiero
1237525da2 GTree: Annotate the real return value type of g_tree_nnodes ()
g_tree_nnodes () is returning a signed integer type (gint), however the
tree node counter value type is really an unsigned integer (guint).

This means that the returned size will be negative if the container holds
more than G_MAXINT elements.

Add a note to this function that its return value can be cast back to
guint in order to support its full range of values.

This will also make sure that we take this into account in future Glib
versions.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
2023-08-09 14:57:14 +02:00
Federico Gallo Herosa
89be3d357d
Fix typos
Fix typo in gio/gappinfo (duplicated word)
Fix typo in gio/gtlsdatabase.c (duplicated word)
Fix typo in gio/gapplication.c (duplicated word, previous words rearranged to improve readability)
Fix typo in glib/tests/gvariant.c (duplicated word)
Fix typo in glib/win_iconv.c (duplicated word)
Fix typo in gio/gschema.dtd (meaning, missing letter)
Fix typo in gio/gdbusintrospection.c (duplicated word)
Fix typo in gio/gdbusintrospection.c (duplicated word).
2023-08-01 15:33:21 -03:00
Emmanuele Bassi
0cc84f9f3e Merge branch '931-gprivate-optimisations' into 'main'
GPrivate: eliminate a malloc for pthread_key_t on most platforms

Closes #931

See merge request GNOME/glib!3507
2023-07-30 10:56:53 +00:00
Emmanuele Bassi
f7bc7d6f3e Merge branch '473-gvariant-systemtap' into 'main'
GVariant: add probes for SystemTap

Closes #473

See merge request GNOME/glib!3508
2023-07-30 10:56:22 +00:00
Emmanuele Bassi
95f372086a Merge branch 'revert-3509' into 'main'
Revert "build-sys: drop -mms-bitfields GCC flag"

See merge request GNOME/glib!3514
2023-07-30 10:50:05 +00:00
Philip Withnall
1f59981f7f Merge branch 'th/fix-main-context-release-owner-check' into 'main'
gmain: drop owner check assertion in g_main_context_release()

Closes #3054

See merge request GNOME/glib!3513
2023-07-30 10:09:09 +00:00
Thomas Haller
07f8a5daa3 gmain: drop owner check assertion in g_main_context_release()
As commit 44616ebafd ('gmain: More explicitly document
g_main_context_release() prereqs') correctly notes, you need to have the
context acquired before releasing it (just like a ref must match an
unref).

Commit 3926af723a ('gmain: Add precondition assertions to
g_main_context_release()') then goes one step further, and requires that
the calling thread is also the owner (the thread, that acquired the
context).

This is something which has been documented by g_main_context_release()
for years:
> Releases ownership of a context previously acquired **by this thread**

With acquire/release and g_main_context_is_owner() we track the thread
that acquired the context. That is mainly useful for asserting
correctness to not accessing the context from an unexpected thread.
Note that g_main_context_acquire() returns FALSE and does nothing when
the context is already acquired from another thread. Methods like
g_main_context_{prepare,query,dispatch}() require that the calling
thread is the owner (although, they don't assert for that, which they
maybe should).

With the assertion, it means you cannot pass an acquired context to
another thread for release. Obviously, if you pass on an acquired
context to another thread, the only next thing you can do is
g_main_context_release() (no acquire,prepare,query,dispatch). But it's
still useful to be able to release it, and to be able to keep it
acquired for a prolonged time.

libnm needs that, as it integrates a GMainContext into another
GMainContext. For that, it needs to acquire the inner context and keep
it acquired for as long as the context is integrated. Otherwise, when a
source gets attached to the inner context, the inner context is not
woken up (see g_source_attach_unlocked()). In commit e26a8a5981 ('Add
G_MAIN_CONTEXT_FLAGS_OWNERLESS_POLLING'), a flag was introduced to solve
that same problem, without keeping the inner context acquired all the
time. Note that G_MAIN_CONTEXT_FLAGS_OWNERLESS_POLLING is a flag of the
GMainContext, so it only works if the user who integrates the inner
context also controls how the context was created.  For libnm, having
the inner context acquired at all times is no problem, because it's
understood that the user gives up agency on the inner context while it's
integrated. The only thing to consider is that the outer context might
be iterated on another thread. When calling prepare,query,dispatch on
the inner context, the code will notice it, release the inner context
and re-acquire it on the new thread ([1]).  This works just fine, but it
requires that g_main_context_release() works from any thread.

So, in order to not break NetworkManager, let’s drop the ownership
assertion. However, NetworkManager is strictly breaking the API contract
here, and GLib reserves the right to re-add this assertion in future.

Still keep the assertion for the owner_count.

(Commit and commit message significantly updated by Philip Withnall; all
errors are his.)

[1] 9f01cff04f/src/libnm-glib-aux/nm-shared-utils.c (L4944)

Related: 3926af723a ('gmain: Add precondition assertions to g_main_context_release()')
Related: c67dd9d3fe ('gmain: Add a missing return on error path in g_main_context_release()')

Closes #3054
2023-07-30 11:53:34 +03:00
Philip Withnall
627dc1415c Revert "build-sys: drop -mms-bitfields GCC flag"
This reverts commit 252bbcd207.

After further discussion in !3511, we’ve decided that there are risks
associated with this change, and it’s not the best way of addressing the
original problem.

The original motivation for the change turned out to be that
`-mms-bitfields` was not handled by `windres`, which was receiving it
from `pkg-config --cflags glib-2.0` in some projects. However, if
`windres` is claiming to accept CFLAGS then it should accept (and
ignore) `-mms-bitfields`, since the `-m` family of options are defined
in `man gcc`, just like `-I`, `-D`, etc.

There is some question that there might still be third party projects
which are built with an old enough compiler that `-mms-bitfields` is not
the compiler default. For that reason, we should either still continue
to specify `-mms-bitfields` in the `.pc` file, or add a test to assert
that third party projects are always compiled with `-mms-bitfields` set.
But adding a new test for all third-party compilations is risky (if we
get it wrong, things will break; and it’s a test which may behave
differently on different platforms), so it seems safer to just keep
`-mms-bitfields` in `.pc` for now.

Once all compilers which we require specify `-mms-bitfields` by default,
we can finally drop this flag (without adding a test for third-party
compilations).

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3511
2023-07-29 11:54:22 +03:00
Philip Withnall
39864716d6 Merge branch 'fix_3050' into 'main'
Strip query sections from file: URIs

Closes #3050

See merge request GNOME/glib!3502
2023-07-28 12:52:36 +00:00
Lukáš Tyrychtr
b504cc0841 gfile: Strip query sections from file: URIs
According to https://url.spec.whatwg.org/#file-state
a file URI can have a fragment and query string, so just ignore them
and don't raise an invalid URI error.

Fixes: #3050
2023-07-28 15:04:49 +03:00
Philip Withnall
215a6ed80c gconvert: Rename an internal variable
The old name was not quite correct: the part of a URI which is just past
the scheme might be the hostname or the path. It isn’t necessarily just
a path.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-07-28 15:04:49 +03:00
Simon McVittie
71d44e8d71 testutils: Use prctl PR_SET_DUMPABLE to silence core dumps on Linux
Otherwise, crashing tests like assert-msg-test will still report to
pipe-based crash reporting frameworks like systemd-coredump, even though
the RLIMIT_CORE limit is zero.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-26 15:42:06 +01:00
Simon McVittie
be2c9220d6 testutils: Factor out g_test_disable_crash_reporting()
We're already repeating this in 4 places, and in a subsequent commit
I'll extend it to do more.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-26 15:41:47 +01:00
Philip Withnall
e051f4abaf Merge branch 'win32' into 'main'
build-sys: drop -mms-bitfields GCC flag

See merge request GNOME/glib!3509
2023-07-24 15:52:10 +00:00
Marc-André Lureau
252bbcd207 build-sys: drop -mms-bitfields GCC flag
This flag is problematic for some usages, and is no longer needed since
~2012 GCC 4.7 (https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a6c467624ade35128)

It is dropped from MINGW since:
https://github.com/msys2/MINGW-packages/pull/12891

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-07-24 14:45:09 +04:00
Philip Withnall
be6c9fc410 Merge branch 'wip/antoniof/transfer-full-strv' into 'main'
strfuncs: Add missing ownership annotations for returned string vectors

See merge request GNOME/glib!3499
2023-07-21 21:20:58 +00:00
Michael Catanzaro
5d738ddcfe Audit and fix incorrect use of (closure) in glib
Following Emmanuele's instructions for use of introspection annotations:

https://www.bassi.io/articles/2023/02/20/bindable-api-2023/

I have audited all uses of the (closure) annotation in glib and
determined that only a handful are correct. This commit changes almost
all of our use of (closure) annotations to conform to Emmanuele's rules.
2023-07-21 19:03:57 +01:00
António Fernandes
28dd5f017d strfuncs: Add missing ownership annotations for returned string vectors 2023-07-21 18:47:52 +01:00
Allison Karlitskaya
55abdd5e4a GVariant: add probes for SystemTap
https://bugzilla.gnome.org/show_bug.cgi?id=662779
Fixes: #473
2023-07-21 18:40:13 +01:00
Allison Karlitskaya
766663dafe GPrivate: eliminate a malloc for pthread_key_t on most platforms
We don't know how big a pthread_key_t is, so we malloc() a big enough
chunk of memory for it and store a pointer into the GPrivate struct.

It turns out, on Linux, pthread_key_t is just an int, so we could much
easier just store it directly into the struct.

https://bugzilla.gnome.org/show_bug.cgi?id=737445
Fixes: #931
2023-07-21 17:12:01 +01:00
Allison Karlitskaya
256b195ff1 GPrivate: change return type of internal function
g_private_get_impl() was returning a pointer to the pthread_key_t, but every
function using this was immediately dereferencing it.  Change it so that we
dereference the value in the helper function and return it by value.

https://bugzilla.gnome.org/show_bug.cgi?id=737445
2023-07-21 17:03:31 +01:00
Philip Withnall
b16e682112 Merge branch 'keyfile-regression-3047' into 'main'
gkeyfile: Fix regression #3047 (group comment)

Closes #3047

See merge request GNOME/glib!3498
2023-07-20 11:59:07 +00:00
Philip Withnall
c67dd9d3fe gmain: Add a missing return on error path in g_main_context_release()
This should have been in commit
3926af723a.

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

Fixes: #3054
2023-07-18 11:31:01 +01:00
Gaël Bonithon
51dfb3c229 gkeyfile: Skip group comment when adding a new key to a group
An oversight in 86b4b045: since the comment of group N now consists of
the last null-key values of group N-1, these keys must obviously be
skipped when adding a new non-null key to group N-1.

Closes: #3047
Fixes: 86b4b0453e
2023-07-13 10:32:18 +02:00
Gaël Bonithon
c49502582f gkeyfile: Ensure we don't add extra blank line above new group
A forgotten edge case in 86b4b045: when the last value of the last group
has been added via g_key_file_set_value() and it contains line breaks.
The best we can do in this case is probably to do nothing.

Closes: #3047
Fixes: 86b4b0453e
2023-07-13 10:32:18 +02:00
Alynx Zhou
57b0e72c7b garray: Fix typo in doc comment of g_ptr_array_sort[_with_data]()
Although g_ptr_array_sort_with_data() could achieve the goal, the
wrapper functions should be expected there because that's the reason
why they are added.
2023-07-11 22:42:33 +08:00
G.Willems
d8483ef696 guniprop: fix param direction in g_unichar_get_mirror_char(), for introspection 2023-06-29 23:55:08 +02:00
Marco Trevisan
39e018e151 Merge branch '3007-option-context-colons' into 'main'
goption: Clarify expected format of option group description in docs

Closes #3007

See merge request GNOME/glib!3481
2023-06-29 17:00:49 +00:00
Marco Trevisan
b1ac3f883a Merge branch '3040-gtester-override-find-program' into 'main'
build: Call override_find_program() for gtester

Closes #3040

See merge request GNOME/glib!3478
2023-06-29 16:57:35 +00:00
Philip Withnall
98f9a11390 goption: Clarify expected format of option group description in docs
To match the current widespread usage.

We can’t automatically append a colon to the group description, as that
would interact badly with translation of the string.

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

Fixes: #3007
2023-06-28 17:03:00 +01:00
Dario Saccavino
ccea09c1c8 Avoid stack overflow in gspawn on macOS 2023-06-28 13:42:40 +00:00
Philip Withnall
7d4f6673b9 build: Call override_find_program() for gtester
Just in case anyone tries to look it up using `find_program()` in a
`meson.build` in GLib (or a project pulling GLib in as a subproject) in
future.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-27 14:54:18 +01:00
Daniel P. Berrange
1bfc04a13d glib: reset errno to 0 when futex() returns EAGAIN 2023-06-22 14:22:03 +00:00
Philip Withnall
679560feaa tests: Fix an intermittent timing error with testing g_usleep(0)
The code to test that `g_usleep(0)` returns immediately assumes that
`g_usleep(1)` always takes longer, but that’s not necessarily always the
case. Even if no sleeping happens, the function call for `g_usleep(0)`
could get descheduled and take longer than normal.

This results in occasional failures like this one:
```
GLib:ERROR:../glib/tests/timer.c:367:test_usleep_with_zero_wait: assertion failed (elapsed0 <= elapsed1): (0.000206 <= 0.000202)
```

(Source: https://gitlab.gnome.org/GNOME/glib/-/jobs/2898468)

I can’t think of a suitable invariant comparison which can be done with
the timers, but running the comparison 10 times and allowing it to fail
once should work. A probabilistic test of `g_usleep(0)`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-21 11:52:03 +01:00
Philip Withnall
e1d47f0b0d Merge branch 'wip/pwithnall/macos-testing' into 'main'
tests: Reduce thread and iteration count on CI for /thread/rec-mutex3

See merge request GNOME/glib!3462
2023-06-09 10:13:21 +00:00
Philip Withnall
d861eee868 Merge branch 'wip/smcv/async-signal-safety' into 'main'
gstdio: Improve documentation of some functions as async-signal safe

See merge request GNOME/glib!3458
2023-06-01 13:42:54 +00:00
Philip Withnall
da0a945477 tests: Reduce thread and iteration count on CI for /thread/rec-mutex3
It’s fairly consistently timing out on macOS. Looking at the verbose
test output, it’s still making progress right up until when it times out
(i.e. it hasn’t hit a `GRecMutex` bug and hasn’t deadlocked), so it
seems that the test runner is just hopelessly overloaded/underpowered
for the number of threads and iterations we’re asking it to test.

Tone those numbers down for CI test runs then.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-01 12:19:09 +01:00
Philip Withnall
add5fceedb tests: Move /thread/rec-mutex3 test state into a struct
And dynamically allocate the arrays. This will allow the scale of the
test to be configured in the following commit, which will allow it to be
tweaked to not time out on slow CI runners.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-01 12:12:38 +01:00
Philip Withnall
9db8765e21 tests: Use g_assert_*() rather than g_assert() in rec-mutex tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-06-01 11:53:19 +01:00
Daniel P. Berrangé
29311d4309 gtestutils: print execution time after every test
Displaying the execution time will aid developers in understanding which
test cases are responsible for slow execution times. The test code is
already measuring the execution time for every test case, but is not
reporting that data anywhere accessible to developers running the tests.

The new code will print a TAP comment:

  # slow test /the/test/path executed in NN.NN secs

for any test taking longer than 0.5 seconds to run.

Example new output format:

  $ ./build/glib/tests/unix
  TAP version 13
  # random seed: R02S690dc3c7a04866e4890501eedc7f8eef
  1..13
  # Start of glib-unix tests
  ok 1 /glib-unix/pipe
  # /glib-unix/pipe-stdio-overwrite summary: Test that g_unix_open_pipe() will use the first available FD, even if it?s stdin/stdout/stderr
  # Bug Reference: https://gitlab.gnome.org/GNOME/glib/-/issues/2795
  ok 2 /glib-unix/pipe-stdio-overwrite
  ok 3 /glib-unix/error
  ok 4 /glib-unix/nonblocking
  ok 5 /glib-unix/sighup
  # slow test /glib-unix/sighup executed in 0.50 secs
  ok 6 /glib-unix/sigterm
  # slow test /glib-unix/sigterm executed in 0.50 secs
  ok 7 /glib-unix/sighup_again
  # slow test /glib-unix/sighup_again executed in 0.50 secs
  ok 8 /glib-unix/sighup_add_remove
  ok 9 /glib-unix/sighup_nested
  ok 10 /glib-unix/callback_after_signal
  # slow test /glib-unix/callback_after_signal took 2.00 secs
  ok 11 /glib-unix/child-wait
  # Start of get-passwd-entry tests
  # /glib-unix/get-passwd-entry/root summary: Tests that g_unix_get_passwd_entry() works for a known-existing username.
  ok 12 /glib-unix/get-passwd-entry/root
  # /glib-unix/get-passwd-entry/nonexistent summary: Tests that g_unix_get_passwd_entry() returns an error for a nonexistent username.
  ok 13 /glib-unix/get-passwd-entry/nonexistent
  # End of get-passwd-entry tests
  # End of glib-unix tests

As a practical usage example, the meson log can be queried to find
slow tests project-wide:

  $ grep 'slow test' build/meson-logs/testlog.txt | sort -n -k 7 -r | head
  # slow test /threadpool/basics executed in 36.04 secs
  # slow test /gobject/refcount/properties-3 executed in 30.00 secs
  # slow test /gio/io-basics executed in 12.54 secs
  # slow test /timeout/rounding executed in 10.60 secs
  # slow test /GObject/threaded-weak-ref executed in 10.42 secs
  # slow test /thread/rerun-all executed in 9.84 secs
  # slow test /gobject/refcount/object-advanced executed in 5.46 secs
  # slow test /thread/static-rw-lock executed in 5.00 secs
  # slow test /gobject/refcount/signals executed in 5.00 secs
  # slow test /gobject/refcount/signals executed in 5.00 secs

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-06-01 11:29:46 +01:00
Daniel P. Berrangé
b6ce20329a gtestutils: use an enum for test case result fields
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-05-31 20:47:22 +01:00
Simon McVittie
0d86ee0a86 gstdio: Improve documentation of g_clear_fd() as async-signal safe
Add cross-references as requested for similar new API in !3457.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-05-31 16:34:16 +01:00
Simon McVittie
9af6b7e4e7 gstdio: Improve documentation of g_close() as async-signal safe
Add cross-references as requested for similar new API in !3457.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-05-31 16:34:14 +01:00
Philip Withnall
7a82da2992 Merge branch 'wip/smcv/steal-fd-preserves-errno' into 'main'
gmain: Document that g_steal_fd() preserves errno

See merge request GNOME/glib!3456
2023-05-31 14:34:33 +00:00
Emmanuele Bassi
6fc6d9ea3e Merge branch 'ebassi/keyfile-docs' into 'main'
docs: Use the type name as the section name for GKeyFile

See merge request GNOME/glib!3453
2023-05-31 01:05:34 +00:00
Simon McVittie
c97348428f gmain: Document that g_steal_fd() preserves errno
This is useful when writing similarly low-level code, and was always true
as implemented here; let's document it so that other codebases can rely
on it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-05-30 16:02:16 +01:00
Michael Catanzaro
d624c850b2 Add some tests for socks:// URI default ports
This also tests socks5h:// which we don't actually support yet, just to
make sure it works, which it does.
2023-05-30 09:55:39 -05:00
Michael Catanzaro
cc5bb80b9a Fix failure to respect default port of proxy URLs
Currently we require explicitly specifying the port when configuring a
proxy server, which is seriously weird. I take the fact that nobody
reported a bug until 2022 to indicate that almost nobody is using
proxies. Whatever. Let's assume that if no port is provided, the default
port for the protocol should be used instead.

For example, you can now specify in GNOME settings that your proxy server
is https://example.com and it will work. Previously, you had to write
https://example.com:443. Yuck!

This was originally reported as GProxyResolver bug, but nothing is
actually wrong there. It's actually GProxyAddressEnumerator that gets
tripped up by URLs returned by GProxyResolver without a default port.
This breaks GSocketClient.

Fixing this requires exposing GUri's _default_scheme_port() function to
GIO. I considered copy/pasting it since it's not very much code, but I
figure the private call mechanism is probably not too expensive, and I
don't like code duplication.

Fixes #2832
2023-05-30 09:49:43 -05:00
Michael Catanzaro
42cb8dfb95 guri: the default port for SOCKS URLs is 1080
This is true for socks://, socks4://, socks4a://, and socks5://. I could
list them individually and risk breaking in the future if socks6:// ever
exists, or test for "socks" and risk breaking if a future URL scheme
begins with "socks" but doesn't use port 1080. I picked the latter.
2023-05-30 09:49:43 -05:00
Philip Withnall
32ec11e51d Merge branch 'free-sized-macro' into 'main'
gmem: Add an inline definition of g_free() to automatically use g_free_sized()

See merge request GNOME/glib!3252
2023-05-30 13:29:25 +00:00
Philip Withnall
1aefcf4e0e Merge branch 'ok/termux-build-issues' into 'main'
gio, tests: adaptations for building with bionic libc from termux

Closes #3008

See merge request GNOME/glib!3443
2023-05-30 13:04:17 +00:00
Philip Withnall
c0bdc61879 meson: Export HAVE_FREE_SIZED in glibconfig.h for use in g_free()
This allows the `g_free()` wrapper introduced in the previous commit to
only be defined if `free_sized()` is actually available to improve
performance.

This avoids passing an allocation size to every `g_free()` call if it’s
not going to be used, saving a register store instruction each time.

Suggested by Marco Trevisan in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3252#note_1660032

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-30 13:45:05 +01:00
Marco Trevisan (Treviño)
c580b5c2f4 gmem: Add an inline definition of g_free() to automatically use g_free_sized()
When using GCC we can take the advantage of __builtin_object_size() to
know the allocated size of a memory area, this generally only works when
some optimization level enabled (-O1 seems enough here) and can provide
us with memory size information for lower-level optimizations.
2023-05-30 13:43:25 +01:00
Emmanuele Bassi
28e8f5c136 docs: Rename the GBookmarkFile section
Use the type name, to ensure that the section docblock gets merged into
the type docblock in the introspection data.

Helps: #2961
2023-05-30 13:33:45 +01:00
Philip Withnall
0196a36022 Merge branch 'more-atomic-exchange-full' into 'main'
gdataset, gobject: Use atomic compare and exchange full to set pointers

See merge request GNOME/glib!3426
2023-05-30 11:59:40 +00:00
Emmanuele Bassi
4386d912d7 docs: Use the type name as the section name for GKeyFile
Without this, the section docblock for GKeyFile disappears into the
ether when generating the introspection data.

Helps: #2961
2023-05-30 12:46:30 +01:00
Philip Withnall
153c7f7b99 Merge branch 'wip/p3732/truncate-middle' into 'main'
gutf8: Add a g_utf8_truncate_middle() function

See merge request GNOME/glib!3440
2023-05-30 11:02:03 +00:00
Peter Eisenmann
cd3837174b gutf8: Add a g_utf8_truncate_middle() function
Adds a helper to truncate UTF8 strings in the middle, allowing to make
them fit certain size constraints.

This function is modeled after similar functionality that has existed
since 2008 in nautilus and in eel before that.
2023-05-25 00:36:56 +02:00
Øyvind Kolås
9f7ed1fc37 glib/tests: evade bionic libc polyfills for getpwuid
This helps build glib's tests and thus glib under termux on android.

Fixes: #3008
2023-05-22 22:44:52 +02:00
Philip Withnall
109dc30581 tests: Add descriptions to environment tests
Prompted by !500.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2023-05-22 17:33:29 +01:00
Sebastian Dröge
dae7c2a706 gstring: Add Since marker to g_string_new_take() 2023-05-21 10:04:29 +03:00
Thomas Haller
3694dac983 gmain: ensure boolean value in g_child_watch_check() is strictly 0 or 1
No problem in practice, but it seems nice to ensure that a gboolean is
always either FALSE or TRUE.
2023-05-18 11:26:33 +02:00
Thomas Haller
d5d6ef8f1b gmain: drop redundant using_pidfd field from GChildWatchSource
It's redundant, which leads to impossible code like:

   if (child_watch_source->using_pidfd)
     {
       if (child_watch_source->poll.fd >= 0)
         close (child_watch_source->poll.fd);
2023-05-18 11:26:33 +02:00
Thomas Haller
cecbb25eeb gmain: fix race with waitpid() and child watcher sources
GChildWatchSource uses waitpid(), among pidfd and GetExitCodeProcess().
It thus only works for child processes which the user must ensure to
exist and not being reaped yet. Also, the user must not kill() the PID
after the child process is reaped and must not race kill() against
waitpid(). Also, the user must not call waitpid()/kill() after the child
process is reaped.

Previously, GChildWatchSource would call waitpid() already when adding
the source (g_child_watch_source_new()) and from the worker thread
(dispatch_unix_signals_unlocked()). That is racy:

- if a child watcher is attached and did not yet fire, you cannot call
  kill() on the PID without racing against the PID being reaped on the
  worker thread. That would then lead to ESRCH or even worse, killing
  the wrong process.

- if you g_source_destroy() the source that didn't fire yet, the user
  doesn't know whether the PID was reaped in the background. Any
  subsequent kill()/waitpid() may fail with ESRCH/ECHILD or even address
  the wrong process.

The race is most visible on Unix without pidfd support, because then the
process gets reaped on the worker thread or during g_child_watch_source_new().
But it's also with Windows and pidfd, because we would have waited for
the process in g_child_watch_check(), where other callbacks could fire
between reaping the process status and emitting the source's callback.

Fix all that by calling waitpid() right before dispatching the callback.
2023-05-18 11:26:33 +02:00
Thomas Haller
cdda194844 gmain: remove unnecessary initialization of *timeout in prepare() callbacks
Note that the prepare callback only has one caller, which pre-initializes
the timeout argument to -1. That may be an implementation detail and not
publicly promised, but it wouldn't make sense to do it any other way in
the caller.

Also, note that g_unix_signal_watch_prepare() and the UNIX branch of
g_child_watch_prepare() already relied on that.
2023-05-18 11:26:33 +02:00
Thomas Haller
30b5418608 gmain: remove unnecessary initialization of source_timeout in g_main_context_prepare_unlocked()
Note that the variable source_timeout is already initialized upon
definition, at the beginning of the block.

It's easy to see, that no code changes the variable between the variable
definition, and the place where it was initialized. It was thus
unnecessary.

It's not about dropping the unnecessary code (the compiler could do that
just fine too). It's that there is the other branch of the "if/else", where
the variable is also not initialized. But the other branch also requires
that the variable is in fact initialized to -1, because prepare()
callbacks are free not to explicitly set the output value. So both
branches require the variable to be initialized to -1, but only one of
them did. This poses unnecessary questions about whether anything is
wrong. Avoid that by dropping the redundant code.
2023-05-18 11:26:33 +02:00
Thomas Haller
a71b0c0461 gmain: simplify handling child watchers in dispatch_unix_signals_unlocked()
- if a child watch source has "using_pidfd", it is never linked in the
  unix_child_watches list. Drop that check.
- replace the deep nested if, with an early "continue" in the loop,
  if we detect there is nothing to do. It makes the code easier to
  read.
2023-05-18 11:26:33 +02:00
Thomas Haller
9315a211fa gmain: unify win/unix implementations for child watcher
Let's move the difference between the win/unix implementations closer to
where the difference is. Thereby, we easier see the two implementations
side by side. Splitting it at a higher layer makes the code harder to
read.

This is just a preparation for what comes next.
2023-05-18 11:26:33 +02:00
Thomas Haller
d1e558f492 gmain/tests: add unit test for g_child_watch_add() reaping processes without notifying
The test currently tests broken behavior. It will be fixed next.
2023-05-18 11:26:33 +02:00
Peter Eisenmann
ac4d1e2686 docs: unify "dynamic memory needed" explanations
All `_take` method constructors require dynamic memory, this unifies
theses explanation texts.
2023-05-16 11:27:45 +01:00
Peter Eisenmann
afdab4f493 gstring: add g_string_new_take
Adds a GString constructor that takes over ownership of an existing,
dynamically allocated, string.
2023-05-16 11:27:45 +01:00