Commit Graph

26936 Commits

Author SHA1 Message Date
Alex Richardson
d2bbd69fd5 Allow using msort_r CHERI-enabled architectures
If we are sorting something that is a multiple of sizeof(void*), we have
to ensure that we swap one pointer at a time since swapping using
sub-pointer-size stores invalidate the pointers (pointers have a hidden
validity tags that is invalidated when performing non-monotonic
operations such as storing only part of the pointers).

While touching this code also use G_ALIGNOF() instead of a macro that
is generated at configure time.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-01-29 12:40:26 +00:00
Alex Richardson
a03950b43c GAtomicArray: Ensure metadata does not misalign the payload
We have to ensure that the memory location is sufficiently aligned to
store any object. This unbreaks the code for CHERI where using gsize
results in values that are only aligned to 8 bytes, but we need 16 byte
alignment for pointers. This is fully API/ABI compatible since amount
of padding before the actual allocation does not change for existing
architectures, only for CHERI.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-01-29 12:36:06 +00:00
Yuri Chornoivan
eafd19da29 Update Ukrainian translation 2023-01-27 20:47:17 +00:00
Marco Trevisan
183c646fea Merge branch 'gmain-cleanups' into 'main'
GMainContext: Use nullable context in docs (and in some missing code)

See merge request GNOME/glib!3234
2023-01-27 14:03:13 +00:00
Philip Withnall
0bf7e8a1f4 Merge branch 'issue-2898-g_print_encoding' into 'main'
Document g_print and g_printerr encoding behaviour

Closes #2898

See merge request GNOME/glib!3233
2023-01-27 14:01:59 +00:00
Daniel Carpenter
04879542a4 Document g_print and g_printerr encoding behaviour 2023-01-27 14:01:58 +00:00
Sergey Bugaev
c121118bc4 tests: Silence a warning
In case the OS does not support epoll and kqueue, we get the warning:

gio/tests/pollable.c: In function ‘test_pollable_unix_nulldev’:
gio/tests/pollable.c:266:7: warning: unused variable ‘fd’
[-Wunused-variable]
  266 |   int fd;

Get rid of it.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:58:56 +03:00
Sergey Bugaev
718f05d090 gwakeup: #include <stdint.h>
Since commit 94b658ab4c, gwakeup.c has
started using C99 integer types, but has not included <stdint.h>. This
broke building on GNU/Hurd. Fix this by adding the missing include.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:58:56 +03:00
Sergey Bugaev
c3d07a625a string: Make g_string_free (_, FALSE) warn on unused result
...much like g_string_free_and_steal () does; by redirecting
g_string_free (_, FALSE) calls (when we can detect them) to
g_string_free_and_steal ().

This relies on some unpretty macros, but should be entirely transparent
to any users of g_string_free (). In particular, the macro only
evaluates its arguments once, no matter which branch ends up being
taken. The ternary operator the macro expands to always gets optimized
out, even at -O0: there is only one call to either g_string_free () or
g_string_free_and_steal () in the compiled code, with no run-time
branching.

Add a test for ensuring this works as expected in C++ too.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:58:52 +03:00
Sergey Bugaev
bccff754b6 Use g_string_free_and_steal () more
Now that there is g_string_free_and_steal (), we can use it instead of
the older g_string_free (_, FALSE). Make sure to use its return value
while doing so, as opposed to manually accessing string->str, to avoid
compiler warnings and make the intent more explicit.

This is all done in preparation for making g_string_free (_, FALSE) warn
on unused return value much like g_string_free_and_steal (), which will
happen in the next commit.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:55:27 +03:00
Marco Trevisan
5e40004bdb Merge branch 'gstrdup-inline' into 'main'
gstrfuncs: Add inline version of g_strdup()

See merge request GNOME/glib!3209
2023-01-26 18:38:37 +00:00
Marco Trevisan (Treviño)
7ac6c3dc9b gmain: Avoid checking for context value in internal function
This is something that is supposed to do by the public API, as everywhere
else the internal functions should be called with proper parameters instead
2023-01-26 18:04:13 +01:00
Marco Trevisan (Treviño)
39557fc4ae gmain: Explicitly mark @context as not nullable in ref/unref operations
It's quite clear already, but let's mark it even more explicit.
2023-01-26 18:04:13 +01:00
Marco Trevisan (Treviño)
1f8787116a gmain: Support nullable GMainContext in all the functions
All the GMainContext functions are supposed to work with a NULL context to
use the default one, but some were not doing it.

So adjust them.
2023-01-26 18:04:13 +01:00
Marco Trevisan
2cbc90cc1e Merge branch '2901-gio-executable-docs' into 'main'
gappinfo: Document that g_app_info_get_executable() should not be spawned

Closes #2901

See merge request GNOME/glib!3240
2023-01-26 16:41:16 +00:00
Marco Trevisan (Treviño)
3b2c7aba99 gmain: Mark context as nullable in docs where appropriate
GMainContext can be NULL in various functions, but we don't mark it as such.
2023-01-26 17:28:30 +01:00
Marco Trevisan (Treviño)
62ee931fce gmain: Always use "global-default main context" terminology in docs
That's also what we do in the GLib tutorial [1], so let's be consistent here

[1] https://gitlab.gnome.org/Teams/documentation/developer-www/-/blob/main/source/tutorials/main-contexts.rst
2023-01-26 17:26:15 +01:00
Marco Trevisan (Treviño)
23da6bade0 {glib,gio}/cxx: Add more tests for C++ inline funcs
These could behave differently in C++ so let's ensure this is not the
case.
2023-01-26 16:52:36 +01:00
Marco Trevisan (Treviño)
cc0fb5e77c gstrfuncs: Add inline version of g_strdup()
g_strdup() is often used to duplicate static strings, in these cases the
compiler could use a faster path because it knows the length of the
string at compile time, but this cannot happen because our g_strdup()
implementation is hidden.

To improve this case, we add a simple implementation of g_strdup() when
it is used with static or NULL strings that explicitly uses strlen,
g_malloc and memcpy to give hints to the compiler how to behave better.

This has definitely some benefits in terms of performances, causing an
iteration of 1000000 string duplication to drop from 2.7002s to 1.9428s
for a static string and from ~0.6584s to ~0.4408 for a NULL one.

Since compiler can optimize these cases quite a bit, the generated code
[2] is not increasing a lot, given that it can now avoid generating some
code or do it in few simpler steps.

Update tests to cover both inlined and non inlined cases.

[1] https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3209#note_1644383
[2] https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3209#note_1646662
2023-01-26 16:51:05 +01:00
Marco Trevisan (Treviño)
ed42f57704 tests/strfuncs: Add test for g_strdup() with empty string 2023-01-26 16:49:28 +01:00
Marco Trevisan (Treviño)
9cd90d97ae tests/strfuncs: Ensure that inlined functions really are macros
Add a compile check to ensure that the functions we have inlined are
actually macros when under gcc (and friends).
2023-01-26 16:49:28 +01:00
Marco Trevisan (Treviño)
a9ee3a5faa gstrfuncs: Ignore parsing inline macro versions for docs and g-i
We have actual definitions for these functions so we should ignore their
inline versions, not to potentially break doc parsers due to the different
argument names.

For some reasons we can't merge the check together with the gnu C check
if, otherwise the check gets ignored by doc parser.
2023-01-26 16:49:28 +01:00
Philip Withnall
a4fe981a7f Merge branch 'gstring-inline-null-handling' into 'main'
gstring: Gracefully handle NULL parameters in inline append

Closes #2890

See merge request GNOME/glib!3217
2023-01-26 15:46:03 +00:00
Marco Trevisan
452e9957a4 Merge branch 'leak-suppressions' into 'main'
Add a few suppressions to glib.supp and fix a minor bug in gapplication test

See merge request GNOME/glib!3223
2023-01-26 15:40:22 +00:00
Philip Withnall
ac30b7d824 Merge branch 'leak-fix' into 'main'
tests/desktop-app-info: fix stack-use-after-scope

See merge request GNOME/glib!3187
2023-01-26 15:36:22 +00:00
Philip Withnall
c53f9c0d37 gappinfo: Document that g_app_info_get_executable() should not be spawned
Spawning a process correctly is a lot more complicated than just bunging
an argument onto the return value from this function.

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

Helps: #2901
2023-01-26 14:54:35 +00:00
Philip Withnall
287314c5a9 Merge branch 'regex-escape-string-bad-gir' into 'main'
g_regex_escape_string: bad GIR: utf8[] -> utf8

See merge request GNOME/glib!3236
2023-01-26 14:47:13 +00:00
Philip Withnall
34f5fa046a Merge branch 'fix_wspawnve' into 'main'
Fix safe_wspawnve #define

Closes #2900 and gimp#9094

See merge request GNOME/glib!3237
2023-01-26 14:25:03 +00:00
Emmanuele Bassi
2974cf272a Merge branch 'bad-gir-gunichar-array' into 'main'
Fix GIR: gunichar -> gunichar[]

See merge request GNOME/glib!3238
2023-01-26 14:03:18 +00:00
Bart Jacobs
4e1fe6cf22 Fix GIR: gunichar -> gunichar[] 2023-01-26 11:27:31 +00:00
Hernan Martinez
4c4448debd Fix safe_wspawnve #define 2023-01-26 10:23:41 +00:00
Bart Jacobs
2f0ec59c4a g_regex_escape_string: bad GIR: utf8[] -> utf8 2023-01-26 10:18:05 +00:00
Philip Withnall
828030a6b2 Merge branch 'io-channel-get-line-term-bad-gir' into 'main'
g_io_channel_get_line_term: add (out) annotation

Closes #2895

See merge request GNOME/glib!3232
2023-01-25 18:54:30 +00:00
Marco Trevisan (Treviño)
50204abda6 gstring: Cleanup some macro definitions 2023-01-25 17:28:09 +01:00
Marco Trevisan (Treviño)
4ca90af6ed gstring: Gracefully handle NULL parameters in inline append
We could have unguarded crashes when calling strlen (NULL) or when passing
invalid GString's.

Also ensure that we are not using the macro `val` argument multiple times as
it may lead to an unwanted behavior when passing to it a variable value such
as `str[++i]`, as the value may be called multiple times.
C++ tests and Coverity were both underlining this.

Fixes: #2890
2023-01-25 17:27:51 +01:00
Philip Withnall
636d4a587a Merge branch 'time-zone-adjust-time-bad-gir' into 'main'
g_time_zone_adjust_time: add (inout) annotation

Closes #2897

See merge request GNOME/glib!3230
2023-01-25 15:27:26 +00:00
Bart Jacobs
0815be81ce g_io_channel_get_line_term: add (optional) annotation 2023-01-25 14:49:30 +00:00
Philip Withnall
8b76267787 Merge branch 'fix_2894' into 'main'
GValue: document ownership transfer in g_value_take_string

Closes #2894

See merge request GNOME/glib!3228
2023-01-25 14:41:05 +00:00
Bart Jacobs
f87475ea87 g_io_channel_get_line_term: add (out) annotation
Fixes #2895
2023-01-25 14:30:23 +00:00
Bart Jacobs
92e34c86da g_time_zone_adjust_time: add (inout) annotation
Fixes #2897 .
2023-01-25 15:19:07 +01:00
Hugo Carvalho
8a9bfa0b62 Update Portuguese translation 2023-01-25 14:16:41 +00:00
Philip Withnall
0f7797d76d Merge branch 'remove-gslice-allocator' into 'main'
gslice: remove slice allocator

Closes #1079

See merge request GNOME/glib!2935
2023-01-25 14:09:58 +00:00
Lukáš Tyrychtr
fce798661d GValue: document ownership transfer in g_value_take_string
Fixes #2894
2023-01-25 14:49:57 +01:00
Philip Withnall
41416c9fe6 tests: Drop unnecessary GSlice tests
Now that the implementation of GSlice has been dropped, these tests for
the internals of the implementation are unnecessary.

We can keep `glib/tests/slice.c` as it tests the API rather than the
implementation.

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

Helps: #1079
2023-01-25 13:49:09 +00:00
Natanael Copa
7e4b8dfb82 glib/tests: Drop debug build of slice test 2023-01-25 13:49:09 +00:00
Natanael Copa
45b5a6c1e5 gslice: Remove slice allocator and use malloc() instead
Keep the API for ABI compatibility.

See
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2935#note_1650099
for a summary of the reasoning for this change:
 - The performance of system-provided allocators has improved since
   GSlice was written, and they are now similarly as performant, or more
   performant, than GSlice.
 - The code is unmaintained and nobody understands it.
 - It doesn’t integrate with tooling and system security features which
   have been written for the system `malloc()` implementation (such as
   sanitisers, valgrind, etc.).
 - It’s confusing for developers: should they use `g_slice_new()` or
   `g_new()`?
 - GSlice is faster than the libc allocator for allocating and
   (particularly) freeing linked lists, but since these are a rubbish
   data structure, that’s not a great thing to optimise for.

For the cases where application performance is negatively impacted by
the implementation of GSlice being dropped (and we don’t think there’ll
be many), applications can use a drop-in `malloc()` replacement which is
more suited to their particular workload. Choosing an allocator in GLib
to suit all application workloads is not possible.

Including documentation updates and cleanups by Philip Withnall.

Fixes: #1079
2023-01-25 13:49:09 +00:00
Philip Withnall
6facddac02 Merge branch 'socket-reuse-tests' into 'main'
tests: Temporarily disable socket test due to a kernel bug

See merge request GNOME/glib!3225
2023-01-25 12:49:42 +00:00
Yosef Or Boczko
65f660914a Update Hebrew translation 2023-01-25 08:16:51 +00:00
Emin Tufan Çetin
7bfbf0e17c Update Turkish translation 2023-01-24 23:47:23 +00:00
Simon McVittie
4dc99db8ad Merge branch 'coverity-test-logging' into 'main'
gtestutils: Fix a potential NULL pointer dereference in g_test_log()

See merge request GNOME/glib!3224
2023-01-24 19:50:25 +00:00