8386 Commits

Author SHA1 Message Date
Cédric Bellegarde
cf5d807881 docs: Fix return type in cmpint example 2023-01-10 11:31:25 +00:00
badcel
fc70f2c057
Do not name callback parameters "user_data"
Calling a callback parameter "user_data" implicitly adds the "closure" attribute in the documentation which is wrong for callbacks.
2023-01-09 14:12:16 +01:00
badcel
b24f6ca27d
Revert "Rename all user datas in callbacks to user_data"
This reverts commit 1422e5f81241650c634413911e92d23495692545. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
2023-01-09 13:23:32 +01:00
badcel
19a02d7d14
Revert "Rename user data parameters to user_data"
This reverts commit da7a31a052614edd2cc87518585ff371cbb0f204. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
2023-01-09 13:09:26 +01:00
Emmanuele Bassi
684d9aa0c3 build: Don't overwrite build variables
We cannot use `gvisibility_h` for different visibility header files; you
never know when you're going to refer to the variable again, and
projects might end up needing to retrieve the variable contents—like,
for instance, gobject-introspection using glib as a subproject.
2023-01-08 00:33:14 +00:00
Emmanuele Bassi
206cbf47a5 Merge branch '2871-find-program-for-path-leak' into 'main'
gutils: Avoid possible leaks in g_find_program_for_path()

Closes #2871

See merge request GNOME/glib!3183
2023-01-06 12:33:08 +00:00
Philip Withnall
73fa684e30 Merge branch 'ptr-array-sort-values' into 'main'
garray: Add g_ptr_array_sort_values[_with_data]() wrappers

See merge request GNOME/glib!3155
2023-01-06 12:09:37 +00:00
Marco Trevisan (Treviño)
0ffd23cac4 garray: Add g_ptr_array_sort_values[_with_data]() wrappers
Historically GPtrArray made possible to compare pointers of pointers values
that it holds, however this is inconvenient in most cases as it requires
wrapper functions and not friendly castings.

So, add two functions that allow to perform the comparisons between the
pointer values that a GPtrArray holds following the same syntax that we
share everywhere in the codebase.
2023-01-06 11:46:01 +00:00
Philip Withnall
db2381026f gutils: Avoid possible leaks in g_find_program_for_path()
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2871
2023-01-05 17:13:35 +00:00
Peter Bloomfield
49ec4d524f gstrfuncs: Fix grammar in documentation of stpcpy
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2857
2023-01-02 13:27:26 -05:00
Philip Withnall
b65e50cff5 gvariant: Factor out some common calls to g_variant_get_type_string()
When printing a `GVariant`.

This introduces no functional changes, but should speed things up a
little bit when printing out arrays.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-29 17:38:04 +00:00
Philip Withnall
41b6de661d garray: Add some additional length assertions
This should shut Coverity up.

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

Coverity CID: #1502194
2022-12-29 16:09:20 +00:00
Philip Withnall
21a204147b gvariant: Propagate trust when getting a child of a serialised variant
If a variant is trusted, that means all its children are trusted, so
ensure that their checked offsets are set as such.

This allows a lot of the offset table checks to be avoided when getting
children from trusted serialised tuples, which speeds things up.

No unit test is included because this is just a performance fix. If
there are other slownesses, or regressions, in serialised `GVariant`
performance, the fuzzing setup will catch them like it did this one.

This change does reduce the time to run the oss-fuzz reproducer from 80s
to about 0.7s on my machine.

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

Fixes: #2841
oss-fuzz#54314
2022-12-21 19:50:26 +00:00
Philip Withnall
78da5faccb gvariant: Check offset table doesn’t fall outside variant bounds
When dereferencing the first entry in the offset table for a tuple,
check that it doesn’t fall outside the bounds of the variant first.

This prevents an out-of-bounds read from some non-normal tuples.

This bug was introduced in commit 73d0aa81c2575a5c9ae77d.

Includes a unit test, although the test will likely only catch the
original bug if run with asan enabled.

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

Fixes: #2840
oss-fuzz#54302
2022-12-21 19:50:19 +00:00
Philip Withnall
5e378c775a Merge branch 'ptr-array-new-take' into 'main'
garray: Add more G(Ptr)Array constructors to take or copy C arrays

See merge request GNOME/glib!3128
2022-12-21 18:34:13 +00:00
Philip Withnall
379a982391 gmain: Define fallback values for siginfo_t constants for musl
musl doesn’t define them itself, presumably because they’re not defined
in POSIX. glibc does define them. Thankfully, the values used in glibc
match the values used internally in other musl macros.

Define the values as a fallback. As a result of this, we can get rid of
the `g_assert_if_reached()` checks in `siginfo_t_to_wait_status()`.

This should fix catching signals from a subprocess when built against
musl.

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

Fixes: #2852
2022-12-21 12:11:46 +00:00
Marco Trevisan (Treviño)
94c45f8fa2 garray: Fix a doc typo in g_ptr_array_sort() 2022-12-21 11:40:48 +00:00
Marco Trevisan (Treviño)
b15040215a garray: Add g_array_new_take() and g_array_new_take_zero_terminated()
Make it easy to handle C arrays using GArray API stealing data from other
sources.
2022-12-21 11:40:39 +00:00
Philip Withnall
6034f35e34 Merge branch '2753-vasprintf-loop' into 'main'
glib/tests: Add test to check that we abort on low-memory

See merge request GNOME/glib!2992
2022-12-21 11:10:54 +00:00
Michael Catanzaro
03cb4261e0 gthread-posix: need to #include <errno.h>
a79c6af23eff5ee978db62e048828c9a992a1261 uses errno without the required
header.
2022-12-20 17:11:29 -06:00
Marco Trevisan (Treviño)
6fcecc86ac glib/tests: Add test to check that we abort on low-memory
In case we're out of memory we should abort after having printed an error
message, this is similar to crashing but not exactly the same, so ensure
we exit for SIGABRT and not because of a SIGSEV.

We use a test wrapper to ensure that both the exit code and the stderr
match what we expected.
2022-12-20 01:16:55 +01:00
Marco Trevisan
38e01b03b6 Merge branch 'tests-isolated-tmpdir' into 'main'
gtestutils: Use $G_TEST_TMPDIR as temporary directory when defined

See merge request GNOME/glib!2886
2022-12-19 21:32:56 +00:00
Marco Trevisan (Treviño)
ca0f04d1c6 gtestutils: Use $G_TEST_TMPDIR as temporary directory when defined
During tests in which we are isolating directories, we may still create
temporary files in the global temporary directory without cleaning them
because the value returned by g_get_tmp_dir() is cached when we isolate
the tests directory to the global TMPDIR.

To ensure that we're always isolating the temporary directories, let's
unset the cached temporary directory once we've defined $G_TEST_TMPDIR
so that the returned value of g_get_tmpdir() can be recomputed using the
test isolated temporary directory.
2022-12-19 21:37:19 +01:00
Marco Trevisan (Treviño)
9ea56848c2 garray: Just use one bit to hold the null teminated state
This is probably ignored for saving space because of padding optimizations,
but since we want this value to be either 0 or 1, this enforces this too.
2022-12-19 20:37:50 +01:00
Marco Trevisan (Treviño)
670c1f4173 garray: Add g_ptr_array_new_from_null_terminated_array()
It allows to create a GPtrArray from a null-terminated C array computing its
size and in case performing copies of the its values using the provided
GCopyFunc.
2022-12-19 20:37:50 +01:00
Marco Trevisan (Treviño)
c5aedc88fc garray: Add g_ptr_array_new_from_array() to copy a C array
It makes it easier (and more optimized) to create a GPtrArray from a C-style
array of pointers, in case using a GCopyFunc to duplicate the elements.
2022-12-19 20:37:49 +01:00
Marco Trevisan (Treviño)
d5efa78a12 garray: Add g_ptr_array_new_take_null_terminated()
Similar to g_ptr_array_new_take() but it also computes the length of a
zero-terminated array.
2022-12-19 20:05:30 +01:00
Marco Trevisan (Treviño)
14ded2ef94 garray: Add g_ptr_array_new_take() to take a C array without copies
GPtrArray is a nice interface to handle pointer arrays, however if a classic
array needs to be converted into a GPtrArray is currently needed to manually
go through all its elements and do new allocations that could be avoided.

So add g_ptr_array_new_take() which steals the data from an array of
pointers and allows to manage it using the GPtrArray API.
2022-12-19 19:55:28 +01:00
Emmanuele Bassi
6337bdaa37 Revert "garray: Add support adding literal values"
Reverts the following commits:

- ab621e15b52a57c8d95b3f4d93493c82f0f3216e.
- 85d9fb8e6c482d7b6d59efbf98040ad58d3f5008.

Too many build breaking regressions.

Fixes: #2846
2022-12-19 17:19:50 +00:00
Emmanuele Bassi
5701a15ae3 Merge branch 'wip/pwithnall/debugging-macos-ci' into 'main'
tests: Fix stall/deadlock in slice-concurrent on macOS CI

See merge request GNOME/glib!3152
2022-12-19 13:53:52 +00:00
Philip Withnall
d0f456a504 Merge branch 'futex64' into 'main'
glib/gthread-posix: Conditionally use `futex` and/or `futex_time64` syscalls...

See merge request GNOME/glib!3120
2022-12-19 13:19:07 +00:00
Alexander Richardson
0ec83bb650 gspawn.c: prefer close_range() on FreeBSD if available 2022-12-19 13:08:13 +00:00
Philip Withnall
b4ecb604aa tests: Use a thread-local GRand in each slice-concurrent test thread
This prevents stalls/deadlocks/timeouts on macOS. I don’t know why, as I
don’t have access to a macOS machine to test — this MR was put together
via testing on CI.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-19 11:32:59 +00:00
Philip Withnall
94d53af427 tests: Fix operator precedence in slice-concurrent
This regressed in commit 9f558a2c5017860c92d69396d36dc7a6b6a4e2af.

Not sure if it makes a functional difference to the test, though.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-19 09:57:39 +00:00
Philip Withnall
ba90e9ab22 Merge branch 'ghash-unsigned-nnodes' into 'main'
ghash: Use unsigned types for number of nodes and occupied ones

See merge request GNOME/glib!3148
2022-12-19 09:24:30 +00:00
William Roy
85d9fb8e6c Fix g_array_append_val compilation on Windows 2022-12-17 23:23:58 +00:00
Marco Trevisan (Treviño)
8465c1a055 ghash: Use unsigned types for number of nodes and occupied ones
It has always been considered an unsigned value, and we also returned it
straight as int in g_hash_table_size(), but it was actually used as an
int.

So use the same type of g_hash_table_size(). Not using more standard
unsigned not to risk that it may different from the guint typedef.
2022-12-16 19:33:01 +01:00
Philip Withnall
abd76e0286 Merge branch 'ghash-keys+values-arrays' into 'main'
ghash: Add APIs to get (and steal) hash table keys and values as GPtrArray

See merge request GNOME/glib!3130
2022-12-16 18:32:10 +00:00
Philip Withnall
cc113b710a Merge branch 'array-direct-insert' into 'main'
garray: Add support adding literal values

See merge request GNOME/glib!3129
2022-12-16 17:57:24 +00:00
Marco Trevisan (Treviño)
d68e7bc84a ghash: Add functions to steal all keys and values preserving ownership
Add functions to steal all the keys or values from a ghash (especially
useful when it's used as a set), passing the ownership of then to a
GPtrArray container that preserves the destroy notify functions.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
d2c3f7f513 ghash: Add APIs to get hash table keys and values as GPtrArray
GPtrArray's are faster than lists and provide more flexibility, so add
APIs to get hash keys and values using these containers too.

Given that we know the size at array initialization we can optimize the
allocation quite a bit, making it faster than the API using GList both at
creation time and for consumers.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
ab621e15b5 garray: Add support adding literal values
GArray's g_array_append_val(), g_array_prened_val() and g_array_insert_val()
macros required an user to use literals to add a new value.

This could be inconvenient at times, but it's possible to avoid this with
recent compilers, in fact in case glib_typeof is defined we can take
advantage of it, to initialize a temporary variable to store the literal
value and pass its address to the actual function.
2022-12-16 18:13:28 +01:00
Alexander Richardson
9f558a2c50 tests/slice-concurrent.c: avoid using rand() from multiple threads 2022-12-16 17:00:56 +00:00
Philip Withnall
58521101b3 Merge branch 'wip/smcv/gvariant-big-endian' into 'main'
gvariant-serialiser: Convert endianness of offsets

Closes #2839

See merge request GNOME/glib!3136
2022-12-16 13:32:39 +00:00
Simon McVittie
ba2137b0d9 gvariant-serialiser: Convert endianness of offsets
The array of offsets is little-endian, even on big-endian architectures
like s390x.

Fixes: ade71fb5 "gvariant: Don’t allow child elements to overlap with each other"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2839
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-16 13:03:37 +00:00
Alex Richardson
58f70cebb6 Fix test_aligned_mem for Morello
On Arm Morello sizeof(void*) is 16 bytes so we fail the check for
`(alignment % sizeof (void *)) != 0))` in gmem.c.
2022-12-15 23:50:23 +00:00
Alex Richardson
34236af33c tests/gvariant.c: ensure posix_memalign alignment argument is correct
posix_memalign() requires the alignment to be a multiple of sizeof(void*),
and a power of 2. Passing 8 does not fulfil both of those constraints on
Arm Morello which resulted in a "posix_memalign failed" test failure.

Co-authored-by: Graeme Jenkinson <graeme@capabilitieslimited.co.uk>
2022-12-15 23:50:23 +00:00
Marco Trevisan (Treviño)
f520066563 gutils: Add a private API to unset the cached temporary directory
We may need to avoid using a cached temp directory for testing purposes,
so let's provide an internal API to perform such task.

This implies removing GOnce and going with mutex-based version, but
that's still using atomic logic in most unix implementations anyways.
2022-12-15 17:29:00 +01:00
Philip Withnall
b012c3470b gtestutils: Check for failure to setenv() and return
This is very unlikely to happen, but it makes Coverity happier.

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

Coverity CID: #1474388
2022-12-14 15:11:10 +00:00
Philip Withnall
a70a16b28b gvariant: Allow g_variant_byteswap() to operate on tree-form variants
This avoids needing to always serialise a variant before byteswapping it.
With variants in non-normal forms, serialisation can result in a large
increase in size of the variant, and a lot of allocations for leaf
`GVariant`s. This can lead to a denial of service attack.

Avoid that by changing byteswapping so that it happens on the tree form
of the variant if the input is in non-normal form. If the input is in
normal form (either serialised or in tree form), continue using the
existing code as byteswapping an already-serialised normal variant is
about 3× faster than byteswapping on the equivalent tree form.

The existing unit tests cover byteswapping well, but need some
adaptation so that they operate on tree form variants too.

I considered dropping the serialised byteswapping code and doing all
byteswapping on tree-form variants, as that would make maintenance
simpler (avoiding having two parallel implementations of byteswapping).
However, most inputs to `g_variant_byteswap()` are likely to be
serialised variants (coming from a byte array of input from some foreign
source) and most of them are going to be in normal form (as corruption
and malicious action are rare). So getting rid of the serialised
byteswapping code would impose quite a performance penalty on the common
case.

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

Fixes: #2797
2022-12-13 19:04:15 +00:00