8781 Commits

Author SHA1 Message Date
Maciej S. Szmigiero
0f5d274871 gtestutils: Document that g_test_trap_fork () won't get close-on-exec fix
We don't want to update this function in case some crusty old third party
code might be relying on its current behavior.
Also, it is deprecated anyway and no code should be using it.
2023-02-21 12:42:55 +00:00
Maciej S. Szmigiero
05d2a1d097 gbacktrace: Use g_unix_open_pipe_internal () for creating pipes
This attempts to create the pipes with race-free setting of the
close-on-exec flag.
2023-02-21 12:42:55 +00:00
Maciej S. Szmigiero
14b5207bfa Add g_unix_open_pipe_internal () for pipes with the close-on-exec flag
Based on the existing g_unix_open_pipe () but for internal use where
returning a raw errno is needed, not a GError.
2023-02-21 12:42:55 +00:00
Chun-wei Fan
601fce37cb spawn-test: Fix running on non-English Windows
Use SetThreadUILocale() to set the UI locale to English (United States)
(en-US), and use SetConsoleOutputCP() to set the code page to en-US (codepage
437) so that g_win32_error_message() will always return the error messages in
English and ensure that the program runs in English as well, so that we
can ensure that the expected error message string can match up
regardless of the languge version of Windows that is running.
2023-02-21 16:34:31 +08:00
Philip Withnall
c4203f740c gerror: Emit a critical warning if the message format is NULL
The code has warned about this since commit 6d9f874330 in 2011.

glibc 2.37 has just started asserting if a `NULL` format is passed to
`sprintf()`, which caused the existing GLib workaround to start
asserting too.

Bite the bullet and upgrade the warning for `format != NULL` to a
critical warning. Projects have had 12 years to fix their code.

The original bug reports
(https://bugzilla.gnome.org/show_bug.cgi?id=660371,
https://bugzilla.gnome.org/show_bug.cgi?id=560482) are actually both
about a domain which is `0`, rather than a format which is `NULL`, which
gives some confidence that this change will actually impact very little
third party code.

Since it doesn’t currently need changing, I have not touched the warning
about `domain != 0`.

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

Fixes: #2913
2023-02-20 16:41:23 +00:00
Luca Bacci
5631a6b9eb spawn-test: Remove the can_fail attribute 2023-02-17 15:57:49 +01:00
Luca Bacci
390dcc92d8 spawn-test: Use an absolute path to the system sort.exe on Windows
This way we avoid executing other kinds of sort.exe which are
available in PATH. This is useful especially on MSYS2 which
provides coreutils sort.
2023-02-17 15:29:00 +01:00
Philip Withnall
6a46aabd4c tests: Use g_assert_*() rather than g_assert() in string tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-16 11:29:26 +00:00
Philip Withnall
bc53fff8a3 tests: Add a -Wsign-conversion test for gstring.h
While it’s not possible to build GLib with `-Wsign-conversion` enabled
(there are too many warnings), it would be useful to check that GLib’s
public headers can be used with `-Wsign-conversion` enabled, as some
projects want to do that. For example, dnf5 is built that way (see
issue #2919).

Add a simple regression test for this, by re-building the `gstring`
tests with `-Wsign-conversion` enabled. Since they include `glib.h`,
this will test all the public libglib headers by proxy.

Since this is a compile-only test, it doesn’t need to be installed.

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

Helps: #2919
2023-02-16 11:29:26 +00:00
Philip Withnall
0bdf7fcce4 tests: Fix some sign-conversion warnings in the GString tests
This will be useful for the next commit.

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

Helps: #2919
2023-02-16 11:29:26 +00:00
Philip Withnall
d2d1af284d gtestutils: Fix a sign-conversion warning in g_assert_cmpmem()
It was assigning the two provided lengths to internal `int` variables.
Given that memory block lengths are typically a `size_t`, this will
usually result in a warning if `-Wsign-conversion` is enabled.

Given that the internal variables are passed to `memcmp()`, which takes
`size_t`, change them to `size_t` and add an explicit cast to avoid
warnings in future.

The alternative would be to mess around with defining `__l1` and `__l2`
to using `typeof()`, but that would lead to a complete mess with the
printf placeholders and probably cause more problems than it fixes.

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

Helps: #2919
2023-02-16 11:29:26 +00:00
Aleš Matěj
f6d6800962 g_string_append_len_inline: fix implicit conversion changes signedness
For: https://gitlab.gnome.org/GNOME/glib/-/issues/2919
2023-02-16 10:57:48 +00:00
Simon McVittie
854fd11422 array-test: Don't rely on endianness of multi-byte numbers
The array is an array of bytes in this part of the test, so we need to
append a single byte. Previously we were reusing val (a size_t variable)
from earlier in the test, but because g_array_append_val passes the value
by reference, appending a multi-byte number to an array of bytes will
take the first byte of the number's memory representation, which has the
desired value on little-endian CPUs but is zero on big-endian, leading
to a test failure.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2918
Bug-Debian: https://bugs.debian.org/1031271
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-14 10:42:08 +00:00
Philip Withnall
a359e56f58 gutils: Remove public API decorator from g_set_user_dirs()
It’s a private API, and is not meant to be exposed in the public API.
Since it’s only used internally within libglib, we don’t have to expose
it in the public symbol table, so drop the decorator.

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

Helps: #2876
2023-02-13 16:14:10 +00:00
Philip Withnall
438bd5cfa1 gutils: Make g_find_program_for_path() a proper private API
It’s not meant to be exposed publicly yet (we’re not ready to stabilise
it), but it was incorrectly decorated with `GLIB_AVAILABLE_IN_2_76`.

We can’t remove the decorator and use it that way, as it’s called in
libgio, so we have to expose it using `GLIB_PRIVATE_CALL()`.

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

Fixes: #2876
2023-02-13 16:12:07 +00:00
Emmanuele Bassi
585c7d2db6 Merge branch 'wip/smcv/symlink-detection-doc' into 'main'
fileutils: Make some sample code detect symlinks as intended

See merge request GNOME/glib!3265
2023-02-10 20:52:08 +00:00
Alex Richardson
9f8edb1e3f GVariant: ensure GVariantIter alignment for CHERI systems
For CHERI-enabled architectures such as Arm Morello we have to align the
GVariantIter to pointer alignment (16 bytes for Morello) but defining the
opaque struct as 16 gsize elements only aligns to 8 bytes.
This does not change the layout for existing architecutre since there
gsize is the same as guintptr.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Alex Richardson
147777e342 GHash: Don't use SMALL_ENTRY_SIZE for CHERI
The code for SMALL_ENTRY_SIZE assumes pointers are no larger than 8 bytes,
so instead of trying to make it work disable the optimization for now.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
Co-authored-by: Graeme Jenkinson <graeme@capabilitieslimited.co.uk>
2023-02-10 18:22:20 +00:00
Alex Richardson
5d8ecac1ec Make GVariantBuilder and GVariantDict layout compatible with CHERI
Use guinptr instead if gsize. While this increases the structure size
for Morello, it is still only 256 bytes which should not matter for a
type where we expect few instances to exist at any given time.
This does not increase the size for existing architectures since gsize
is the same as guintptr for all of them.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Alex Richardson
2aed76fc94 Fix GHashTableIter layout for CHERI targets
Last field needs to be pointer-size to match GHashTableIter. This happened
to work for most architecture due to alignment padding/pointer size, but
for CHERI targets with 128-bit pointers RealIter ends up being smaller
than GHashTableIter.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Simon McVittie
702e606f73 Merge branch 'wip/smcv/pathbuf-windows' into 'main'
pathbuf: Treat forward slashes and backslashes as equivalent on Windows

Closes #2914

See merge request GNOME/glib!3264
2023-02-10 15:41:31 +00:00
Philip Withnall
9ab080c6ce Merge branch 'wip/smcv/gi-warnings' into 'main'
Avoid some warnings from GObject-Introspection

See merge request GNOME/glib!3266
2023-02-10 13:49:22 +00:00
Simon McVittie
ee223e8ec8 gtimezone: Avoid a nested preprocessor conditional to be nice to g-i
GObject-Introspection seems to become confused by the nested conditional
followed by an `#elif` clause for the outer conditional, and issues
this warning:

.../gtimezone.c:830: mismatched #elif  defined (G_OS_WIN32)

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:16:01 +00:00
Simon McVittie
30352032a6 gstrfuncs: Use separate preprocessor conditionals for g-i and gtk-doc
GObject-Introspection and gtk-doc both parse C headers using regular
expressions, so they can easily be confused by non-trivial conditions.
GObject-Introspection warns about this:

    .../gstrfuncs.h:151: the __GI_SCANNER__ constant should only be used with simple #ifdef or #endif: #if  !defined (__GTK_DOC_IGNORE__) && !defined (__GI_SCANNER__)

In this case it's very easy to convert the compound expression into
nesting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:14:42 +00:00
Simon McVittie
f6e13753aa fileutils: Make some sample code detect symlinks as intended
The sample code here wasn't a race-free version of the race-susceptible
anti-pattern, because it would have dereferenced a symlink automatically.

Fixes: 293b4923 "Clarify g_file_test() docs about TOCTOU bugs"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:06:04 +00:00
Simon McVittie
def7c0ac10 pathbuf: Treat forward slashes and backslashes as equivalent on Windows
The canonical directory separator is a backslash, but some Windows APIs
allow either, interchangeably. Do the same here.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2914
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 11:13:36 +00:00
Alex Richardson
14ae87f379 Add a (temporary) assertion that sizeof(gsize) == sizeof(guintptr)
Glib does not yet have a well defined ABI/API for architectures
where gsize != guintptr (e.g. CHERI). To enable working on bringup
for new architectures this assertion can be disabled with
`-DG_ENABLE_EXPERIMENTAL_ABI_COMPILATION`.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2842

[smcv: Apply review comments from pwithnall]

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 10:54:36 +00:00
Simon McVittie
73c91ef799 Revert "glib-init: Add more static assertions for gintptr, guintptr"
On closer inspection, these are redundant with stricter assertions that I
added in commit bd1e2a98 "glib-init: Statically assert more facts about
standard types", which assert that sizeof (gintptr) == sizeof (void *).

As far as I can tell, a sufficiently pedantic interpretation of Standard
C doesn't actually require (u)intptr_t to be the same size as a pointer:
it only requires that pointers can be losslessly stored in a (u)intptr_t,
which a sufficiently pathological ABI could implement by having (for
example) 32-bit pointers and a 64-bit uintptr_t just to troll us. However,
I'm fairly confident that no practically useful ABI would do this,
and certainly nobody has complained about this assertion since 2020.

Similarly, Standard C might permit an ABI where 64-bit pointers have the
first 32 bits always-zero and therefore storing the remaining bits in a
32-bit uintptr_t is lossless, but again, that would be pathological.

This reverts commit da3fc59544f36e246cd7f5a198083203199d5127.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-09 19:08:08 +00:00
Emmanuele Bassi
fcdbd7f9bd tests: Add GPathBuf to the g_auto suite 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
7e62d01053 tests: Add PathBuf.new_from_path() coverage 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
d0ee88078b doc: Clarify g_path_buf_to_path()
The returned path is built on demand.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
a05fda9990 Move GPathBuf tests into their own file
Keep the fileutils tests related to the gfileutils.h API.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
280649fb82 docs: Clarify the path construction functions
Use the same wording for functions that belong in the same family, and
link to the newly introduced GPathBuf API.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
314d62f302 doc: Make file utils docblocks render nicely with gi-docgen
Do not use 4-spaces indentation for return and argument descriptions, to
avoid getting rendered as preformatted blocks.

Annotate code examples with their language, for syntax highlighting.

Isolate the first paragraph to give a short description.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
293b492334 Clarify g_file_test() docs about TOCTOU bugs
Do not show just what not to do: show what to do instead, otherwise
people won't know how to fix their code.

Make sure to link to an explanation of the TOCTOU class of bugs;
Wikipedia is as good a place as any.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
2015723a4f Add tests for GPathBuf 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
f60f432b6c Add GPathBuf
GPathBuf is a path buffer type that can be used to build paths
programmatically, using it as a stack.
2023-02-09 13:36:51 +00:00
Thomas Haller
4d7f66f214 gmessages: use g_atomic_pointer to access handlers for g_print()/g_printerr()
It seems unnecessary to use the mutex to get/set a single pointer.
2023-02-07 13:16:07 +01:00
Philip Withnall
361745149f Merge branch 'msort-cheri' into 'main'
Allow using msort_r CHERI-enabled architectures

See merge request GNOME/glib!3243
2023-02-06 14:04:18 +00:00
Marco Trevisan (Treviño)
893b86b939 gslice: Mark memory arguments and return values as nullable when it's the case
GSlice can handle NULL arguments or return NULL values, but we did not
properly mark them all the times.
2023-02-03 16:28:51 +01:00
Marco Trevisan (Treviño)
6af6f3eb9b gslice: Do not try to memset-0 NULL a pointer
According to the docs, g_slice_free1() is supposed to do nothing if
@mem_block is NULL, but we still try to zero it in case we're using
g_mem_gc_friendly.

So avoid this case.

Closes: #2908
2023-02-03 16:28:37 +01:00
Marco Trevisan
95cbff0fd2 Merge branch 'free-sized' into 'main'
gmem: Add g_free_sized() and g_aligned_free_sized()

See merge request GNOME/glib!3231
2023-02-03 10:01:35 +00:00
Philip Withnall
548d917f35 Merge branch 'gcc13-warning-fix' into 'main'
timezone: Fix a compiler warning

See merge request GNOME/glib!3248
2023-02-03 08:02:57 +00:00
Matthias Clasen
d9f8d73be2 gstring: Avoid warnings from inline functions
The current code for g_string_append_c_inline generates
warnings when used, with -Wnull-dereference. Avoid that.
2023-02-03 00:36:53 +00:00
Matthias Clasen
cbb2ca8c4a timezone: Fix a compiler warning
gcc 13 complains that last_explicit_transition_time
may be used uninitialized.
2023-02-03 00:36:21 +00:00
Philip Withnall
97ebd794a7 gslice: Use g_free_sized() instead of g_free()
If libc supports `free_sized()`, this could mean that freeing slices is
a bit more performant. If not, it falls back to using `free()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-02 12:30:59 +00:00
Philip Withnall
329843f682 gmem: Add g_free_sized() and g_aligned_free_sized()
These wrap `free_sized()` and `free_aligned_sized()`, which are present
in C23[1]. This means that user code can start to use them without checking
for C23 support everywhere first.

It also means we can use them internally in GSlice to get a bit of
performance for the code which still uses it.

See https://en.cppreference.com/w/c/memory/free_aligned_sized and
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2699.htm.

[1]: Specifically, section 7.24.3.4 of the latest C23 draft at
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3088.pdf.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-02 12:30:59 +00:00
Marco Trevisan
fe2de360de Merge branch 'cxx-leak' into 'main'
tests: Fix a minor leak in the cxx string append tests

See merge request GNOME/glib!3247
2023-02-01 16:29:04 +00:00
Marco Trevisan
155e44652e Merge branch 'gstring-free-warning' into 'main'
Make g_string_free (_, FALSE) warn on unused result

See merge request GNOME/glib!3226
2023-02-01 16:28:02 +00:00
Philip Withnall
b3389b66d6 tests: Fix a minor leak in the cxx string append tests
See https://gitlab.gnome.org/GNOME/glib/-/jobs/2547640

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

Helps: #2904
2023-01-31 11:52:11 +00:00