8781 Commits

Author SHA1 Message Date
Philip Withnall
63e1e83c33 Merge branch 'wip/p3732/timeout-seconds-once' into 'main'
add g_timeout_add_seconds_once

See merge request GNOME/glib!3383
2023-05-09 12:50:39 +00:00
Philip Withnall
85af9b73c9 tests: Zero the rlimit in standalone tests which are expected to abort
This should hopefully stop the kernel spending a lot of memory and disk
bandwidth creating coredumps for them unnecessarily, which slows down
the rest of the tests and generally wastes resources.

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

Fixes: #2939
2023-05-02 12:53:13 +01:00
Peter Eisenmann
467b917719 gtimeout: use helper for seconds_full variant
Use timeout_add_full() helper to deduplicate code
2023-05-02 13:42:54 +02:00
Peter Eisenmann
3abf23b2a7 add g_timeout_add_seconds_once
Add a new call combing behaviors of g_timeout_add_seconds and
g_timeout_add_once.
2023-05-02 13:42:54 +02:00
Philip Withnall
e8c1bdbf4f tests: Add copyright/licensing header to assert-msg-test
This is put together through git archaeology:
```
git log -- glib/tests/assert-msg-test.c tests/assert-msg-test.c
```

The following commits were too trivial to have meaningful copyright:
 - 8e59d8602ca5921d78245f5d2b405b517a5e7cf9
 - 44c004c84e9080040ff4e0e90b322dda0561cf85
 - 207b8cb8a50d68e207d28b59e588311a5cbd9772
 - a1bee97d4f093db01dee834bf3292eabd5b13d17

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

Helps: #1415
2023-05-02 11:03:49 +01:00
Philip Withnall
a1bee97d4f tests: Reformat assert-msg-test.c to follow coding style
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-02 11:03:00 +01:00
Arnaud Rebillout
d6faa002a5 gtestutils: Fix section marker in documentation
Apparently 3 hashes is too many, and as a result this line is not
displayed properly in the HTML documentation. 2 hashes seems to be
just right, as can be seen with:

  $ git grep '^ \* ##' | wc -l
  65
  $ git grep '^ \* ###' | wc -l
  1
2023-05-02 13:21:17 +07:00
Philip Withnall
e7398198c5 gthreadpool: Document that g_thread_pool_new() will spawn a thread
Otherwise it might look like it would only start spawning threads when
jobs are enqueued.

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

Helps: #2958
2023-04-28 10:52:22 +01:00
Philip Withnall
7adca698d8 gthreadpool: Clarify that item_free_func is not normally called
If you’re only quickly looking at the API signature, it looks like
`item_free_func` will be called for all items enqueued to the thread
pool.

As it happens, it’s actually only called for the items which are still
enqueued when the thread pool is destroyed. The user’s `GFunc` is
responsible for freeing items which are successfully dequeued and
processed during the lifetime of the thread pool.

That’s a bit of a gotcha, so document it more explicitly.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-27 15:48:07 +01:00
Marco Trevisan
59a2235e9d Merge branch '98-current-path' into 'main'
gfileutils: Fix potential integer overflow in g_get_current_dir()

Closes #98

See merge request GNOME/glib!3375
2023-04-27 09:18:07 +00:00
Philip Withnall
73bf66dd2a Merge branch 'unix-fd-source-docs' into 'main'
glib-unix: Improve documentation for g_unix_fd_source_new()

See merge request GNOME/glib!3396
2023-04-26 16:11:42 +00:00
Peter Kjellerstedt
edd1e47f10 Avoid having g_futex_simple() inadvertently modify errno
If both __NR_futex and __NR_futex_time64 are defined, g_futex_simple()
will first call futex_time64(). If that fails with ENOSYS, then
futex_time() is called instead. However, errno was not saved and
restored in this case, which would result in g_futex_simple()
returning with errno set to ENOSYS, even if futex_time() succeeded.
2023-04-26 02:08:46 +02:00
Philip Withnall
df9d3818ac glib-unix: Improve documentation for g_unix_fd_source_new()
In particular, document the type of the callback function.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-25 15:30:45 +01:00
Philip Withnall
c176fcf2eb Merge branch 'doc-indentation' into 'main'
Fix small issues in docs

See merge request GNOME/glib!3393
2023-04-24 12:58:08 +00:00
Philip Withnall
d3e7b9e17c Merge branch 'context-checks' into 'main'
gmain: More explicitly document g_main_context_release() prereqs

See merge request GNOME/glib!3314
2023-04-24 12:52:51 +00:00
Philip Withnall
3926af723a gmain: Add precondition assertions to g_main_context_release()
As with the previous commit.

The logic has to be a little contorted here to avoid leaving the context
locked after emitting the critical warning. Execution does (and should)
continue after a critical warning by default, so we should do our best
to recover.

Inspired by https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3302.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-24 13:02:36 +01:00
Philip Withnall
44616ebafd gmain: More explicitly document g_main_context_release() prereqs
The documentation was fairly clear before, but we can make it clearer:
it’s a programming error to call `g_main_context_release()` if you have
not received a true return value from `g_main_context_acquire()` before.

Inspired by https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3302.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-24 12:49:23 +01:00
Emmanuele Bassi
e2e93056f2 Add init macros for refcounting types
We need a way to initialise refcounted types placed in static storage,
or on the stack. Using proper macros avoids knowing the magic constant
used for grefcount and gatomicrefcount.
2023-04-24 12:48:32 +01:00
Arjan Molenaar
84d8d5647e
Fix small issues in docs
This will make converting the docs to another format
(say, rst) somewhat easier.
2023-04-24 13:18:33 +02:00
Philip Withnall
28b1b9d9c3 Merge branch 'gmain-less-locks' into 'main'
gmain: Avoid some lock/unlock dance during g_main_context_iterate

See merge request GNOME/glib!3235
2023-04-24 10:29:41 +00:00
Philip Withnall
cba49eb6a1 Merge branch 'mutex-tests-more' into 'main'
glib/tests/[rec-]mutex: Allow each thread to work

See merge request GNOME/glib!3389
2023-04-24 10:25:05 +00:00
Arnaud Rebillout
edb85b99f6 gvariant: Fix doc for g_variant_new_object_path
The parameter is named 'object_path', not 'string'.
2023-04-21 21:56:50 +07:00
Marco Trevisan (Treviño)
3aeef671d0 glib/tests/[rec-]mutex: Allow each thread to work
In non-perf mode, we were making only one thread to win the race to increase
the value, but since we're launching more threads anyways let's allow
more of them to have a chance to do something, to make the test more
valuable, even if it's still quick enough.
2023-04-20 17:01:05 +02:00
Gaël Bonithon
86b4b0453e gkeyfile: Fix group comment management
This removes the `comment` member of the GKeyFileGroup structure, which
seemed intended to distinguish comments just above a group from comments
above them, separated by one or more blank lines. Indeed:
* This does not seem to match any specification in the documentation,
  where blank lines and lines starting with `#` are indiscriminately
  considered comments. In particular, no distinction is made between the
  comment above the first group and the comment at the beginning of the
  file.
* This distinction was only half implemented, resulting in confusion
  between comment above a group and comment at the end of the preceding
  group.

Instead, the same logic is used for groups as for keys: the comment
above a group is simply the sequence of key-value pairs of the preceding
group where the key is null, starting from the bottom.

The addition of a blank line above groups when writing, involved in
bugs #104 and #2927, is kept, but:
* It is now added as a comment as soon as the group is added (since a
  blank line is considered a comment), so that
  `g_key_file_get_comment()` returns the correct result right away.
* It is always added if comments are not kept.
* Otherwise it is only added if the group is newly created (not present
  in the original data), in order to really keep comments (existing and
  not existing).

Closes: #104, #2927
2023-04-20 16:59:04 +02:00
Gaël Bonithon
f74589f530 gkeyfile: Replace g_slice_*() with g_new*()/g_free_sized() 2023-04-20 16:52:19 +02:00
Marco Trevisan (Treviño)
164f199afc gmacros: Do not redefine NULL on C++
Even though having NULL as nullptr should be the standard for newer C++
versions, it may break some headers, so let's not touch it for now.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/2973
2023-04-19 23:03:43 +02:00
Marco Trevisan (Treviño)
7d5242d34e gmain: Do not dead-look if calling g_main_loop_run from a GSource
This should fail and warn but not leaving the context acquired and
locked.

Add tests.
2023-04-19 22:52:43 +02:00
Marco Trevisan (Treviño)
f8e440335c gmain: Avoid locking dance in g_main_loop_run()
We do it during initialization, this may be if necessary handled by GCond in
case we need to acquire the lock.
2023-04-19 22:04:13 +02:00
Marco Trevisan (Treviño)
e7c2ead41b gmain: Avoid some lock/unlock dance during g_main_context_iterate
A context iteration we're doing lots of lock/unlocks and that's fine to give
other threads contexts a chance to run, but we're doing it also just to call
other functions that require locking, and this can be avoided.

Other threads can still have a chance to run while releasing the ownership
of the context.
2023-04-19 21:58:22 +02:00
Marco Trevisan
9f111c3416 Merge branch 'valgrind-variable' into 'main'
meson: Add glib_valgrind_suppressions variable to glib pkg-config file

See merge request GNOME/glib!3361
2023-04-17 12:52:28 +00:00
Marco Trevisan (Treviño)
c2e46b3789 meson: cleanup pkg-config variables definitions
Use more readable and shorter syntax
2023-04-17 14:25:52 +02:00
Marco Trevisan (Treviño)
ade79bcb50 meson: Add tests for generated pkg-config files
Ensure things are generated as we expect and avoid we regress on that.
2023-04-17 14:25:52 +02:00
Philip Withnall
7c1ef5c9ec Merge branch 'no-usleep-on-0' into 'main'
gtimer: Avoid doing anything on g_usleep (0)

See merge request GNOME/glib!3381
2023-04-17 11:44:36 +00:00
Marco Trevisan (Treviño)
732e40dcfa gtimer: Avoid doing anything on g_usleep (0)
It's unlikely to happen, but still could be the case, so avoid do
anything.
2023-04-14 20:24:52 +02:00
Philip Withnall
7a5d4c2bb7 gfileutils: Fix potential integer overflow in g_get_current_dir()
In practice, this will never happen.

If `getcwd()` returns `ERANGE` whenever the working directory is ≥
`PATH_MAX`, though, the previous implementation of the loop would run
until `max_len == G_MAXULONG`, and would then overflow when adding `1`
to it for a nul terminator in the allocation.

Avoid that problem by always keeping `buffer_len` as a power of two, and
relying on `getcwd()` to write a nul terminator within the buffer space
it’s given. It seems to do this on all platforms we care about, because
the previous version of the code never explicitly wrote a nul terminator
anywhere.

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

Fixes: #98
2023-04-14 19:23:20 +01:00
Marco Trevisan (Treviño)
fcad56e313 meson: Add glib_valgrind_suppressions variable to glib pkg-config file
Various projects are running tests under valgrind, and they are using
the GLib suppresions to avoid false-positive results.

While this is stored in a well-known path for some years, and easy to
figure out from the GLib prefix, it's better to expose it through a
proper pkgconfig variable so that it's easy to get it from any build
system.
2023-04-14 19:20:51 +02:00
Philip Withnall
9d2f65576f Merge branch 'work-around-ucrt-spawn-env-issue' into 'main'
Work around an UCRT issue with _wspawn() functions taking an envp block

See merge request GNOME/glib!3289
2023-04-14 17:06:32 +00:00
Philip Withnall
d46405029c Merge branch 'ghash-gvariant-cheri-layout' into 'main'
Make GVariant/GHash opaque types compatible with CHERI

See merge request GNOME/glib!3146
2023-04-14 17:02:54 +00:00
Luca Bacci
5d1046d3b2 Add test for UCRT issue workaround 2023-04-14 17:15:28 +01:00
Luca Bacci
911d091866 Work around an UCRT issue with _wspawn() functions taking an environment block argument
We were working around that with a call to chdir("."). Internally chdir()
sets up cmd shell-related environment variables, but only if the current
working directory belongs to a volume with a drive letter. For example,
if the current working directory is on a UNC volume like a network share,
the call to chdir() won't help.

Reference:
  https://developercommunity.visualstudio.com/t/UCRT-Crash-in-_wspawne-functions/10262748
2023-04-14 17:15:28 +01:00
Philip Withnall
353f2e4b3c Merge branch 'normalize-utf8-bounds-checking' into 'main'
g_utf8_normalize: don't read past the end of the buffer

See merge request GNOME/glib!3341
2023-04-14 16:14:54 +00:00
Philip Withnall
3f390d5598 Merge branch '2307-mainloop-test-asan' into 'main'
tests: Re-enable mainloop test under AddressSanitizer

Closes #2307

See merge request GNOME/glib!3329
2023-04-14 15:55:06 +00:00
Todd Carson
c82f9adb19 Test g_utf8_normalize() handling of invalid UTF-8 inputs
Add three classes of test case for which g_utf8_normalize() should
safely return NULL:
 - Strings ending with a truncated multibyte character which would
   extend past the NUL terminator
 - Strings ending with a multibyte character which extends past the
   length limit provided by the max_len argument
 - Strings containing an invalid multibyte character in any position
2023-04-14 16:52:16 +01:00
Todd Carson
7f4726d151 g_utf8_normalize: don't read past the end of the buffer
_g_utf8_normalize_wc() could read past the end of the provided buffer if
it ends with a truncated multibyte character. If max_len is -1, it can
continue reading until it encounters either a NUL or unreadable
memory. Avoid this with extra bounds checks prior to g_utf8_get_char()
to ensure that it does not read past either max_len or a NUL
terminator.
2023-04-14 16:52:10 +01:00
Philip Withnall
088e2a4f5a Merge branch 'socket-nonblock' into 'main'
gsocket/inotify/gwakeup: Use SOCK_NONBLOCK and O_NONBLOCK to avoid fcntl() syscalls where possible

See merge request GNOME/glib!3347
2023-04-14 15:49:52 +00:00
Philip Withnall
17295bd0b0 Merge branch 'move-msvc-recommended-pragmas' into 'main'
meson: Move msvc_recommended_pragmas.h to a subdirectory

See merge request GNOME/glib!3340
2023-04-14 15:49:21 +00:00
Emmanuele Bassi
2f828ef2d4 Merge branch '95-markup-docs' into 'main'
docs: Add simple GMarkup parser example

Closes #95

See merge request GNOME/glib!3364
2023-04-13 21:37:41 +00:00
Emmanuele Bassi
2af45f9c20 Merge branch 'libicu-tests' into 'main'
unicode: add tests for g_utf8_normalize() and empty strings

See merge request GNOME/glib!3326
2023-04-13 21:35:51 +00:00
Emmanuele Bassi
2972cb61f5 Merge branch 'update-unicode-normalisation-tests' into 'main'
tests: Update Unicode normalisation tests from Unicode 15

See merge request GNOME/glib!3351
2023-04-13 21:33:23 +00:00
Emmanuele Bassi
28209912ef Merge branch '2969-date-time-format-docs' into 'main'
gdatetime: Improve Markdown formatting of g_date_time_format() docs

Closes #2969

See merge request GNOME/glib!3362
2023-04-13 21:32:57 +00:00