Commit Graph

25434 Commits

Author SHA1 Message Date
Philip Withnall
8e9f238667 glocalfilemonitor: Skip event handling if the source has been destroyed
This should prevent unbounded growth of the `event_queue` in the
unlikely case that the `GSource` is removed from its `GMainContext` and
destroyed separately from the `GFileMonitor`.

I’m not sure if that can currently happen, but it could with future
refactoring, so it’s best to address the possibility now while we’re
thinking about this bit of code.

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

Helps: #1941
2022-05-31 12:24:13 +01:00
Benjamin Berg
ee4d93c6fd glocalfilemonitor: Avoid file monitor destruction from event thread
Taking a reference to the GFileMonitor when handling events may cause
object destruction from th worker thread that calls the function. This
condition happens if the surrounding code drops the otherwise last
reference ot the GFileMonitor. The series of events causes destruction
from an unrelated worker thread and also triggers g_file_monitor_cancel
to be called from g_file_monitor_source_handle_event.

For the inotify backend, this results in a deadlock as cancellation
needs to take a lock that protects data structures from being modified
while events are dispatched.

One alternative to this approach might be to add an RCU (release, copy,
update) approach to the lists contained in the wd_dir_hash and
wd_file_hash hash tables.

Fixes: #1941

An example stack trace of this happening is:

Thread 2 (Thread 0x7fea68b1d640 (LWP 260961) "gmain"):
 #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
 #1  0x00007fea692215dc in g_mutex_lock_slowpath (mutex=mutex@entry=0x7fea6911e148 <g.inotify_lock_lock>) at ../glib/gthread-posix.c:1493
 #2  0x00007fea69222062 in g_mutex_lock (mutex=mutex@entry=0x7fea6911e148 <g.inotify_lock_lock>) at ../glib/gthread-posix.c:1517
 #3  0x00007fea6908025a in _ih_sub_cancel (sub=0x1492620) at ../gio/inotify/inotify-helper.c:131
 #4  0x00007fea6907f9da in g_inotify_file_monitor_cancel (monitor=0x14a3550) at ../gio/inotify/ginotifyfilemonitor.c:75
 #5  0x00007fea68fae959 in g_file_monitor_cancel (monitor=0x14a3550) at ../gio/gfilemonitor.c:241
 #6  0x00007fea68fae9dc in g_file_monitor_dispose (object=0x14a3550) at ../gio/gfilemonitor.c:123
 #7  0x00007fea69139341 in g_object_unref (_object=<optimized out>) at ../gobject/gobject.c:3636
 #8  g_object_unref (_object=0x14a3550) at ../gobject/gobject.c:3553
 #9  0x00007fea6907507a in g_file_monitor_source_handle_event (fms=0x14c3560, event_type=<optimized out>, child=0x7fea64001460 "spawned-1", rename_to=rename_to@entry=0x0, other=other@entry=0x0, event_time=<optimized out>) at ../gio/glocalfilemonitor.c:457
 #10 0x00007fea6907fe0e in ih_event_callback (event=0x7fea64001420, sub=0x1492620, file_event=<optimized out>) at ../gio/inotify/inotify-helper.c:218
 #11 0x00007fea6908075c in ip_event_dispatch (dir_list=dir_list@entry=0x14c14c0, file_list=0x0, event=event@entry=0x7fea64001420) at ../gio/inotify/inotify-path.c:493
 #12 0x00007fea6908094e in ip_event_dispatch (event=0x7fea64001420, file_list=<optimized out>, dir_list=0x14c14c0) at ../gio/inotify/inotify-path.c:448
 #13 ip_event_callback (event=0x7fea64001420) at ../gio/inotify/inotify-path.c:548
 #14 ip_event_callback (event=0x7fea64001420) at ../gio/inotify/inotify-path.c:530
 #15 0x00007fea69081391 in ik_source_dispatch (source=0x14a2bf0, func=0x7fea69080890 <ip_event_callback>, user_data=<optimized out>) at ../gio/inotify/inotify-kernel.c:327
 #16 0x00007fea691d0824 in g_main_dispatch (context=0x14a2cc0) at ../glib/gmain.c:3417
 #17 g_main_context_dispatch (context=0x14a2cc0) at ../glib/gmain.c:4135
 #18 0x00007fea691d0b88 in g_main_context_iterate (context=context@entry=0x14a2cc0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4211
 #19 0x00007fea691d0c2f in g_main_context_iteration (context=0x14a2cc0, may_block=may_block@entry=1) at ../glib/gmain.c:4276
 #20 0x00007fea691d0c81 in glib_worker_main (data=<optimized out>) at ../glib/gmain.c:6176
 #21 0x00007fea691f9c2d in g_thread_proxy (data=0x1487cc0) at ../glib/gthread.c:827
 #22 0x00007fea68d93b1a in start_thread (arg=<optimized out>) at pthread_create.c:443
 #23 0x00007fea68e18650 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
2022-05-31 12:24:13 +01:00
Sebastian Dröge
745148b453 Merge branch 'wip/biggio/fix-socket-enumerator-annotation' into 'main'
gsocketaddressenumerator: add nullable annotation to the result of `next`

See merge request GNOME/glib!2701
2022-05-31 10:16:30 +00:00
Matteo Biggio
ac3fc84ff4 gsocketaddressenumerator: add nullable annotation to the result of next
The returned `SocketAddress` is going to be NULL when the stream of
socket addresses is finished
2022-05-31 11:34:02 +02:00
Yosef Or Boczko
4643276972 Update Hebrew translation 2022-05-30 18:32:40 +00:00
Philip Withnall
cf988d2a06 Merge branch 'final-type-speedup' into 'main'
gtype: Speed up type checks for final types

See merge request GNOME/glib!2700
2022-05-30 11:01:33 +00:00
Matthias Clasen
0ddea2d8e2 gtype: Speed up type checks for final types
If a type is final, it is enough to compare the
instance type for equality, since it can't have
a derived type.
2022-05-30 00:10:32 -04:00
Philip Withnall
04803944a3 Merge branch 'skip-debug-only-tests' into 'main'
testsuite: Make tests not fail in !debug builds

Closes #2656

See merge request GNOME/glib!2699
2022-05-28 19:53:22 +00:00
Matthias Clasen
3db1d260ee testsuite: Make tests not fail in !debug builds
Some of our tests rely on on warning that only
occur in debug builds. Skip them in non-debug
builds.

Fixes: #2656
2022-05-28 08:02:16 -04:00
Emmanuel Fleury
ee67ca43cd Move tests/gobject/testgobject.c to gobject/tests/basics-gobject.c
Helps issue #1434
2022-05-27 22:31:13 +02:00
Emmanuel Fleury
ccfabc0f99 Convert tests/gobject/testgobject.c to glib test framework 2022-05-27 22:19:42 +02:00
Philip Withnall
43ac055a46 2.73.0
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 18:24:35 +01:00
Philip Withnall
6fdc4275f3 Merge branch 'nano' into 'main'
Add functionality to preserve nanosecond timestamps

Closes #369

See merge request GNOME/glib!2176
2022-05-27 17:01:22 +00:00
Philip Withnall
18c0088678 tests: Fix a memory leak when abandoning a file creation time test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 17:45:03 +01:00
Philip Withnall
b7b10cc7e0 tests: Add additional tests for nanosecond precision file timestamps
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #369
2022-05-27 17:45:03 +01:00
nitinosiris
b33ef610de Add functionality to preserve nanosecond timestamps
file copy doesn't preserve nanosecond timestamps

Closes #369
2022-05-27 17:03:35 +01:00
Philip Withnall
7ad6b05458 gfileinfo: Split out a g_file_info_remove_value() helper function
This introduces no functional changes but will make refactoring a bit
easier in the following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 16:56:10 +01:00
Philip Withnall
a922f2f2c7 Merge branch 'th/g-ptr-array-set-null-terminated' into 'main'
array: add support for g_ptr_array_null_terminated()

See merge request GNOME/glib!1485
2022-05-27 15:08:50 +00:00
Thomas Haller
ee247c0a2d array: add support for %NULL termination in GPtrArray
GArray supports a "zero_terminated" flag, but GPtrArray doesn't.
This is odd, because especially for a pointer array it makes sense
to have a %NULL sentinel. This would be for example useful to track
or construct a strv array with a GPtrArray.

As workaround for this missing feature you could use a GArray instead
(ugly) or to explicitly add the %NULL element. However the latter increases
the "len" of the array, which can be problematic if you want to still use
the GPtrArray for other purposes.

Add API for marking a GPtrArray as %NULL terminated. In that case, the
API will ensure that there is always a valid %NULL sentinel after the
array. Note that the API does not enforce that a %NULL terminated API
actually has any data allocated. That means, even with a %NULL terminated
array, pdata can still be %NULL (only if len is zero).

Add g_ptr_array_new_null_terminated() constructor. The null-terminated flag
cannot be cleared. Once the GPtrArray is flagged to be %NULL terminated, it
sticks. The purpose is that once a user checks whether a GPtrArray instance
is safe to be treated as a %NULL terminated array, the decision does
not need to be re-evaluated.

Also add a g_ptr_array_is_null_terminated(). That is useful because it
allows you to check whether a GPtrArray created by somebody else is safe
to use as a %NULL terminated array. Since there is no API to make an
array not %NULL terminated anymore, this is not error prone.

The new flag is tracked as a guint8 in GRealPtrArray. On common 64 bit
architectures this does not increase the size of the struct as it fits
in an existing hole. Note that this is not a bitfield because it's
probably more efficient to access the entire guint8. However, there is
still a 3 bytes hole (on common 32 and 64 architectures), so if we need
to add more flags in the future, we still have space for 24 bits,
despite the new flag not being a bitfield.

The biggest downside of the patch is the runtime overhead that most
operations now need to check whether %NULL termination is requested.

Includes some tweaks and additional tests by Philip Withnall.

https://gitlab.gnome.org/GNOME/glib/-/issues/353
2022-05-27 15:27:19 +01:00
Philip Withnall
a9321c3652 garray: Add missing (transfer full) introspection annotations
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 14:27:52 +01:00
Emmanuele Bassi
1c7966b58e Merge branch 'source-once-no-allocs' into 'main'
gmain: Refactor idle-once and timeout-once to avoid a closure allocation

See merge request GNOME/glib!2693
2022-05-27 12:51:15 +00:00
Philip Withnall
6db112f9a7 gmain: Refactor idle-once and timeout-once to avoid a closure allocation
Instead store a bit inside `GTimeoutSource` and `GIdleSource` to
indicate that they are one-shot sources, and that their callbacks have a
different type and should always be assumed to return `G_SOURCE_REMOVE`.

This should make one-shot idle and timeout sources a teeny weeny little
bit cheaper to set up.

From a suggestion here: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2684#note_1462917

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
c1477f79e7 gmain: Factor out common GIdleSource code
This allows it to be reused and extended (internally) a little more.
This commit introduces no functional changes, but allows for more easy
additions in a following commit.

It introduces `GIdleSource` as a simple wrapper around `GSource`, which
will be extended in a following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
af02a614a2 gmain: Factor out common GTimeoutSource code
This allows it to be reused and extended (internally) a little more.
This commit introduces no functional changes, but allows for more easy
additions in a following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
93bf87528d Merge branch 'ebassi/source-once' into 'main'
Add one-shot idle and timeout functions

See merge request GNOME/glib!2684
2022-05-27 12:25:51 +00:00
Philip Withnall
c1f94cd1a5 gmain: Minor documentation updates to idle-once and timeout-once funcs
As suggested on !2684.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 12:58:10 +01:00
Emmanuele Bassi
50c316ef36 Port various timeout/idle callbacks to the once API
So we excercise it in our test coverage.
2022-05-27 12:58:10 +01:00
Emmanuele Bassi
12571a0821 Add one-shot idle and timeout functions
Many idle and timeout sources are installed as "one shot": called once
and immediately removed. While it's easy to write a simple callback that
returns G_SOURCE_REMOVE, it would also be useful to have some sort of
"visual" marker when reading the code; a way to immediately see that a
callback (which may be defined elsewhere in the code) is meant to be
invoked just once.

Includes additional unit tests by Philip Withnall.
2022-05-27 12:57:55 +01:00
Philip Withnall
87646793e7 tests: Drop redundant collate test data files
These were made redundant in 5b08ef84e4
and cddce179f5,
when the test data was moved into the test program as strings.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-26 19:50:05 +01:00
Philip Withnall
81fd75b4bb Merge branch 'move_gobject_tests' into 'main'
Moving gobject tests from tests/gobjects to gobjects/tests

See merge request GNOME/glib!2550
2022-05-26 18:37:19 +00:00
Emmanuel Fleury
4e02be948b Moving gobject tests from tests/gobjects to gobjects/tests
The test files concerned are:

- tests/gobjects/accumulator.c
- tests/gobjects/defaultiface.c
- tests/gobjects/deftype.c
- tests/gobjects/dynamictype.c
- tests/gobjects/override.c
- tests/gobjects/references.c
- tests/gobjects/signals.c
- tests/gobjects/singleton.c

Related to issue #1434
2022-05-26 19:13:19 +01:00
Emmanuel Fleury
a8baa8d0d8 Convert tests/gobject/singleton.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
d0577293a2 Convert tests/gobject/signals.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
2767e1614d Convert tests/gobject/references.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
662d8458f5 Convert tests/gobject/override.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
17ddf79e1d Convert tests/gobject/dynamictype.c to glib test framework 2022-05-26 19:13:16 +01:00
Emmanuel Fleury
b61d3edc33 Convert tests/gobject/defaultiface.c to glib test framework 2022-05-26 19:12:15 +01:00
Philip Withnall
d1cb96b5e3 Merge branch 'refcount_tests' into 'main'
Moving tests/refcount/ directory to gobject/tests/

See merge request GNOME/glib!2553
2022-05-26 18:03:00 +00:00
Emmanuel Fleury
d378108b10 Convert tests/gobject/accumulator.c to glib test framework 2022-05-26 18:51:57 +01:00
Philip Withnall
ed84b8f468 tests: Port GObject tests from g_thread_create() to g_thread_new()
To avoid warnings about deprecated functions.

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

Helps: #1434
2022-05-26 18:37:35 +01:00
Emmanuel Fleury
70401ae8c3 Moving tests/refcount/ directory to gobject/tests/
Modified by Philip Withnall to omit the subdirectory and drop the
`refcount` suite as both seem like unnecessary over-categorisation.

Related to issue #1434
2022-05-26 18:37:35 +01:00
Emmanuel Fleury
b65260abe4 Convert tests/refcount/signals.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
d97c1a148e Convert tests/refcount/properties4.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
94ef5ae4c7 Convert tests/refcount/properties3.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
ddadb89d7c Convert tests/refcount/properties2.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
76fccc78c0 Convert tests/refcount/properties.c to glib test framework 2022-05-26 18:37:34 +01:00
Emmanuel Fleury
715ff4ea29 Convert tests/refcount/objects2.c to glib test framework 2022-05-26 18:37:34 +01:00
Emmanuel Fleury
62b5fe5991 Convert tests/refcount/objects.c to glib test framework 2022-05-26 18:37:34 +01:00
Philip Withnall
ce585ba4d2 Merge branch 'slice-test' into 'main'
Slice test

See merge request GNOME/glib!2579
2022-05-26 17:01:52 +00:00
Philip Withnall
8625d8144b Merge branch 'module_tests' into 'main'
Move tests/module-test.c to gmodules/tests/

See merge request GNOME/glib!2660
2022-05-26 16:42:02 +00:00