32073 Commits

Author SHA1 Message Date
Luca Bacci
b972407445 Tests: Add test for g_win32_error_message_in_place 2025-08-07 19:14:51 +02:00
Luca Bacci
5fda2637d8 Tests: Add test for g_win32_handle_is_console_output 2025-08-07 19:14:50 +02:00
Luca Bacci
e284ec1749 tests: Add test for g_fputs 2025-08-07 19:14:50 +02:00
Luca Bacci
02c63162a4 Use g_fputs in g_printf, g_fprintf 2025-08-07 19:14:50 +02:00
Luca Bacci
a3a98500ac Use g_fputs in g_log_writer_standard_streams 2025-08-07 19:14:50 +02:00
Luca Bacci
d26c0f1907 Add g_log_writer_format_fields variant for UTF-8 (internal) 2025-08-07 19:14:50 +02:00
Luca Bacci
b080c5f051 Use g_fputs in g_print
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3341
2025-08-07 19:14:50 +02:00
Luca Bacci
f26173963a Add g_fputs() utility function
Like g_print, expects UTF-8 and outputs in the right charset.
2025-08-07 19:14:50 +02:00
Luca Bacci
7faaac9265 Move strdup_convert() to dedicated source file
And thus rename to g_print_convert()
2025-08-07 19:14:50 +02:00
Luca Bacci
734b998eea Add error handling functions for Windows
Import some Windows-specific error handling functions from GTK. See:

 * https://gitlab.gnome.org/GNOME/gtk/-/blob/4.18.0/gdk/win32/gdkmain-win32.c?ref_type=tags#L110
 * https://gitlab.gnome.org/GNOME/gtk/-/blob/4.18.0/gdk/win32/gdkprivate-win32.h?ref_type=tags#L141
2025-08-07 19:14:50 +02:00
Luca Bacci
7f2a587746 Add g_win32_file_stream_is_console_output() 2025-08-07 19:14:50 +02:00
Luca Bacci
4e39a7c08c Add g_win32_handle_is_console_output()
Private function that checks whether a HANDLE refers to a console
screen buffer.
2025-08-07 19:14:50 +02:00
Luca Bacci
c4be7824d5 Add g_utf8_to_utf16_make_valid() with backtrack functionality 2025-08-07 19:14:42 +02:00
Stefan Hansson
f0f4f31206 gspawn: Improve docstring for g_spawn_async()
Based on my reading of the docs, g_spawn_async_with_pipes_and_fds()
seems to have a much more comprehensive explanation of itself than
g_spawn_async_with_pipes(). As such, it makes sense to me to refer to it
rather than the latter when suggesting where to go for further reading.

Signed-off-by: Stefan Hansson <newbyte@postmarketos.org>
2025-08-07 18:33:17 +02:00
Philip Withnall
a1a48126b1 Merge branch 'faccessat-openbsd' into 'main'
glocalfile: Disable faccessat()-based query_exists on OpenBSD

See merge request GNOME/glib!4731
2025-08-07 11:28:25 +00:00
Antoine Jacoutot
ff47c01818 glocalfile: Disable faccessat()-based query_exists on OpenBSD 2025-08-07 11:28:25 +00:00
Philip Withnall
ebe003c1b7 Merge branch 'wip/kabus/filenamecompleter-test' into 'main'
Add a basic GFilenameCompleter test

See merge request GNOME/glib!4726
2025-08-05 15:02:31 +00:00
Khalid Abu Shawarib
7a38cbc1dc gio/filenamecompleter: Use platform-specific directory separator 2025-08-05 17:36:41 +03:00
Khalid Abu Shawarib
48f8812cca gio/tests/filenamecompleter: Add a basic test 2025-08-05 17:36:00 +03:00
Khalid Abu Shawarib
f9592306c9 gio/filenamecompleter: Add more specifics to documentation
Also remove redundant things like asking a user to free a string,
as it is already covered by transfer type annotations.
2025-08-05 17:36:00 +03:00
Philip Withnall
da19665880 Merge branch 'gdbuserror-docs' into 'main'
gdbuserror: Reformat docs to fully use gi-docgen and match style guide

See merge request GNOME/glib!4715
2025-08-05 13:20:06 +00:00
Philip Withnall
d6ba42a489 gdbuserror: Reformat docs to fully use gi-docgen and match style guide
https://developer.gnome.org/documentation/guidelines/devel-docs.html#writing-api-references

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3250
2025-08-05 13:57:40 +01:00
Philip Withnall
924e4656e6 Merge branch 'strtoll' into 'main'
gstrfuncs: Always treat G_MININT64 in g_ascii_strtoll

See merge request GNOME/glib!4730
2025-08-05 12:23:09 +00:00
Tobias Stoeckmann
14f4ca3287 gstrfuncs: Always treat G_MININT64 in g_ascii_strtoll
If g_ascii_strtoll does not use strtoll_l, the result of
g_parse_long_long could be G_MININT64 with gboolean negative set.

In such a case, returning `- (gint64) result` would lead to an undefined
behavior because -G_MININT64 would lead to an implicit integer overflow.

Realistically though, this still leads to G_MININT64. Fixes test failure
if compiled with ubsan on a platform without strtoll_l.
2025-08-05 08:13:20 +02:00
Philip Withnall
49bf72ac63 Merge branch 'gbytearray_err' into 'main'
garray: Pass errors through GByteArray functions

See merge request GNOME/glib!4724
2025-08-04 11:08:01 +00:00
Tobias Stoeckmann
e2850dfd73 garray: Pass errors through GByteArray functions
Some GByteArray functions already pass through the return values of
called GArray functions. Do so for all functions so callers might
react to errors and for consistency.
2025-08-04 11:08:01 +00:00
Philip Withnall
ddf647363b Merge branch 'array_check' into 'main'
garray: Add checks to g_ptr_array_extend_and_steal

See merge request GNOME/glib!4725
2025-08-04 10:47:04 +00:00
Philip Withnall
817952c59c Merge branch 'python-tests-no-timeout' into 'main'
[RFC] Tests: do not set a timeout in Python tests

See merge request GNOME/glib!4729
2025-08-04 10:36:58 +00:00
Philip Withnall
858e6f7ab8 Merge branch 'bitlock_doc' into 'main'
gbitlock: Fix documentation issues

See merge request GNOME/glib!4728
2025-08-04 10:31:11 +00:00
Luca Bacci
12543df16f Tests: do not set a timeout in Python tests
The Meson test harness handles that for us.

With a custom timeout, meson test -t is not useful (which is
surprising for users) and interactive debugging sessions may
terminate unexepectedly.
2025-08-04 10:47:50 +02:00
Tobias Stoeckmann
d3d425271f gbitlock: Fix documentation issues
- Adds a missing colon for introspection
- Removes extra brackets
- Fixes variable name to match header definition
- Simplifies grammar
2025-08-02 22:22:04 +02:00
Tobias Stoeckmann
3c952f0b80 garray: Add checks to g_ptr_array_extend_and_steal
Make sure that arguments are not null. While internal functions are
properly protected, the code execution continues and eventually leads
to a NULL pointer dereference.
2025-08-02 10:51:55 +02:00
Michael Catanzaro
e57cbd8b47 Merge branch 'socket-listener-wait' into 'main'
tests: Add a missing poll condition to socket-listener test

See merge request GNOME/glib!4723
2025-07-31 16:05:22 -05:00
Michael Catanzaro
4147da9c99 Merge branch 'wip/pwithnall/musl-getpid' into 'main'
tests: Add missing unistd.h header to thread-pool test

See merge request GNOME/glib!4722
2025-07-31 15:26:02 -05:00
Philip Withnall
2326db507d tests: Add a missing poll condition to socket-listener test
It’s possible for the server communications to finish one main context
iteration before all of the client communications, depending on how the
kernel queues socket connection messages.

Fixes CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/5341950

```
GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL
not ok /socket-listener/accept/multi-simultaneously - GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-31 00:11:25 +01:00
Philip Withnall
cf950878f0 tests: Add missing unistd.h header to thread-pool test
For `getpid()`. On libc the definition was pulled in from somewhere
else, but musl (correctly) explicitly required the header.

Fixes this CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/5341946

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-31 00:00:16 +01:00
Michael Catanzaro
364f33c168 Merge branch '3739-socket-listener-keeps-on-giving' into 'main'
gsocketlistener: Fix accepting multiple connections in a single GMainContext iteration

Closes #3739

See merge request GNOME/glib!4717
2025-07-28 02:04:34 -05:00
Michael Catanzaro
1231a396ae Merge branch '3740-win32-error-message-docs' into 'main'
gwin32: Document fallback behaviour of g_win32_error_message()

Closes #3740

See merge request GNOME/glib!4716
2025-07-27 03:51:06 -05:00
Philip Withnall
8b82fb34c9 gsocketlistener: Fix infinite blocking when accepting connections
As the new comments in the code try to explain, this fixes infinite
blocking which could happen when calling
`g_socket_listener_accept_async()` multiple times in parallel, with more
parallel calls than there are pending incoming connections on any of the
`GSocket`s in the `GSocketListener`.

The way `g_socket_listener_accept_async()` works is to create a set of
`GSocketSource`s when it’s called, one for each of the `GSocket`s in the
`GSocketListener`. Those sources are attached to the main context,
polling for `G_IO_IN` (indicating that the socket has a pending incoming
connection to accept).

When one of the socket sources polls ready, `g_socket_accept()` is
called on it, and a new connection is created.

If there are multiple pending `g_socket_listener_accept_async()` calls,
there are correspondingly multiple `GSocketSource` sources for each
`GSocket` in the `GSocketListener`. They will all poll ready in a single
`GMainContext` iteration. The first one to be dispatched will
successfully call `g_socket_accept()`, and subsequent ones to dispatch
will do likewise until there are no more pending incoming connections.
At that point, any remaining socket sources polling ready in that
`GMainContext` iteration will call `g_socket_accept()` on a socket which
is *not* ready to accept, and that will block indefinitely, because
`GSocket` has its own blocking layer on top of `poll()`.

This is not great.

It seems like a better approach would be to disable `GSocket`’s blocking
code, because `GSocketListener` is using `poll()` directly. We only need
one source of poll truth. So, do that.

Unfortunately, that’s complicated by the fact that
`g_socket_listener_add_socket()` allows third party code to provide its
own `GSocket`s to listen on. We probably can’t unilaterally change those
to non-blocking mode, so users of that API will get what they ask for.
That might include blocking indefinitely. I’ve adjusted the
documentation to mention that, at least.

The changes are fairly simple; the accompanying unit test is less
simple. Shrug. It tests for the scenario fixed by this commit, plus the
scenario fixed by the previous commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3739
2025-07-25 16:36:33 +01:00
Philip Withnall
5ccce023de gsocketlistener: Fix a use-after-free when accepting sockets
The changes in commit 30ccfac9cf were not quite correct. The code is
structured so that a single reference to a `GTask` (and hence its
`AcceptSocketAsyncData` task data) is shared across the multiple
`GSocketSource`s which are created for a pending `accept_async()` call.

Setting `returned_yet` to true to short-circuit the remaining
`accept_ready()` dispatches in a given `GMainContext` iteration would
have worked, were it not for the fact that the code then immediately
dropped the last reference it had to the `GTask`, potentially freeing
the structure which contained `returned_yet`. Because of the async
nature of `GTask`, the exact timing of finalisation could vary.

This also meant that the other `GSocketSource`s were not destroyed until
an unknown time later.

Improve on that by explicitly destroying the other `GSocketSource`s as
soon as the first one returns an accepted socket. This causes
`GMainContext` to skip dispatching them, even within the same
`GMainContext` iteration. It also means the separate `returned_yet`
member is unnecessary.

This should fix the immediate issue seen in #3739. However, while
testing it I found a further issue which will be fixed in a following
commit, before I add a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3739
2025-07-25 16:04:44 +01:00
Philip Withnall
0558fc541e gsocketlistener: Factor out code to add sockets to internal structures
This introduces no functional differences, just makes some upcoming
changes clearer.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3739
2025-07-25 16:04:37 +01:00
Philip Withnall
4e1fcbffbd gsocket: Handle cancellation of connect() in non-blocking mode
As with the previous commit, but for `g_socket_connect()`, which is the
other cancellable use of `g_socket_condition_wait()` in the file.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-25 15:29:51 +01:00
Philip Withnall
e6a1eacfe1 gsocket: Handle cancellation of accept() in non-blocking mode
Currently, if `g_socket_accept()` is called with a cancelled cancellable
and the socket is in non-blocking mode, `G_IO_ERROR_CANCELLED` is not
returned, because the cancellable is only checked in the call to
`g_socket_condition_wait()`, which only happens in blocking mode.

Fix that and add a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3739
2025-07-25 15:20:13 +01:00
Philip Withnall
3d0b142bf6 gwin32: Document fallback behaviour of g_win32_error_message()
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3740
2025-07-25 10:23:04 +01:00
Philip Withnall
764aaae391 gwin32: Reformat documentation for g_win32_error_message()
Port it to gi-docgen format and improve it to match the documentation
style guide.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3740
2025-07-25 10:21:04 +01:00
Philip Withnall
b142f130b1 Merge branch 'memory-monitor-race' into 'main'
tests: Connect to GMemoryMonitor signals earlier

See merge request GNOME/glib!4709
2025-07-25 00:24:47 +00:00
Philip Withnall
8dbc637ab7 Merge branch 'kate/fix-test-error' into 'main'
Fix test error for GMemoryMonitor

See merge request GNOME/glib!4713
2025-07-23 12:40:10 +00:00
Philip Withnall
341cd08a42 gmemorymonitorbase: Emit signals in the global default main context
`GMemoryMonitor` is a singleton, which means we can’t use the usual
approach of emitting signals in the thread-default main context from the
time of construction of the object.

The next best thing is to emit them in the global default main context.
For many applications, this will be exactly what they are expecting. For
multi-threaded applications, they will need to implement their own
thread safety in the signal handler, but they would have to do that
anyway.

Currently, the signals are emitted in the GLib worker thread (for the
PSI and poll implementations of `GMemoryMonitor`) — this is the worst
option, because it means that third party signal handlers could block
the worker thread (which is precisely what the worker thread is meant to
avoid).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-07-23 13:27:58 +01:00
Kate Hsuan
7e7c452d4a gio: gmemorymonitorpsi: Fix test error since memory free ratio test can be skipped when performing the test
The memory free ratio test can be skipped when we run the test. If
proc_override is TRUE and proc path is overridden, the memory free
ratio test can be skipped.
2025-07-23 20:13:19 +08:00
Kate Hsuan
e9b0fe2879 gio: gmemorymonitorpoll: Fix unit test error since the callback returns earlier
The value overriding has to be set before testing the value and returning
the callback. Otherwise, the callback can't emit a signal to the test
program.
2025-07-23 20:09:26 +08:00