Commit Graph

22681 Commits

Author SHA1 Message Date
Sebastian Dröge
7367c5d367 Release GBinding transform functions also when implicitly unbinding because source/target are finalized
This was inconsistently handled before and only explicit unbinding or
finalizing the binding would've previously released the transform
function. If the source/target were finalized while more strong
references to the binding still existed then the transform function
would stay alive and only the binding itself would be deactivated.
2020-11-26 19:51:56 +02:00
Sebastian Dröge
cc15c933b3 Add tests for GBinding thread-safety 2020-11-26 19:51:56 +02:00
Sebastian Dröge
d296ad435d Factor out common GBinding unbind code into a separate function
This was previously duplicated in two places.
2020-11-26 19:30:54 +02:00
Sebastian Dröge
98bbe4f4d1 Make transform function handling in GBinding thread-safe
Unbinding can happen from one thread while a property notification is
being handled concurrently in another one.

To solve this, introduce a reference counter for the transform function
that ensures that it always stays valid while in use and protect access
to the one stored inside the binding with the unbind mutex.
2020-11-26 19:30:48 +02:00
Sebastian Dröge
1daee6ac64 Make explicit/implicit GBinding unbinding thread-safe
It's possible for g_binding_unbind() to be called at the same time as
one (or both) of source and target are being finalized. The resulting
unbinding needs to be protected with a mutex to ensure that it only
happens exactly once.

As the first reference is owned by both weak notifies and the caller of
g_object_bind_property(), additional indirections are needed to ensure that
unreffing the first reference after creation still unbinds the binding
as before. This seems to be a common code pattern and how this was
intended to be used, but is only safe in single-threaded contexts as it
relies on both the source and target object to be still alive.

Add a lot of comments to the code about all these dependencies and a
couple of assertions to ensure they hold valid.

Also document that inconsistent reference ownership handling of
g_binding_unbind() that makes it unfit for automatically generated
language bindings.
2020-11-26 16:15:36 +02:00
Sebastian Dröge
c8c829fa42 Add g_binding_dup_target() and g_binding_dup_source()
These new getters prevent the source/target from simply disappearing if
they're finalized from another thread in the meantime.
2020-11-26 10:49:23 +02:00
Sebastian Dröge
51ee5cf1c2 Use GWeakRef in GBinding
This makes GBinding slightly more thread-safe as the source/target can't
simply disappear.
2020-11-26 10:49:18 +02:00
Philip Withnall
0af274faa4 Merge branch 'macos-cross' into 'master'
macos: fix frexpl checks in cross-compilation

See merge request GNOME/glib!1771
2020-11-25 19:11:19 +00:00
Philip Withnall
3088fbae52 Merge branch 'mark_g_assert_as_noreturn_on_MSVC' into 'master'
Adding macros G_NORETURN and G_NORETURN_FUNCPTR

Closes #994

See merge request GNOME/glib!1078
2020-11-25 11:52:23 +00:00
Philip Withnall
9cccc08b82 gmacros: Document soft-deprecation of G_GNUC_NORETURN
It still works, and deprecating it would be quite disruptive (as it’s
used in headers), so amend the documentation to point people to
`G_NORETURN` instead.

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

Helps: #994
2020-11-25 11:37:06 +00:00
Emmanuel Fleury
76426c0158 Rewriting the G_GNUC_NORETURN into G_NORETURN macros everywhere 2020-11-25 11:34:05 +00:00
Emmanuel Fleury
c1d74e35c1 Adding macros G_NORETURN and G_NORETURN_FUNCPTR
This macro is borrowed from the gnulib project in the 'noreturn.h' file.

Fixes: #994
2020-11-25 11:34:05 +00:00
Patrick Griffis
a5944828ae Merge branch 'carlosgc/uri-scheme-normalization' into 'master'
guri: apply scheme normalization flag consistently

Closes #2257

See merge request GNOME/glib!1764
2020-11-24 17:25:26 +00:00
Philip Withnall
77361ef45e Merge branch 'fix_extra_warnings' into 'master'
Fix more warnings

See merge request GNOME/glib!1765
2020-11-24 15:37:21 +00:00
Emmanuel Fleury
236d6281b8 Fix signedness warnings in gobject/gobject.c:g_object_new_internal()
gobject/gobject.c: In function ‘g_object_new_internal’:
gobject/gobject.c:1962:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1962 |           for (j = 0; j < n_params; j++)
      |                         ^
gobject/gobject.c:1989:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1989 |       for (i = 0; i < n_params; i++)
      |                     ^
2020-11-24 16:17:46 +01:00
Emmanuel Fleury
7753a0492b Fix signedness warnings in gobject/gobject.c:g_object_new_with_custom_constructor()
gobject/gobject.c: In function ‘g_object_new_with_custom_constructor’:
gobject/gobject.c:1836:21: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1836 |       for (j = 0; j < n_params; j++)
      |                     ^
gobject/gobject.c:1914:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1914 |   for (i = 0; i < n_params; i++)
      |                 ^
2020-11-24 16:17:46 +01:00
Emmanuel Fleury
d50d2098b5 Fix signedness warning in gobject/gobject.c:g_object_class_install_properties()
gobject/gobject.c: In function ‘g_object_class_install_properties’:
gobject/gobject.c:766:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  766 |   for (i = 1; i < n_pspecs; i++)
      |                 ^
2020-11-24 16:17:46 +01:00
Emmanuel Fleury
e28d9defb1 Fix signedness warning in gobject/gtype.c:g_type_interface_add_prerequisite()
gobject/gtype.c: In function ‘g_type_interface_add_prerequisite’:
gobject/gtype.c:1607:21: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
 1607 |       for (i = 0; i < prerequisite_node->n_supers + 1; i++)
      |                     ^
2020-11-24 16:17:37 +01:00
Philip Withnall
69f0f33267 Merge branch 'mcatanzaro/#2076' into 'master'
Suppress some valgrind leak warnings

Closes #2076

See merge request GNOME/glib!1768
2020-11-24 14:45:11 +00:00
Michael Catanzaro
fb6e10c959 gtype: suppress valgrind memory leak warnings
The problem occurs because we keep a pointer inside the allocated block,
instead of a pointer to the start of the block. This memory exists for
the lifetime of the application, so let's silence it.

This is probably abuse of VALGRIND_MALLOCLIKE_BLOCK(), which is really
intended for use in memory allocators, but gtype.c already uses it in
two other places, and it's a practical solution. I wrote another larger
fix for this issue that involves keeping an array of extra pointers when
running under valgrind. This is simpler.

Fix suggested by Philip Withnall

```
==180238== 16 bytes in 1 blocks are possibly lost in loss record 3,078 of 16,075
==180238==    at 0x483BB1A: calloc (vg_replace_malloc.c:762)
==180238==    by 0x5489495: g_malloc0 (gmem.c:132)
==180238==    by 0x5489754: g_malloc0_n (gmem.c:364)
==180238==    by 0x53FDBEE: type_set_qdata_W (gtype.c:3722)
==180238==    by 0x53FDEE8: type_add_flags_W (gtype.c:3787)
==180238==    by 0x53FC348: g_type_register_fundamental (gtype.c:2662)
==180238==    by 0x53D969B: _g_enum_types_init (genums.c:124)
==180238==    by 0x53FF058: gobject_init (gtype.c:4432)
==180238==    by 0x53FF082: gobject_init_ctor (gtype.c:4493)
==180238==    by 0x4010F29: call_init.part.0 (dl-init.c:72)
==180238==    by 0x4011030: call_init (dl-init.c:30)
==180238==    by 0x4011030: _dl_init (dl-init.c:119)
==180238==    by 0x4002149: ??? (in /usr/lib64/ld-2.30.so)
```

Fixes #2076
2020-11-24 08:10:58 -06:00
Michael Catanzaro
a412ffe4d3 gatomicarray: suppress valgrind memory leak warnings
The problem occurs because we keep a pointer inside the allocated block,
instead of a pointer to the start of the block:

```
==180238== 16 bytes in 1 blocks are possibly lost in loss record 3,086 of 16,075
==180238==    at 0x483980B: malloc (vg_replace_malloc.c:309)
==180238==    by 0x548942C: g_malloc (gmem.c:102)
==180238==    by 0x54A4748: g_slice_alloc (gslice.c:1025)
==180238==    by 0x53D0AAF: freelist_alloc (gatomicarray.c:77)
==180238==    by 0x53D0B85: _g_atomic_array_copy (gatomicarray.c:133)
==180238==    by 0x53F8E6D: iface_node_set_offset_L (gtype.c:1347)
==180238==    by 0x53F91F1: type_node_add_iface_entry_W (gtype.c:1444)
==180238==    by 0x53F93DF: type_add_interface_Wm (gtype.c:1477)
==180238==    by 0x53FC946: g_type_add_interface_static (gtype.c:2852)
==180238==    by 0x4A3D53A: gtk_menu_shell_accessible_get_type_once (gtkmenushellaccessible.c:26)
==180238==    by 0x4A3D495: gtk_menu_shell_accessible_get_type (gtkmenushellaccessible.c:26)
==180238==    by 0x4C8AC44: gtk_menu_shell_class_init (gtkmenushell.c:424)
```

Note we cannot use VALGRIND_FREELIKE_BLOCK() in freelist_free() because we
have not actually freed the FreeListNode and need to dereference it in
freelist_alloc() to decide whether to reuse the block. That would result
in a use-after-free warning before we would get a chance to call
VALGRIND_MALLOCLIKE_BLOCK() in the reuse path.

Also note that this free list only ever grows: it never shrinks for the
lifetime of the application, so nothing here will ever be truely freed,
although unused elements are eligible for reuse.

Fix suggested by Philip Withnall

Related: #2076
2020-11-24 08:10:58 -06:00
Carlos Garcia Campos
fb838bf3f6 guri: apply scheme normalization flag consistently
For URIs produced in string form, the path should be normalized and port
omitted when the default one is used. When querying the path and port of
a GUri (using getters or g_uri_split()) the normalized path and the
default port should be returned when they were omitted in the parsed URI.

Closes #2257
2020-11-24 14:35:19 +01:00
Andoni Morales Alastruey
64dda3ad87 macos: fix frexpl checks in cross-compilation
Cross-compilation to arm64 for Apple Silicon is not possible
due to the hardcoded settings for frexpl.
See: #1868
2020-11-24 13:05:17 +00:00
Philip Withnall
23ad18791d Merge branch 'mcatanzaro/coverity-checked-return' into 'master'
gkeyfilesettingsbackend: improve error-checking

See merge request GNOME/glib!1746
2020-11-24 10:44:59 +00:00
Philip Withnall
44fede46be Merge branch 'wip/jfelder/gdatetime-annotations' into 'master'
Fix some gdatetime annotations

See merge request GNOME/glib!1766
2020-11-24 10:36:38 +00:00
Philip Withnall
9aaac19173 Merge branch 'wip/pwithnall/disable-assert' into 'master'
gfileicon: Fix unused-but-set variable with G_DISABLE_ASSERT

See merge request GNOME/glib!1769
2020-11-24 10:10:26 +00:00
Michael Catanzaro
00e8064137 gkeyfilesettingsbackend: improve error checking
Coverity noticed that we are ignoring return values in a couple places
here. We should print warnings when appropriate.
2020-11-24 10:09:02 +00:00
Jean Felder
cd6b35f7d2 gdatetime: Fix g_date_time_equal annotation
The parameters C type need to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Jean Felder
b513b358a8 gdatetime: Fix g_date_time_hash annotation
The parameter C type needs to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Jean Felder
7ec3c26e67 gdatetime: Fix g_date_time_compare annotation
The parameters C type need to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Philip Withnall
44c4e42151 gfileicon: Fix unused-but-set variable with G_DISABLE_ASSERT
This fixes a warning (which is promoted to an error) in our
`G_DISABLE_ASSERT` CI.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:44:48 +00:00
Sebastian Dröge
d78778cc46 Merge branch 'scan-build-fixes' into 'master'
Minor scan-build fixes

See merge request GNOME/glib!1770
2020-11-24 09:40:34 +00:00
Sebastian Dröge
ec981cf570 Merge branch 'wip/pwithnall/553-tz-freebsd-tests' into 'master'
tests: Fix GDateTime tests on FreeBSD

See merge request GNOME/glib!1767
2020-11-24 09:33:47 +00:00
Philip Withnall
6e446931a8 tests: Add a test to avoid a set-but-unused variable
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
eafc6b257c tests: Add a test to avoid a set-but-unused variable
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
6fcc4db228 tests: Drop dead code from GDateTime test
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
2237db78f1 tests: Fix GDateTime tests on FreeBSD
`g_time_zone_new_identifier()` returns NULL in the FreeBSD test setup,
presumably because `TZ` isn’t set.

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

Helps: #553
2020-11-24 09:20:28 +00:00
Emmanuel Fleury
6b0552bb89 Fix signedness warning in gobject/gtype.c:type_node_add_iface_entry_W()
gobject/gtype.c: In function ‘type_node_add_iface_entry_W’:
gobject/gtype.c:1379:21: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
 1379 |       for (i = 0; i < num_entries; i++)
      |                     ^
2020-11-22 17:10:53 +01:00
Emmanuel Fleury
f6e234fdb6 Fix signedness warning in gobject/gtype.c:lookup_iface_entry_I()
gobject/gtype.c: In function ‘lookup_iface_entry_I’:
gobject/gtype.c:599:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  599 |       if (index < IFACE_ENTRIES_N_ENTRIES (entries))
      |                 ^
gobject/gatomicarray.h:51:8: note: in definition of macro ‘G_ATOMIC_ARRAY_DO_TRANSACTION’
   51 |       {_C_;}         \
      |        ^~~
2020-11-22 17:10:53 +01:00
Sebastian Dröge
72360eb8bd Merge branch '553-tz-errors' into 'master'
gtimezone: Add new constructor which can report errors

Closes #553

See merge request GNOME/glib!1760
2020-11-22 08:35:33 +00:00
Philip Withnall
3356934db5 gtimezone: Deprecate g_time_zone_new()
Use `g_time_zone_new_identifier()` instead so you can get error
checking.

Adapt the tests to match.

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

Helps: #553
2020-11-21 23:11:23 +00:00
Philip Withnall
9f041c9e05 Merge branch 'th/gobject-new-parameter-list' into 'master'
gobject: allocate parameter list for g_object_new_valist() entirely on stack

See merge request GNOME/glib!1385
2020-11-21 22:55:55 +00:00
Sebastian Dröge
fa8a39c6c6 Merge branch 'py-fixes' into 'master'
Python formatting improvements

See merge request GNOME/glib!1757
2020-11-20 18:10:40 +00:00
Philip Withnall
a7c0adbe11 Merge branch 'py-sh-check-fixes' into 'master'
shellcheck fixes

See merge request GNOME/glib!1756
2020-11-20 15:01:59 +00:00
Philip Withnall
936a07173a Merge branch '600-drop-volatile' into 'master'
Drop use of volatile

Closes #600

See merge request GNOME/glib!1719
2020-11-20 14:55:03 +00:00
Philip Withnall
72e4781ffc ci: Temporarily fold SH and Py checks into style-check job
It doesn’t seem to be possible to use `only:changes` from a branch
pipeline extending `.only-default` and have it correctly trigger when
`*.sh` or `*.py` files are modified.

We possibly need to convert all our pipelines to be merge-request-only,
but that’s an avenue I’ve been down before and I couldn’t get it to
work. Using
[`workflow:rules`](https://docs.gitlab.com/ee/ci/yaml/README.html#workflowrules)
might fix that, but I don’t have time to rework the entire CI to use
that now.

So in the meantime, move the SH and Py checks into the existing
style-check job so we’re not always spinning up two additional container
instances on every merge request.

See !1743.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-20 14:48:14 +00:00
Philip Withnall
c7d2206df3 update-pcre: Use a subshell to avoid cd ..
Shellcheck warning SC2103.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-20 14:48:14 +00:00
Philip Withnall
51651ac67e ci: Fix backslash escaping in run-docker.sh
Spotted by shellcheck (warning SC1117): `\e` is not an actual escape
sequence, so it’s interpreted as `\\e`. Best make that explicit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-20 14:48:14 +00:00
Philip Withnall
83e48d8ac1 docs: Document not to use volatile qualifiers
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #600
2020-11-20 14:41:07 +00:00
Philip Withnall
7d417f8406 gresource: Fix a pointer mismatch with an atomic load
This squashes a warning when compiling with Clang.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-20 14:41:07 +00:00