Commit Graph

31715 Commits

Author SHA1 Message Date
Thomas Haller
dadb759c65 gobject: invoke g_object_weak_ref() one-by-one during destruction
Previously, at two places (in g_object_real_dispose() and shortly before
finalize()), we would call

    g_datalist_id_set_data (&object->qdata, quark_weak_notifies, NULL);

This clears @quark_weak_notifies at once and then invokes all
notifications.

This means, if you were inside a notification callback and called
g_object_weak_unref() on the object for *another* weak-reference, then
an exception failed:

  GLib-GObject-FATAL-CRITICAL: g_object_weak_unref_cb: couldn't find weak ref 0x401320(0x16b9fe0)

Granted, maybe inside a GWeakNotify you shouldn't call much of anything
on where_the_object_was. However, unregistering things (like calling
g_object_weak_unref()) should still reasonably work.

Instead, now remove each weak notification one by one and invoke it.

As we now invoke the callbacks in a loop, if a callee registers a new
callback, then that one gets unregistered right away too.  Previously,
we would during g_object_real_dispose() only notify the notifications
that were present when the loop starts. This is similar to what happens
in closure_array_destroy_all(). This is a change in behavior, but it
will be fixed in a separate follow-up commit.

https://gitlab.gnome.org/GNOME/glib/-/issues/1002
2025-05-07 21:29:37 +00:00
Thomas Haller
af508f91b1 gobject: add internal WeakRefTuple helper structure
This is already useful and will be more useful later.
2025-05-07 21:29:37 +00:00
Thomas Haller
d2e08b7dfe gobject: preserve order of weak notifications in g_object_weak_unref()
g_object_weak_unref() would have done a fast-removal of the entry, which
messes up the order of the weak notifications.

During destruction of the object we emit the weak notifications. They
are emitted in the order in which they were registered (FIFO). Except,
when a g_object_weak_unref() messes up the order. Avoid that and
preserve the order.

Now, do a memmove(), which is O(n). But note that we already track weak
references in a flat array that requires a O(n) linear search. Thus,
g_object_weak_unref() was already O(n) and that didn't change. More
importantly, users are well advised to limit themselves to a reasonably
small number of weak notifications. And for small n, the linear search
and the memmove() is an efficient solution.
2025-05-07 21:29:37 +00:00
Thomas Haller
7743c7aaa2 gobject/tests: add test for g_object_weak_ref() 2025-05-07 21:29:37 +00:00
Michael Catanzaro
3548c4ae53 Merge branch 'th/gobject-no-object-locks-pt1-notify' into 'main'
[th/gobject-no-object-locks-pt1-notify] use `g_datalist_id_update_atomic()` instead of OPTIONAL_BIT_LOCK_NOTIFY

See merge request GNOME/glib!4185
2025-05-06 21:24:32 +00:00
Michael Catanzaro
22f57fce78 Merge branch 'th/gobj-doc-weakref' into 'main'
[th/gobj-doc-weakref] clear #GWeakRef earlier in g_object_run_dispose() and reword docs about #GWeakRef

See merge request GNOME/glib!4586
2025-05-06 21:23:52 +00:00
Philip Withnall
549a966b46 Merge branch 'add-g-log-get-always-fatal' into 'main'
gmessages: Add 'g_log_get_always_fatal()' for use in custom log writers

Closes #2544

See merge request GNOME/glib!4546
2025-05-06 12:15:08 +00:00
Philip Withnall
a4b4fb2bea Merge branch 'fix-garray' into 'main'
garray: Fix annotations

See merge request GNOME/glib!4601
2025-05-06 12:02:30 +00:00
Philip Withnall
87f69dd5d1 Merge branch 'g_slist_doc_update' into 'main'
gslist: Improve documentation for append / prepend / insert methods

See merge request GNOME/glib!4619
2025-05-06 12:02:02 +00:00
Philip Withnall
634085c39a Merge branch 'tzset' into 'main'
gdate: Call tzset before localtime_r

Closes gnome-control-center#3363

See merge request GNOME/glib!4617
2025-05-06 11:21:15 +00:00
5dma
fef650ca86 gslist: Improve documentation for append / prepend / insert methods
The new descriptions are sourced from the parallel methods g_list_append,
g_list_prepend and g_list_insert.

Refer: https://discourse.gnome.org/t/return-value-of-g-slist-append/27921
2025-05-06 12:01:20 +01:00
Philip Withnall
c0ada13e0b docs: Fix broken links to ‘Running GLib Applications’ docs page
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2025-05-06 11:58:50 +01:00
sid
13a6f0ee51 gmessages: Add 'g_log_get_always_fatal()' for use in custom log writers
Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2544
2025-05-06 11:58:47 +01:00
Alessandro Astone
664accc444 gdate: Call tzset before localtime_r
From `man 3 ctime`:
  According to POSIX.1, localtime() is required to behave as though tzset(3)
  was called, while localtime_r() does not have this requirement.
  For portable code, tzset(3) should be called before localtime_r().
2025-05-06 11:56:43 +01:00
Michael Catanzaro
cb2267eea1 Merge branch 'wip/pwithnall/wsign-conversion2a' into 'main'
gobject, girepository: Fix several -Wsign-conversion warnings on macOS

See merge request GNOME/glib!4606
2025-05-05 18:36:32 +00:00
Thomas Haller
ce1742303f gbinding: drop obsolete code in weak_unbind()
At the time when this code was added ([1]), the code and the comment was
correct. g_object_run_dispose() did not clear GWeakRef.

That was later adjusted to clear them ([2]), but at various times it was
not ensured that the GWeakRef was cleared *before* the weak notification
is emitted.

This is now fixed, and the checks for "where_the_object_was" are no
longer necessary. Drop them.

I considered to keep the checks just to be extra safe. But we need to
rely on how g_object_run_dispose() works in detail. By now there is a
test that checks GWeakRef are cleared before emitting the notifications,
so we should not accidentally mess this up and the code is no longer
needed.

[1] commit e82eb490fe ('Handle the case of g_object_run_dispose() in GBinding')
[2] commit a7262d6357 ('gobject: Cleanup weak locations data as part of dispose')
2025-05-01 23:40:02 +02:00
Thomas Haller
d8f84a517e gobject: clear weak locations before calling dispose in g_object_run_dispose()
This changes behavior from commit [1] most similar to what was before.

The point of g_object_run_dispose() is to break reference cycles to
bring down an object. We don't expect the object to take new references
to keep it alive for longer. We probably also don't expect it to
register new weak references. We also don't expect the dispose() callees
to check g_weak_ref_get() for the object. In that case, this change
makes not difference.

Note that during g_object_run_dispose() the ref count does not yet go to
zero, still we clear GWeakRef. As such, GWeakRef rather tracks when
objects get disposed, instead of when the ref count really goes to zero.
That is intentional (e.g. issue [2]).

But compare to g_object_unref(), where we also clear GWeakRef *before*
calling dispose. That makes more sense, because inside dispose() (and
for example during weak notifications), we probably want to see that
g_weak_ref_get() indicates the object is already disposed. For that
reason, it seems more correct to clear out the GWeakRef before calling
dispose().

Also, the dispose() callees (e.g. the weak notifications) might refuse to
let the object die by intentionally keeping strong references around.
Not sure why they would do that, it is similar to resurrecting an object
during dispose(). But if they do, they might also want to register new
GWeakRef. In that case, we wouldn't want to unset those newly set
GWeakRef unconditionally right after.

In most cases, it shouldn't make a difference. In the case where it
does, this is the more sensible order of doing things.

[1] commit 2952cfd7a7 ('gobject: drop clearing quark_weak_locations from g_object_real_dispose()')
[2] https://gitlab.gnome.org/GNOME/glib/-/issues/2266
2025-05-01 23:40:02 +02:00
Thomas Haller
42c0f9a7b1 gobject: rework freezing once during object initialization
During object initialization, we may want to freeze the notifications,
but only do so once (and once unfreeze at the end).

Rework how that was done. We can avoid an additional GData lookup.
2025-05-01 23:01:46 +02:00
Thomas Haller
18d5b34cfc gobject: don't pass around the GObjectNotifyQueue instance
By now, GObjectNotifyQueue gets reallocated. So quite possibly if we
keep the queue, it is a dangling pointer.

That is error prone, but it's also unnecessary. All we need to know is
whether we bumped the freeze count and need to unfreeze. The queue
itself was not useful, because we anyway must take a lock (via
g_datalist_id_update_atomic()) to do anything with it.

Instead, use a nqueue_is_frozen boolean variable.
2025-05-01 23:01:46 +02:00
Thomas Haller
b8ff814d7d gobject: rework GObjectNotifyQueue to not use GSList
GSList is almost in all use cases a bad choice. It's bad for locality
and requires a heap allocation per entry.

Instead, use an array, and grow the buffer exponentially via realloc().

Now, that we use g_datalist_id_update_atomic(), it is also easy to
update the pointer. Hence, the GObjectNotifyQueue struct does not point
to an array of pspecs. Instead the entire GObjectNotifyQueue itself gets
reallocated, thus saving one heap allocation for the separate head
structure.
2025-05-01 23:01:46 +02:00
Philip Withnall
d496e97b75 gitypes: Add ‘none’ members for flags enums
This is a little clearer than using `0` as a precondition failure
return value.

Suggested by John Ralls in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4606#note_2420640.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-30 13:18:55 +01:00
Philip Withnall
d1e28aed1a girepository: Fix -Wsign-conversion warnings in macOS library code
The members of `struct segment_command` appear to have type `uint32_t`,
so definitely need casting to the machine’s integer pointer type before
doing pointer arithmetic on them.

See https://developer.apple.com/documentation/kernel/segment_command

Tested only on macOS CI as I don’t have access to a macOS machine.

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

Helps: #3405
2025-04-30 13:18:49 +01:00
Philip Withnall
c76b9bc72e girepository: Fix various precondition failure return values to typecheck
This fixes various `-Wsign-conversion` warnings in `giarginfo.c` and
related files.

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

Helps: #3405
2025-04-30 13:18:45 +01:00
Philip Withnall
cdca951d06 gdump: Fix some GError -Wsign-conversion warnings
Because of the generic nature of `GError`, `g_set_error()` has to take
an `int`, but `g_file_error_from_errno()` returns a `GFileError`. The
macOS CI runner decides that’s a good reason to emit
`-Wsign-conversion`.

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

Helps: #3405
2025-04-30 13:18:38 +01:00
Philip Withnall
e662421d3a girnode: Make an internal struct member’s type more specific
This struct is only ever heap allocated, and enums are always the same
size as an int (or unsigned int), so it won’t change size.
The struct doesn’t correspond to any mmapped structure from a
typelib file.

This should fix some `-Wsign-conversion` warnings (curiously only seen
on the macOS CI runner) by using the most specific type.

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

Helps: #3405
2025-04-30 13:18:31 +01:00
Philip Withnall
eaf27c0649 Merge branch 'macos_ci' into 'main'
Update macOS job for new CI runner

See merge request GNOME/glib!4613
2025-04-29 20:56:59 +00:00
René de Hesselle
dc23a17fb1 ci: Update macOS job for new CI runner
Remove settings no longer required on an ephemeral runner (redirecting
cache locations etc.).

Adjust cache settings.
2025-04-29 22:38:45 +02:00
Philip Withnall
c22642589b Merge branch 'wip/shell-parse-empty-comment' into 'main'
shell: Handle empty comment gracefully

See merge request GNOME/glib!4615
2025-04-29 09:22:09 +00:00
Jonas Ådahl
2c0c03ad27 shell: Handle empty comment gracefully
Parsing scripts using g_shell_parse_argv() line by line, it's useful to
have empty comments, so one can write pragraphs etc, e.g.

    # This is a comment with multiple paragraphs.
    #
    # It's useful to split things up like this at times.
    #
    # The empty comment characters makes it clear the paragraphs form a
    # single comment.
2025-04-29 00:29:20 +02:00
Philip Withnall
490438c416 Merge branch 'patch-pt' into 'main'
Update Portuguese translation

See merge request GNOME/glib!4609
2025-04-24 19:29:27 +00:00
Philip Withnall
585bdf45cf Merge branch 'uk_update1' into 'main'
Update Ukrainian translation

See merge request GNOME/glib!4610
2025-04-24 19:28:58 +00:00
Yuri Chornoivan
5e444e46bb Update Ukrainian translation 2025-04-24 17:37:13 +00:00
Hugo Carvalho
5624206212 Replace pt.po 2025-04-24 17:14:32 +00:00
Philip Withnall
35b47a5414 Merge branch 'preserve-mode' into 'main'
gfileutils: Preserve mode during atomic updates

Closes dconf#76

See merge request GNOME/glib!4607
2025-04-24 13:43:50 +00:00
Wesley Hershberger
45a36e52b5 gfileutils: Preserve mode during atomic updates
If g_file_set_contents{_full,} is replacing an existing file, require
that the tmpfile have the same mode as the existing file.

This prevents the umask from taking effect for consistent writes to
existing files.

Closes GNOME/dconf#76
2025-04-23 08:54:07 -05:00
Philip Withnall
0dbdce17dd tests: Fix some -Wsign-conversion warnings in GParamSpec tests
We can tighten up the types which are being used, to prevent the
warnings. Not everything in the world has to be a `guint`.

These warnings only showed up on the macOS CI runner.

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

Helps: #3405
2025-04-22 23:43:13 +01:00
Philip Withnall
0bf12ea619 gobject: Fix a few more straightforward -Wsign-conversion warnings
These only show up on macOS. Apparently it’s more sensitive to assigning
`gboolean` (which is secretly `int`) to a `guint` bitfield. 🤷

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

Helps: #3405
2025-04-22 23:12:56 +01:00
Philip Withnall
4e54b46ce9 gclosure: Fix two -Wsign-conversion warnings on macOS
These don’t show up for me on Linux, but are now causing CI failures on
macOS (https://gitlab.gnome.org/GNOME/glib/-/jobs/5006543):
```
../gobject/gclosure.c:923:40: error: implicit conversion changes signedness: 'gboolean' (aka 'int') to 'guint' (aka 'unsigned int') [-Werror,-Wsign-conversion]
      ATOMIC_SET (closure, in_marshal, in_marshal);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-22 23:12:49 +01:00
Marco Trevisan
9f11c8962b Merge branch 'param-specs-constants' into 'main'
gparamspecs: Use standard min/max constants rather than literals

See merge request GNOME/glib!4605
2025-04-22 22:10:33 +00:00
Philip Withnall
a25e15695b Merge branch 'wsign-conversion3' into 'main'
Enable -Wsign-conversion for girepository, gthread, gmodule

See merge request GNOME/glib!4594
2025-04-22 21:47:03 +00:00
Philip Withnall
d425135164 gparamspecs: Use standard min/max constants rather than literals
This makes the code a little clearer. In most cases, it’s not a
functional change.

In a few cases, the values are different. I believe the original values
were incorrect (accidentally transposed, perhaps). This never caused an
issue because they were all immediately overwritten during construction
of a `GParamSpec`: these values were defaults in the `instance_init`
vfunc of the `GTypeInstance` for a `GParamSpec`, but the actual min/max
for the `GParamSpec` instance were immediately written over them in the
constructor (such as `g_param_spec_int()`).

Spotted in !4593.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-22 22:38:58 +01:00
Philip Withnall
988db0e89d Merge branch 'wsign-conversion2' into 'main'
Enable -Wsign-conversion for gobject directory

Closes #3405

See merge request GNOME/glib!4593
2025-04-22 21:31:41 +00:00
Philip Withnall
745d22eec8 Merge branch 'LLyaudet-main-patch-21388' into 'main'
docs: fix typo glong: ULONG_MAX -> LONG_MAX

See merge request GNOME/glib!4602
2025-04-22 17:00:38 +00:00
Laurent Lyaudet
2bf5064655 docs: add INT(16|32|64)_(MAX|MIN) and fix some typos 2025-04-22 17:00:38 +00:00
Sergey Bugaev
271ce5166b garray: Fix annotations
Notably without the (array), the argument of g_byte_array_append appears
as

  <type name="guint8" c:type="const guint8*"/>

which will cause the bindings to pass a byte, not a pointer.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2025-04-22 16:04:03 +03:00
Philip Withnall
be8c76c98c Merge branch 'networkmonitor-jail' into 'main'
Fix GNetworkMonitorNetlink operation under a FreeBSD jail with shared network stack

See merge request GNOME/glib!4603
2025-04-21 22:28:49 +00:00
Gleb Popov
b479d14371 Fix GNetworkMonitorNetlink operation under a FreeBSD jail with shared network stack 2025-04-21 22:28:49 +00:00
Philip Withnall
80e3ea1e1d Merge branch 'larma/cocoa-notification-bytes-icon' into 'main'
cocoa: add support for GBytesIcon in notification backend

See merge request GNOME/glib!4604
2025-04-21 21:39:33 +00:00
Marvin W
cf44fb0d2a cocoa: add support for GBytesIcon in notification backend 2025-04-18 14:36:34 +02:00
Thomas Haller
88f5db3e75 gobject/docs: remove wrong paragraph from GWeakRef docs
The "without first having or creating a strong reference" part is wrong.

While we invoke the dispose() method, we always still hold the last
reference. The calling thread called g_object_unref() with a strong
reference that we are about to give up, but at the point where we call
dispose(), we didn't yet decrement the ref count to zero. Doing so would
be a fatal bug.

As such, during dispose() the object is still healthy and still has a
strong pointer. You can call `g_weak_ref_set()` on that pointer without
taking an additional strong reference. Of course, if you don't actually
take a strong reference (and thus don't resurrect the object), then
right afterwards, the last reference is dropped to zero, and the
GWeakRef gets reset again.

But there is no need to claim that you need to take another strong
reference to set a GWeakRef during dispose(). This was always the case.

Also, reword the previous paragraph. I think this is clearer.
2025-04-17 18:07:27 +02:00