Commit Graph

27372 Commits

Author SHA1 Message Date
Philip Withnall
c0bdc61879 meson: Export HAVE_FREE_SIZED in glibconfig.h for use in g_free()
This allows the `g_free()` wrapper introduced in the previous commit to
only be defined if `free_sized()` is actually available to improve
performance.

This avoids passing an allocation size to every `g_free()` call if it’s
not going to be used, saving a register store instruction each time.

Suggested by Marco Trevisan in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3252#note_1660032

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-30 13:45:05 +01:00
Marco Trevisan (Treviño)
c580b5c2f4 gmem: Add an inline definition of g_free() to automatically use g_free_sized()
When using GCC we can take the advantage of __builtin_object_size() to
know the allocated size of a memory area, this generally only works when
some optimization level enabled (-O1 seems enough here) and can provide
us with memory size information for lower-level optimizations.
2023-05-30 13:43:25 +01:00
Philip Withnall
ad464d5563 Merge branch 'main' into 'main'
gio/tests/portal-support: Fix snap test ordering race

Closes #3020

See merge request GNOME/glib!3454
2023-05-30 12:29:06 +00:00
Philip Withnall
0196a36022 Merge branch 'more-atomic-exchange-full' into 'main'
gdataset, gobject: Use atomic compare and exchange full to set pointers

See merge request GNOME/glib!3426
2023-05-30 11:59:40 +00:00
Marco Trevisan (Treviño)
ea904fba1a gresource: Use compare and exchange full to get registered resources 2023-05-30 12:34:41 +01:00
Philip Withnall
28f83c9cf7 gresource: Ensure lazy_register_resources is always accessed atomically
On some platforms, pointer-sized reads are not necessarily atomic, so we
always need to use the correct atomic access primitives.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-30 12:33:48 +01:00
Richard Purdie
c63cf19d9a gio/tests/portal-support: Fix snap test ordering race
When the gnome test runner executes the tests, the test appear to execute in disk
order. This means it sometimes works and sometimes we see breakage in portal-support-snap
and portal-support-snap-classic.

The issue is that some tests create config files but some don't. If they run
in the wrong order, tests see config files they shouldn't and break.

Fix this by deleting the files after each test run, properly cleaning up after
themselves. The cleanup code is based upon gtestutils.c:rm_rf().

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-05-30 12:28:45 +01:00
Philip Withnall
153c7f7b99 Merge branch 'wip/p3732/truncate-middle' into 'main'
gutf8: Add a g_utf8_truncate_middle() function

See merge request GNOME/glib!3440
2023-05-30 11:02:03 +00:00
Sabri Ünal
49971ee217 Update Turkish translation 2023-05-26 23:05:00 +00:00
Philip Withnall
57087ff42d Merge branch 'remove-action-entries' into 'main'
gactionmap: Add g_action_map_remove_action_entries()

See merge request GNOME/glib!3450
2023-05-26 09:47:30 +00:00
Guido Günther
b3b23072f3 gactionmap: Add g_action_map_remove_action_entries()
Since we have a convenience method to add actions let's allow to remove
them just as easily. This makes resource cleanup as simple as initially
adding the entries.
2023-05-26 10:30:40 +01:00
Guido Günther
ac840b954f gactionmap: Move declaration of loop var in g_action_map_add_action_entries() 2023-05-25 17:45:17 +02:00
Guido Günther
596fec811d gactionmap: Check for < 0 in g_action_map_add_action_entries()
Assume that all negative values mean `NULL` terminated. Everything else
will cause a disaster anyway.
2023-05-25 17:43:09 +02:00
Patrick Griffis
ec9e7b5487 Merge branch 'more-docs' into 'main'
docs: Move README.win32.md to the docs folder and update CONTRIBUTING.md

See merge request GNOME/glib!3449
2023-05-25 13:56:43 +00:00
Peter Eisenmann
cd3837174b gutf8: Add a g_utf8_truncate_middle() function
Adds a helper to truncate UTF8 strings in the middle, allowing to make
them fit certain size constraints.

This function is modeled after similar functionality that has existed
since 2008 in nautilus and in eel before that.
2023-05-25 00:36:56 +02:00
Philip Withnall
716bd4dfd7 docs: Update meson example commands
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:35:33 +01:00
Philip Withnall
c217e5905c docs: Don’t mention pushing directly to origin
If people do that, it clutters the place up with branches which are not
deleted-on-merge by default. Better to use their own forks.

And the people who are in a position to be able to push directly to
`origin` are not going to be reading the `CONTRIBUTING.md` file, so this
paragraph is noise to most readers anyway.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:34:57 +01:00
Philip Withnall
5212171d0e docs: Suggest that new APIs don’t have to be in GLib
GLib can’t grow forever, so we should really only be accepting APIs
which are useful across a variety of projects and which couldn’t easily
live in a separate library.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:33:22 +01:00
Philip Withnall
d608ceedb3 docs: Update security instructions in CONTRIBUTING.md
Point strongly towards `SECURITY.md` so we are not maintaining security
instructions in multiple places.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:32:54 +01:00
Philip Withnall
c9ea59b888 docs: Mention Matrix rather than IRC in CONTRIBUTING.md
GNOME as a whole has moved to Matrix.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:32:39 +01:00
Philip Withnall
f6f250fc38 docs: Move README.win32.md to the docs folder
It’s a bit confusing to have two files called `README`, especially given
that `README.win32.md` only contains build instructions and none of the
other overview/contribution/bug reporting information that `README.md`
contains.

It feels like these would be better organised by having one top-level
`README.md`, and pointing to the Windows build instructions from there.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-24 16:19:47 +01:00
Philip Withnall
ecbe360a38 Merge branch '3003-glib-compile-schemas-failed' into 'main'
glib-compile-resources: Fix non-ASCII arg parsing on Windows

Closes #3003

See merge request GNOME/glib!3446
2023-05-23 17:16:27 +00:00
Daniyar Tleulin
49537e298c glib-compile-schemas: Fix non-ASCII arg parsing on Windows
When the source directory contains non-ASCII symbols,
argument parsing previously failed on MINGW64.

Fixes: #3003
2023-05-23 16:49:21 +06:00
Daniyar Tleulin
0305d237dd glib-compile-resources: Fix non-ASCII arg parsing on Windows
When the source directory contains non-ASCII symbols,
argument parsing previously failed on MINGW64.

Fixes: #3003
2023-05-23 16:48:41 +06:00
Philip Withnall
00826caacf Merge branch 'sonnyp/g_file_new_build_filenamev' into 'main'
gio: Add g_file_new_build_filenamev

See merge request GNOME/glib!3442
2023-05-23 10:14:28 +00:00
Sonny Piers
0b73d72a44 gio: Add g_file_new_build_filenamev 2023-05-23 10:14:28 +00:00
Philip Withnall
9f4f8702e5 Merge branch 'environ-fixes' into 'main'
tests: Add descriptions to environment tests

See merge request GNOME/glib!3410
2023-05-22 17:16:43 +00:00
Philip Withnall
b8801b7cf9 Merge branch 'fixes_for_gdb_python_helper' into 'main'
gobject_gdb.py: support gsignal fastpath and detect more marshallers

See merge request GNOME/glib!3437
2023-05-22 16:57:33 +00:00
Philip Withnall
109dc30581 tests: Add descriptions to environment tests
Prompted by !500.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2023-05-22 17:33:29 +01:00
Philip Withnall
fa5a99bffd Merge branch 'g-string-new-take-since' into 'main'
gstring: Add `Since` marker to `g_string_new_take()`

See merge request GNOME/glib!3439
2023-05-22 15:45:05 +00:00
Sebastian Dröge
dae7c2a706 gstring: Add Since marker to g_string_new_take() 2023-05-21 10:04:29 +03:00
Nelson Benítez León
f09805fd97 gobject_gdb.py: small style change to signal name
This is a minor style change to better differentiate
signal name by enclosing it in single quotes.

Before:
<emit signal event on instance 0xf14e60 [GdkWaylandToplevel]>

After:
<emit signal 'event' on instance 0xf14e60 [GdkWaylandToplevel]>
2023-05-20 02:30:07 +01:00
Nelson Benítez León
3e9db78656 gobject_gdb.py: support gsignal fastpath and detect more marshallers
- Commit f02ec2f2de added a gsignal fastpath where g_closure_invoke_va()
is directly called from g_signal_emit_valist() skipping signal_emit_unlocked_R()
altogether which it's the function used by gobject_gdb.py to detect
signal emission.

So we update gobject_gdb.py to also detect signals which use this
g_closure_invoke_va() fastpath.

- We also update the existent code to detect marshallers to also
include these:

surface_event_marshaller()
gdk_surface_event_marshallerv()
g_type_class_meta_marshal()
g_type_class_meta_marshalv()

This allow us that for signal emissions which use those marshallers
to keep showing the signal handler frame just after the
<emit signal blabla> line.
2023-05-20 02:30:00 +01:00
Marco Trevisan
13536dc68d Merge branch 'wip/carlosg/cancel-local-file-enumeration' into 'main'
gio: Check cancellable iterating local file enumerator

See merge request GNOME/glib!3438
2023-05-19 13:42:42 +00:00
Carlos Garnacho
4641b02ca2 gio: Add test for local enumerator cancellation
Check that the enumerator is able to cancel if told so.
2023-05-19 11:53:18 +00:00
Carlos Garnacho
99571c42d5 gio: Check cancellable iterating local file enumerator
In the typical `while (g_file_enumerator_next_file ())` patterns,
there is nothing much checking whether the operation was cancelled
on the GIO side. Unless the user checks for the case, this means
local enumerators always run to completion even if cancelled.

Fix this by checking the cancellable state explicitly for local
enumerators, so there are oportunities for bailing out early if
the enumerator is going through a very large directory.
2023-05-19 11:53:18 +00:00
Michael Catanzaro
eaaa2b5f66 Merge branch 'th/child-watch-waitpid' into 'main'
[th/child-watch-waitpid] fix race with waitpid() and child watcher sources

See merge request GNOME/glib!3353
2023-05-18 19:10:42 +00:00
Thomas Haller
3694dac983 gmain: ensure boolean value in g_child_watch_check() is strictly 0 or 1
No problem in practice, but it seems nice to ensure that a gboolean is
always either FALSE or TRUE.
2023-05-18 11:26:33 +02:00
Thomas Haller
d5d6ef8f1b gmain: drop redundant using_pidfd field from GChildWatchSource
It's redundant, which leads to impossible code like:

   if (child_watch_source->using_pidfd)
     {
       if (child_watch_source->poll.fd >= 0)
         close (child_watch_source->poll.fd);
2023-05-18 11:26:33 +02:00
Thomas Haller
cecbb25eeb gmain: fix race with waitpid() and child watcher sources
GChildWatchSource uses waitpid(), among pidfd and GetExitCodeProcess().
It thus only works for child processes which the user must ensure to
exist and not being reaped yet. Also, the user must not kill() the PID
after the child process is reaped and must not race kill() against
waitpid(). Also, the user must not call waitpid()/kill() after the child
process is reaped.

Previously, GChildWatchSource would call waitpid() already when adding
the source (g_child_watch_source_new()) and from the worker thread
(dispatch_unix_signals_unlocked()). That is racy:

- if a child watcher is attached and did not yet fire, you cannot call
  kill() on the PID without racing against the PID being reaped on the
  worker thread. That would then lead to ESRCH or even worse, killing
  the wrong process.

- if you g_source_destroy() the source that didn't fire yet, the user
  doesn't know whether the PID was reaped in the background. Any
  subsequent kill()/waitpid() may fail with ESRCH/ECHILD or even address
  the wrong process.

The race is most visible on Unix without pidfd support, because then the
process gets reaped on the worker thread or during g_child_watch_source_new().
But it's also with Windows and pidfd, because we would have waited for
the process in g_child_watch_check(), where other callbacks could fire
between reaping the process status and emitting the source's callback.

Fix all that by calling waitpid() right before dispatching the callback.
2023-05-18 11:26:33 +02:00
Thomas Haller
cdda194844 gmain: remove unnecessary initialization of *timeout in prepare() callbacks
Note that the prepare callback only has one caller, which pre-initializes
the timeout argument to -1. That may be an implementation detail and not
publicly promised, but it wouldn't make sense to do it any other way in
the caller.

Also, note that g_unix_signal_watch_prepare() and the UNIX branch of
g_child_watch_prepare() already relied on that.
2023-05-18 11:26:33 +02:00
Thomas Haller
30b5418608 gmain: remove unnecessary initialization of source_timeout in g_main_context_prepare_unlocked()
Note that the variable source_timeout is already initialized upon
definition, at the beginning of the block.

It's easy to see, that no code changes the variable between the variable
definition, and the place where it was initialized. It was thus
unnecessary.

It's not about dropping the unnecessary code (the compiler could do that
just fine too). It's that there is the other branch of the "if/else", where
the variable is also not initialized. But the other branch also requires
that the variable is in fact initialized to -1, because prepare()
callbacks are free not to explicitly set the output value. So both
branches require the variable to be initialized to -1, but only one of
them did. This poses unnecessary questions about whether anything is
wrong. Avoid that by dropping the redundant code.
2023-05-18 11:26:33 +02:00
Thomas Haller
a71b0c0461 gmain: simplify handling child watchers in dispatch_unix_signals_unlocked()
- if a child watch source has "using_pidfd", it is never linked in the
  unix_child_watches list. Drop that check.
- replace the deep nested if, with an early "continue" in the loop,
  if we detect there is nothing to do. It makes the code easier to
  read.
2023-05-18 11:26:33 +02:00
Thomas Haller
9315a211fa gmain: unify win/unix implementations for child watcher
Let's move the difference between the win/unix implementations closer to
where the difference is. Thereby, we easier see the two implementations
side by side. Splitting it at a higher layer makes the code harder to
read.

This is just a preparation for what comes next.
2023-05-18 11:26:33 +02:00
Thomas Haller
d1e558f492 gmain/tests: add unit test for g_child_watch_add() reaping processes without notifying
The test currently tests broken behavior. It will be fixed next.
2023-05-18 11:26:33 +02:00
Philip Withnall
54d1ebfc37 Merge branch 'ebassi/task-pretty-print-ignore-gir' into 'main'
Ignore g_task_print_alive_task() when introspecting GIO

See merge request GNOME/glib!3435
2023-05-16 14:50:21 +00:00
Emmanuele Bassi
20142de034 Ignore g_task_print_alive_task() when introspecting GIO
The `__GTK_DOC_IGNORE__` check is not enough for g-ir-scanner: we need
to check for `__GI_SCANNER__` as well.
2023-05-16 13:33:19 +01:00
Philip Withnall
ec8856d7d6 Merge branch 'wip/p3732/g-string-new-steal' into 'main'
gstring: add g_string_new_take

See merge request GNOME/glib!3423
2023-05-16 12:04:37 +00:00
Peter Eisenmann
ac4d1e2686 docs: unify "dynamic memory needed" explanations
All `_take` method constructors require dynamic memory, this unifies
theses explanation texts.
2023-05-16 11:27:45 +01:00
Peter Eisenmann
afdab4f493 gstring: add g_string_new_take
Adds a GString constructor that takes over ownership of an existing,
dynamically allocated, string.
2023-05-16 11:27:45 +01:00