8386 Commits

Author SHA1 Message Date
Philip Withnall
8b1e8ecb54 goption: Slightly improve the documentation for G_OPTION_FLAG_REVERSE
None of the documentation actually mentioned booleans, which would be a
useful keyword to include for context.

Inspired by https://stackoverflow.com/questions/72958500/what-is-the-sense-of-a-command-line-option

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-07-13 15:58:24 +01:00
Owen Rafferty
871e570867
gmain: define non-posix symbols 2022-07-12 20:03:56 -05:00
Marco Trevisan (Treviño)
f0e98a1923 gstdio: Do not pass wrong pointer types to FILETIME to unix conversion 2022-07-12 15:55:59 +02:00
Marco Trevisan (Treviño)
39ecb71452 gthread-posix: Do not do unguarded and non-atomic assignment of an atomic
We ended up always skipping showing the scheduler settings errors after
the first call, while we were already setting such variable atomically
in case it needed to.

Related to: #1672
2022-07-12 14:30:20 +02:00
Philip Withnall
cd9a5c173a Merge branch 'rybalkin-pcre2' into 'main'
replace pcre1 with pcre2

Closes #1085

See merge request GNOME/glib!2529
2022-07-12 11:46:35 +00:00
Aleksei Rybalkin
8d5a44dc8f replace pcre1 with pcre2 2022-07-12 11:46:34 +00:00
Marco Trevisan (Treviño)
a275ee6679 gthreadpool: Update unused_threads while we still own the pool lock
As per the rationale explained in the previous commit, we could end up
having the unused_threads value not to be conformant to what
g_thread_pool_get_num_threads() returns, because an about-to-be-unused
thread might not be counted yet as such, while the pool threads number
has been already decreased.

To avoid such scenario, and to make sure that when all the pool's
threads are stopped, they're unmarked as unused, let's increase the
unused_threads value earlier, while we still own the pool lock so that
it will always include the pool that is not used anymore, but not yet
queued.

As per this we can update the test, not to repeat the stop-unused call
as now we're sure that when the pool has no threads anymore, the unused
threads value is also updated accordingly.

Also adding a tests with multiple pools.
2022-07-11 19:56:26 +02:00
Marco Trevisan (Treviño)
fabdc2d4fa glib/test/thread-pool-slow: Ensure all unused threads are really stopped
In this tests we wanted to ensure that all the unused threads were
stopped, however while we were calling g_thread_pool_stop_unused_threads
some threads could still be in the process of being recycled even tough
the pool's num_thread values are 0.

In fact, stopping unused threads implies also resetting back the max
unused threads to the previous value, and in this test it caused it to
go from -1 -> 0 and back to -1, after killing the unused threads we
knew about; thus any about-to-be-unused thread that is not killed during
this call will be just left around as a waiting unused thread afterwards.

However, if this function was getting called when a thread was in
between of calling the user function and the moment it was being
recycled (and so when the pool num_threads was updated), but this thread
was not counted in unused_threads, we ended up in having a race because
all the threads were consumed from our POV, but some were actually not
yet unused, and so were kept waiting forever for some new job.

To avoid this in the test, we can ensure that we stop the unused
threads until we the number of them is really 0.

Sadly we need to repeat this as we don't have a clear point in which we
are sure about the fact that our threads are done, while it would be
wrong to stop a thread that is technically not yet marked as unused.

We could also do this in g_thread_pool_stop_unused_threads() itself, but
it would make such function to wait for threads to complete, and this is
probably not what was expected in the initial API.

Fixes: #2685
2022-07-11 19:56:26 +02:00
Marco Trevisan (Treviño)
a5ccaa0525 glib/tests/thread-pool-slow: Fix indentation in test_thread_stop_unused
It used three-spaces indentation instead of 2, fix it.
2022-07-11 19:56:26 +02:00
Emmanuele Bassi
043f3dcf11 Merge branch 'wip/pwithnall/2216-pidfd-sigchld' into 'main'
gmain: Use waitid() on pidfds rather than a global SIGCHLD handler

Closes #2216

See merge request GNOME/glib!2408
2022-07-08 14:10:13 +00:00
Philip Withnall
f615eef4ba gmain: Use waitid() on pidfds rather than a global SIGCHLD handler
When the system supports it (as all Linux kernels ≥ 5.3 should), it’s
preferable to use `pidfd_open()` and `waitid()` to be notified of
child processes exiting or being signalled, rather than installing a
default `SIGCHLD` handler.

A default `SIGCHLD` handler is global, and can never interact well with
other code (from the application or other libraries) which also wants to
install a `SIGCHLD` handler.

This use of `pidfd_open()` is racy (the PID may be reused between
`g_child_watch_source_new()` being called and `pidfd_open()` being
called), so it doesn’t improve behaviour there. For that, we’d need
continuous use of pidfds throughout GLib, from fork/spawn time until
here. See #1866 for that.

The use of `waitid()` to get the process exit status could be expanded
in future to also work for stopped or continued processes (as per #175)
by adding `WSTOPPED | WCONTINUED` into the flags. That’s a behaviour
change which is outside the strict scope of adding pidfd support,
though.

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

Helps: #1866
Fixes: #2216
2022-07-07 14:08:29 +01:00
Philip Withnall
a7efce14e0 Merge branch 'issue-2659' into 'main'
Fix  /maincontext/timeout-once randomly fails

Closes #2659

See merge request GNOME/glib!2780
2022-07-07 12:34:45 +00:00
Philip Withnall
7b93693ab3 gmain: Add a clarifying comment about exit statuses vs wait statuses
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2216
2022-07-07 13:05:18 +01:00
Marc-André Lureau
1a29fd4308 tests/mainloop: iterate for a little while for timeout-once
On win32, WaitForSingleObject may return before the timeout is
dispatched, as it doesn't have a resolution higher than the system tick.
Wait for ~50ms before checking the callback changes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-07 15:52:25 +04:00
Marc-André Lureau
17ac6642c7 gmain: do not wakeup the wakeup registration
Do not wakeup immediately for our own context wakeup poll registration.

g_main_context_add_poll_unlocked() will call g_wakeup_signal() to wake
up the loop waiting in poll(). Doing so during context creation will
create an extra wakeup for the first poll().

Skip the wakeup call if it is the wake_up_rec registration. No other
sources/caller should ever reach that condition.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-07 15:52:25 +04:00
Philip Withnall
ed564b71dd Merge branch '2672-dataset-tests-and-fixes' into 'main'
gdataset: Preserve destruction order

Closes #2672 and #2676

See merge request GNOME/glib!2776
2022-07-07 11:52:19 +00:00
Marc-André Lureau
a43723ef17 tests/spawn-singlethread: fix test EOL on win32
The "arg" argument is given in \n-ending form, but the returned result
is \r\n-ending.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-07 15:35:28 +04:00
Marco Trevisan (Treviño)
d21d213d00 gstrfuncs: Update docs for g_strerror with a string closer to reality 2022-07-07 00:42:45 +02:00
Marco Trevisan (Treviño)
edd718ba48 gstrfuncs: Handle the case strerror_r returns an error
In the case strerror_r returns an error (both in the char* variant and
in the int variant) we should not try to proceed converting the message
and adding to the errors maps, as that's likely causing errors.

So, let's just return a null string in case this happens
2022-07-07 00:42:45 +02:00
Marco Trevisan (Treviño)
640e586251 gbacktrace: Handle case of strerror_r returning an int value
As it's the case in FreeBSD and Mac OS X.
2022-07-07 00:42:45 +02:00
Marco Trevisan (Treviño)
8c5dac1eb2 glib/tests/fileutils: use g_assert_no_errno instead of manual checking 2022-07-06 18:41:10 +02:00
Marco Trevisan (Treviño)
7a382438aa glib/tests: Ensure that calls to write, system, symlink and pipe are checked
Assert that calls to such system calls are returning the expected values
2022-07-06 18:41:10 +02:00
Marco Trevisan (Treviño)
0e4d8c2478 gbacktrace: Ensure return values of write, dup and fgets are used
Make sure that we did not error when doing write or read operations, and
in such case, just exit reporting the error.
2022-07-06 16:02:13 +02:00
Philip Withnall
8385f52db7 Merge branch 'inline-macros' into 'main'
gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINE

See merge request GNOME/glib!2781
2022-07-06 13:40:10 +00:00
Marco Trevisan (Treviño)
e59ac0bc2d gthread-posix: Use G_NO_INLINE instead of actual attribute
Even if this is gcc/clang-only code, it's just better to use the generic
macros we now have.
2022-07-06 14:57:06 +02:00
Marco Trevisan (Treviño)
a6f8fe071e cleanup: Replace G_GNUC_NO_INLINE with G_NO_INLINE
As per this we can also now mark G_GNUC_NO_INLINE as
GLIB_AVAILABLE_MACRO_IN_2_58, given that we don't have anymore headers
using it.
2022-07-06 14:57:06 +02:00
Marco Trevisan (Treviño)
15cd0f0461 gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINE
We had gcc-only implementations for them while both can be used in all
the supported platforms we have.

So let's just provide generic definitions, while we keep the old ones
for both consistency and retro-compatibility.
2022-07-06 14:57:06 +02:00
Marco Trevisan
5764e3944d Merge branch 'key-file-dead-code' into 'main'
gkeyfile: Remove some unreachable code

See merge request GNOME/glib!2795
2022-07-06 11:06:46 +00:00
Philip Withnall
41691cc4c8 Merge branch 'more-spdx' into 'main'
Add more SPDX license headers

See merge request GNOME/glib!2706
2022-07-05 11:06:49 +00:00
Philip Withnall
3c69cd369f gkeyfile: Remove some unreachable code
There’s a precondition assertion on the function which checks that
`group_name != NULL`.

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

Coverity CID: #1474780
2022-07-05 10:41:49 +01:00
Philip Withnall
c530debb62 tests: Shorten another sleep/retry loop in thread-pool-slow
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-30 14:42:37 +01:00
Philip Withnall
afc0883652 test: Potentially fix a race in thread-pool-slow test
It’s failed on a CI machine
(https://gitlab.gnome.org/GNOME/glib/-/jobs/2006694) with log:
```
[unused] => pushed 100 threads onto the idle pool
[unused] stopping unused threads
[unused] waiting ONE second for threads to die
[unused] waiting ONE second for threads to die
[unused] waiting ONE second for threads to die
[unused] waiting ONE second for threads to die
[unused] waiting ONE second for threads to die
[unused] stopped idle threads, 9 remain
Bail out! GLib:ERROR:../glib/tests/thread-pool-slow.c:113:test_thread_stop_unused: assertion failed (g_thread_pool_get_num_unused_threads () == 0): (9 == 0)
```

I can’t reproduce this locally, but it’s possible that it failed because
a one second wait was not enough to enqueue all the jobs (on a heavily
loaded machine), and hence some jobs spawned thread pool threads after
calling `g_thread_pool_stop_unused_threads()`, leading to the assertion
failure.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-30 14:41:36 +01:00
Emmanuele Bassi
2a12de5b1d Require C99's __VA_ARGS__
We have fallback in places for GNU's variadic arguments in macros, and
for static inline functions with variadic arguments as an fallback of
last resort, but going forward we are going to depend on `__VA_ARGS__`
for macros that cannot be re-implemented using a static inline function.

Fixes: #2681
2022-06-30 01:46:32 +01:00
Emmanuele Bassi
d2c715d7a8 Merge branch 'why-are-the-tests-always-breaking' into 'main'
tests: Skip assert-msg-test.py if gdb is non-functional

See merge request GNOME/glib!2790
2022-06-29 14:49:08 +00:00
Philip Withnall
466a080c45 Merge branch 'typos' into 'main'
gdate: Fix a typo in a code comment

See merge request GNOME/glib!2789
2022-06-29 14:28:51 +00:00
Philip Withnall
6e44151bf7 tests: Skip assert-msg-test.py if gdb is non-functional
Some of the CI runners disable ptrace, as they’re running inside a
container and ptrace would allow container escape. On those systems, gdb
can’t work, so skip the gdb test.

Add some additional stderr debug output to make it clear that’s the
case.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-29 15:07:20 +01:00
Michael Vetter
162df3a6fa gdate: Fix a typo in a code comment 2022-06-29 16:05:09 +02:00
Emmanuel Fleury
207b8cb8a5 Convert tests/assert-msg-test* to glib/tests/assert-msg-test*
Closes issue #1434
2022-06-28 11:19:21 +01:00
Peter Bloomfield
8a43ae71c8 dataset: Document some logic
Add comments to clarify how the 'old' array is allocated and used.
2022-06-27 17:53:25 -04:00
Peter Bloomfield
8bd63258a5 dataset: Improve readability
Improve the readability by using a temporary variable
2022-06-27 17:42:11 -04:00
Simon McVittie
6a599e0349 gdatetime test: Consistently expect %k to generate a figure space
This part of test_non_utf8_printf() was missed while converting other
test expectations to look for a figure space, probably because it is
only run if a legacy ja_JP.eucjp locale exists. Debian generates a fairly
comprehensive set of locales (including some that are non-UTF-8) while
running GLib's installed-tests, so this was caught by CI.

Fixes: 7074122 "gdatetime: Pad numbers with numeric space"
Signed-off-by: Simon McVittie <smcv@debian.org>
2022-06-27 09:29:35 +01:00
Peter Bloomfield
e95a6bdd7d glib/tests/dataset: Use existing code
`destroy_index` duplicates `destroy_count`, and `foreach_func()`
essentially duplicates `notify()`.
2022-06-23 21:08:41 -04:00
Peter Bloomfield
a437a97ffd dataset: Rename i as destroy_index and move it out of destroy_func(), so that it can be checked to confirm that destroy_func() was called three times. 2022-06-23 22:17:13 +00:00
Peter Bloomfield
42826576a8 glib/tests/dataset: Test id_remove_multiple
Test that destroy-funcs are called in the order that the keys are
specified, not the order that they are found in the datalist.

Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2672
2022-06-23 17:41:55 -04:00
Peter Bloomfield
a4fa456e67 gdataset: Preserve destruction order
In `g_data_remove_internal()`, call the `GDataElt:destroy` functions in the
order that they appear in `keys`, instead of the order that they are found in
`datalist`.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2672
2022-06-23 17:41:55 -04:00
Peter Bloomfield
ac113c1ed2 In test_datalist_id_remove_multiple(), verify that the data list contains 3 items before calling g_datalist_id_remove_multiple(). 2022-06-23 17:41:55 -04:00
Peter Bloomfield
ad0f7199f1 glib/tests/dataset: Add a test
Test that `g_datalist_id_remove_multiple()` removes all the keys it is given.

Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2672
2022-06-23 17:41:55 -04:00
Peter Bloomfield
8c4598aab3 dataset: Do not increment
Do not increment the `data` pointer when it points to an item that has
not been inspected.

Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2672
2022-06-23 17:41:55 -04:00
Philip Withnall
ac898b8e67 Merge branch 'fix-macos-again' into 'main'
tests: Fix type mismatches in new atomic tests when compiling with clang

See merge request GNOME/glib!2774
2022-06-23 18:44:13 +00:00
Marco Trevisan (Treviño)
00f3f0d407 gthread: Use atomic pointer exchange to check value set on g_init_leave 2022-06-23 20:01:12 +02:00