8781 Commits

Author SHA1 Message Date
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 44616ebafdca ('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 3926af723a74 ('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 e26a8a59813c ('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: 3926af723a74 ('gmain: Add precondition assertions to g_main_context_release()')
Related: c67dd9d3fe91 ('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 252bbcd2078aadc67a49bacd5b2cd4fd348a8dd7.

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
3926af723a7469a2ea492307f421820361d617b3.

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: 86b4b0453ea3a814167d4a5f7a4031d467543716
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: 86b4b0453ea3a814167d4a5f7a4031d467543716
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