Commit Graph

2045 Commits

Author SHA1 Message Date
Philip Withnall
b1e371034d Merge branch 'gobject-speedup8' into 'main'
Avoid g_param_spec_get_redirect_target

See merge request GNOME/glib!2722
2022-06-07 11:45:25 +00:00
Philip Withnall
8f7df344b6 gobject: Sink floating pspecs if adding them to a class fails
This may fix Coverity assuming that pspecs are leaked, which is causing
tens and tens of false positives in the latest Coverity reports for
GLib.

Ensure that the pspecs are sunk (if floating) even if adding them to the
class fails (due to validation failure or an identically named property
already existing).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-07 11:20:32 +01:00
Matthias Clasen
54c867a01e Revert "gtype: Speed up type checks for final types"
This reverts commit 0ddea2d8e2.

The commit was based on the misunderstanding that types
declared with G_DECLARE_FINAL_TYPE are actually non-derivable.
But that is only the case for types defined with
G_DEFINE_FINAL_TYPE.

Fixes: #2661
2022-06-06 16:39:41 -04:00
Matthias Clasen
7d8e2fcf6d Cosmetic coding style fixes 2022-06-06 14:28:31 -04:00
Matthias Clasen
f755f445c6 Avoid property notification during g_object_set
If we have no nontrivial notify vfunc, and no signal
handlers for notify, we don't need to maintain the
notify queue. No need to notify if nobody's listening.
2022-06-06 14:26:58 -04:00
Matthias Clasen
8851112b8d Avoid property notification during object construction
Check whether an object has a nontrivial notify vfunc
and avoid creating and updating the notify queue if
it doesn't. We know that there can be no notify signal
handlers at this point. No need to notify if nobody's
listening.
2022-06-06 14:26:45 -04:00
Matthias Clasen
8b328f1d6d Keep a separate flag for notify handlers
We currently keep a flag for whether an object has
ever had any signal handlers. But even if it had signal
handlers, it may not have any notify handlers. Keep that
information separately, so we can speed up property setting.
2022-06-06 14:25:41 -04:00
Matthias Clasen
16a8b6d819 gobject: Avoid redundant atomics
According to the commit that introduced these
calls (4b334ef8f1), we are checking
the refcount here to avoid calling g_object_ref
when the refcount is 0, in the rare case that
notification would be triggered during finalize.

But we are now freezing notifications during
finalize, and after recent changes, we no longer call
g_object_ref for notification while a freeze is
in place.
2022-06-06 14:13:20 -04:00
Matthias Clasen
9d7d439607 Avoid g_param_spec_get_redirect_target
Inline the getting of the redirect target.
This is a rare thing, and the calls were
showing up in profiles.
2022-06-06 14:00:33 -04:00
Philip Withnall
2b437402e8 Merge branch 'gobject-speedup7' into 'main'
Avoid g_object_ref/unref in some cases

See merge request GNOME/glib!2721
2022-06-06 17:53:42 +00:00
Philip Withnall
f8c5d71104 Merge branch 'gobject-speedup9' into 'main'
Avoid g_type_class_peek

See merge request GNOME/glib!2723
2022-06-06 17:16:33 +00:00
Matthias Clasen
e70a4eef77 Avoid g_object_ref/unref in some cases
We only need to take a ref on the object when
we call out to external code (ie around
->dispatch_properties_changed). If we avoid
the signal emission, we can avoid the ref/unref
too. This is not currently happening, but
might in the future.
2022-06-06 12:33:34 -04:00
Matthias Clasen
19551ac983 Avoid g_type_class_peek
Most of the time, properties belong to the class
we set them on. Check that first, before going
into GType, which takes locks and whatnot.
2022-06-06 11:51:55 -04:00
Matthias Clasen
a4940943e5 Move deprecation warnings to object_set_property
A small reorg that reduces the code and matches
what we do for object_get_property.

Note that as a consequence of this change, we now
check the deprecated flag on the redirected property,
not on the original when setting properties. This
matches what we were already doing for getting
properties.
2022-06-06 11:29:16 -04:00
Matthias Clasen
d97c948567 Don't inline deprecation warnings
The code that emits property deprecation warnings
rarely runs, and doesn't need to be inlined
everywhere. It is enough to inline the check for
the deprecation flag.
2022-06-06 11:29:14 -04:00
Philip Withnall
d730cfcdf4 Merge branch 'gobject-speedup2' into 'main'
Simplify g_object_new_with_properties

See merge request GNOME/glib!2713
2022-06-06 15:18:01 +00:00
Philip Withnall
d7ff2b3ad1 Merge branch 'gobject-speedup5' into 'main'
Don't copy values in g_object_new

See merge request GNOME/glib!2716
2022-06-06 13:51:13 +00:00
Philip Withnall
22fea9d24a Merge branch 'gobject-speedup3' into 'main'
Simplify g_object_notify_by_pspec

See merge request GNOME/glib!2714
2022-06-06 13:02:52 +00:00
Matthias Clasen
ec69e7c463 Simplify g_object_new_with_properties
This function was doing an unnecessary extra
copy of the GValues. We can avoid that.
2022-06-03 07:10:08 -04:00
Matthias Clasen
149b0f03b4 Simplify g_object_notify_by_pspec
Fold get_notify_pspec into its only caller.
2022-06-01 19:33:04 -04:00
Matthias Clasen
95caffcd26 Don't copy values during g_object_set
It is safe not to copy arguments here,
because we are not emitting any signals
before we are done setting the values
as properties.

This matches what we do for g_object_new now.
2022-06-01 18:22:10 -04:00
Matthias Clasen
d50bc3c1c3 Don't copy values in g_object_new
We can safely use the values without copying here.
This is safe because we are not emitting any
signals before we are done setting the values
as properties.
2022-06-01 18:20:41 -04:00
Simon McVittie
804c45324e Merge branch 'test-verbose-output' into 'main'
tests: Remove various bits of overly-verbose test output

See merge request GNOME/glib!2704
2022-06-01 17:31:53 +00:00
Matthias Clasen
72a682950d gobject: Drop an unused quark
quark_in_construction is only used if
we don't have per-instance flags.
2022-05-31 16:13:18 -04:00
Philip Withnall
0611999fed tests: Remove various bits of overly-verbose test output
None of these messages are particularly helpful, but they increase the
overall test log output size, which has to be stored by the CI for every
test run.

With these messages removed, the size of a full test log is reduced from
6.5MB to 1.8MB for me.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 15:21:46 +01: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
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
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
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
Matthias Clasen
ecc641de71 Avoid malloc for construct params
Stack-allocate the GObjectConstructParams (except for
extreme cases), for a small speedup of object construction.
2022-05-26 09:47:23 -04:00
Matthias Clasen
f7119a7935 Keep a count of construct params
This avoids walking the construct params list
one extra time just to count when constructing
objects, for a small speedup of object construction
in the presence of construct params.
2022-05-26 09:47:23 -04:00
Philip Withnall
f157c7d0d3 gparamspecs: Tidy up a precondition
Move the `if` into the precondition assertion, eliminating one line of
code and making the function preconditions clearer to static analysers.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-25 14:44:48 +01:00
Philip Withnall
96f4c2b095 gparamspecs: Remove redundant NULL checks
`g_param_spec_internal()` can never return `NULL`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-25 14:44:48 +01:00
Matthias Clasen
c72de9dd99 gobject: Use value_is_valid
Avoid GValue transformation when we can, using
the new value_is_valid vfunc.

This is particularly useful for string properties,
where g_value_transform will make a copy of the string.
2022-05-25 14:25:18 +01:00
Matthias Clasen
b0d15068c4 gparamspec: Test individual paramspec is_valid() implementations
Test many of the paramspec implementations
at least a little bit.
2022-05-25 14:25:18 +01:00
Matthias Clasen
c8e14df6f7 Add another test for g_param_value_is_valid
Add a test that exercises the fallback
in g_param_value_is_valid.
2022-05-23 15:51:33 -04:00
Matthias Clasen
24925658f5 Add tests for g_param_value_is_valid 2022-05-23 15:51:33 -04:00
Matthias Clasen
dacfe8c88a param: Add g_param_value_is_valid
This is wrapper for the new value_is_valid vfunc,
but it falls back to using value_validate to
obtain the same information.
2022-05-23 15:48:28 -04:00
Matthias Clasen
bdc8b025c5 param: Add a value_is_valid vfunc
In constrast to value_validate, this one does not
modify the passed-in value, so we can avoid the cost
of copying the GValue beforehand.
It is optional, but we set it for most of the
builtin pspec types.
2022-05-23 15:48:28 -04:00
Matthias Clasen
b7be0f95a8 gobject: Speed up finalization
Move the warning about finalize-during-construction
to debug-only.
2022-05-23 09:20:46 -04:00
Matthias Clasen
fa8c7c0da6 gobject: Use g_datalist_id_remove_multiple
This speeds up object finalization a little.
2022-05-23 09:19:45 -04:00
Philip Withnall
7de0fcd628 Merge branch 'gobject-speedups2' into 'main'
Avoid g_type_peek_value_table

See merge request GNOME/glib!2674
2022-05-23 11:00:23 +00:00
Matthias Clasen
f2a085d8ea Avoid g_type_peek_value_table
In several places we do paired calls of g_value_init
and g_value_unset, both of which peek the value table.
We can avoid half of that cost by remembering the value
table, instead of looking it up again.

This uses the new G_VALUE_COLLECT_INIT2 macro.
2022-05-23 06:35:55 -04:00
Matthias Clasen
aaef7f30b3 value: Add G_VALUE_COLLECT_INIT2
Add a variant of the G_VALUE_COLLECT_INIT() macro
that provides the GTypeValueTable to the caller.
2022-05-23 05:57:36 -04:00
TestingPlant
da7a31a052 Rename user data parameters to user_data
The user data parameters in callbacks need to be named user_data to
generate correct closure attributes in the introspection data. This
updates parameters missed in GNOME/glib!2633.
2022-05-22 01:06:37 +00:00
Matthias Clasen
0a3a0894f9 Merge branch 'gtype-speedups' into 'main'
gtype: small optimization

See merge request GNOME/glib!2672
2022-05-20 13:43:17 +00:00
Philip Withnall
1f42078ace Merge branch 'param-speedups' into 'main'
param: Avoid strcmps

See merge request GNOME/glib!2673
2022-05-20 13:15:39 +00:00
Matthias Clasen
e80d2bc1ca Add a test for g_type_is_a
Check that the macro and function versions
of g_type_is_a work the same.
2022-05-20 09:08:09 -04:00
Matthias Clasen
22f51b87a2 gtype: Speed up g_type_is_a
As noticed by Christian Hergert: We can reduce
some overhead by checking for exact type
equality first. According to Christian, around
3% of g_type_is_a calls are exact equalities.
2022-05-20 09:08:09 -04:00
Matthias Clasen
55700948eb param: Drop a pointless function
There is nothing to validate for boxed
parameters, so we don't need a validate
function for these.
2022-05-20 08:20:56 -04:00
Matthias Clasen
51215bf7b8 param: Avoid strchrs
Using prefixed property names like GtkWidget::visible
is very deprectated and basically never done. So avoid
paying the strchr cost before doing the first lookup.
2022-05-20 08:20:56 -04:00
Matthias Clasen
91dafa85fc param: Avoid strcmps
Most of the time, we are dealing with static strings,
and we can compare them directly and avoid the strcmp.

Note that triggering this optimization requires
properties to be marked as G_PARAM_STATIC_NAME.
2022-05-20 08:20:56 -04:00
Philip Withnall
3c14b6846d docs: Standardise property ID enums in examples
Drop the redundant `PROP_0` (which isn’t a real property) and initialise
the first member of the enum instead.

Add a typedef so that the enum type can be used in `switch` statements
in `get_property()` and `set_property()` vfuncs. This allows
`-Wswitch-enum` to be used to improve type safety.

The examples here don’t have `get_property()` or `set_property()`
vfuncs, but people might copy/paste the code to somewhere which does.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-20 12:57:36 +01:00
Philip Withnall
8f9c5090db docs: Use G_PARAM_STATIC_STRINGS in examples and explain it more
Make it a bit clearer in the documentation that using
`G_PARAM_STATIC_STRINGS` everywhere is a good thing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-20 12:57:36 +01:00
Matthias Clasen
c492f4aec2 gtype: small optimization
These warnings are never seen at runtime, so they
are evidently very unlikely. Tell the compiler that.
2022-05-20 07:20:19 -04:00
Philip Withnall
caf6d99fbe Merge branch 'win32-fd' into 'main'
gio: various unix/fd-related enablement on win32

See merge request GNOME/glib!2656
2022-05-18 14:01:43 +00:00
Philip Withnall
2dc8184590 tests: Add some SPDX license headers
These cover the files which Debian has already worked out the licensing
information for, in
https://salsa.debian.org/gnome-team/glib/-/blob/debian/master/debian/copyright.

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

Helps: #1415
2022-05-17 17:23:34 +01:00
Marc-André Lureau
bb890b57d2 gobject/gsignalgroup: fix memory leaks on error
Spotted by ASAN during the tests:

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7ff0b4562077 in calloc (/lib64/libasan.so.8+0xba077)
    #1 0x7ff0b3e8b508 in g_malloc0 ../glib/gmem.c:155
    #2 0x7ff0b375052f in g_closure_new_simple ../gobject/gclosure.c:220
    #3 0x7ff0b375b422 in g_cclosure_new ../gobject/gclosure.c:976
    #4 0x7ff0b37d159e in g_signal_group_connect_full ../gobject/gsignalgroup.c:790
    #5 0x7ff0b37d159e in g_signal_group_connect ../gobject/gsignalgroup.c:886
    #6 0x4045d8 in test_signal_group_invalid ../gobject/tests/signalgroup.c:331
    #7 0x7ff0b3f369a5 in test_case_run ../glib/gtestutils.c:2930
    #8 0x7ff0b3f369a5 in g_test_run_suite_internal ../glib/gtestutils.c:3018
    #9 0x7ff0b3f364ed in g_test_run_suite_internal ../glib/gtestutils.c:3035
    #10 0x7ff0b3f364ed in g_test_run_suite_internal ../glib/gtestutils.c:3035
    #11 0x7ff0b3f37879 in g_test_run_suite ../glib/gtestutils.c:3112
    #12 0x7ff0b3f37995 in g_test_run ../glib/gtestutils.c:2231
    #13 0x40253c in main ../gobject/tests/signalgroup.c:664
    #14 0x7ff0b2de758f in __libc_start_call_main (/lib64/libc.so.6+0x2d58f)

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f012addf077 in calloc (/lib64/libasan.so.8+0xba077)
    #1 0x7f012a708508 in g_malloc0 ../glib/gmem.c:155
    #2 0x7f0129fcd52f in g_closure_new_simple ../gobject/gclosure.c:220
    #3 0x7f0129fd8422 in g_cclosure_new ../gobject/gclosure.c:976
    #4 0x7f012a04e5ae in g_signal_group_connect_full ../gobject/gsignalgroup.c:791
    #5 0x7f012a04e5ae in g_signal_group_connect ../gobject/gsignalgroup.c:887
    #6 0x4043cc in test_signal_group_invalid ../gobject/tests/signalgroup.c:308
    #7 0x7f012a7b39a5 in test_case_run ../glib/gtestutils.c:2930
    #8 0x7f012a7b39a5 in g_test_run_suite_internal ../glib/gtestutils.c:3018
    #9 0x7f012a7b34ed in g_test_run_suite_internal ../glib/gtestutils.c:3035
    #10 0x7f012a7b34ed in g_test_run_suite_internal ../glib/gtestutils.c:3035
    #11 0x7f012a7b4879 in g_test_run_suite ../glib/gtestutils.c:3112
    #12 0x7f012a7b4995 in g_test_run ../glib/gtestutils.c:2231
    #13 0x40253c in main ../gobject/tests/signalgroup.c:664
    #14 0x7f012966458f in __libc_start_call_main (/lib64/libc.so.6+0x2d58f)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-17 17:34:06 +02:00
Philip Withnall
25ab87d8e5 build: Drop checks and workarounds for older Meson versions
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-06 13:01:44 +01:00
Logan Rathbone
3a4f0746f5 docs: Expand G_DEFINE_BOXED_TYPE docs with more detailed example 2022-04-25 10:39:27 +00:00
Jason Francis
2a842b1173 gobject: Add g_signal_group_connect_closure 2022-04-05 15:32:20 +01:00
Gabor Karsay
7e64004db0 docs: mark macros, flags, enums with percent sign 2022-03-04 16:21:55 +00:00
Xavier Claessens
2bd152bfeb meson: Add PYTHONPATH to load GDB helper module
Meson generates a gdbinit file that will automatically load glib and
gobject scripts. However that script uses a helper python module that
needs PYTHONPATH to be pointing into the right location in the source
tree to be able to find glib_gdb.py and gobject_gdb.py
2022-02-25 16:50:18 -05:00
Philip Withnall
cb18e6b969 Merge branch 'empty-argv' into 'main'
Various minor fixes for empty argv handling

See merge request GNOME/glib!2466
2022-02-20 09:36:41 +00:00
Xavier Claessens
893ff61176 doc: Extend a bit G_DECLARE_* documentation example 2022-02-19 14:23:37 -05:00
Loic Le Page
8e37f9c48a Fix global variable name hidden by local variables in gobject/tests/reference.c 2022-02-18 10:49:00 +01:00
Loic Le Page
208593acc6 Fix redefinition of local variable and non-initialized variable in gobject/gsignal.c 2022-02-18 10:49:00 +01:00
Loic Le Page
84c5675cef Fix redefinition of local variable in gobject/gtype.c 2022-02-18 10:49:00 +01:00
Philip Withnall
3ea4ba31a1 tools: Fix handling of empty argv in various minor GLib tools
This won’t really affect anything, but we might as well fix them to not
crash if called with an empty `argv` by someone (ab)using `execve()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:42 +00:00
Christian Hergert
dd43471f60 gobject: add GSignalGroup
Much like GBindingGroup, the GSignalGroup object allows you to connect many
signal connections for an object and connect/disconnect/block/unblock them
as a group.

This is useful when using many connections on an object to ensure that they
are properly removed when changing state or disposing a third-party
object.

This has been used for years in various GNOME projects and makes sense to
have upstream instead of multiple copies.
2022-02-01 17:09:14 -08:00
Christian Hergert
0d9de09192 gobject: add GBindingGroup
Originally, GBindingGroup started with Builder as a way to simplify all
of the third-degree object bindings necessary around Model-Controller
objects such as TextBuffer/TextView.

Over time, it has grown to be useful in a number of scenarios outside
of Builder and has been copied into a number of projects such as GNOME
Text Editor, GtkSourceView, libdazzle, and more.

It makes sense at this point to unify on a single implementation and
include that upstream in GObject directly alongside GBinding.
2022-01-28 16:01:22 -08:00
Andoni Morales Alastruey
b1ed9907c2 gi: expose some files as variable for gobject-introspection
see:
https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/313
2022-01-28 16:16:29 +01:00
Xavier Claessens
9159e84ce5 Windows: Do not link DLL specific resources when doing a static build
Fixes: #2585
2022-01-26 09:49:30 -05:00
Loic Le Page
42c77c7ac7 Enable full-static build on Windows
Glib cannot be built statically on Windows because glib, gobject and gio
modules need to perform specific initialization when DLL are loaded and
cleanup when unloaded. Those initializations and cleanups are performed
using the DllMain function which is not called with static builds.

Issue is known for a while and solutions were already proposed but never
merged (see: https://gitlab.gnome.org/GNOME/glib/-/issues/692). Last
patch is from version 2.36.x and since then the
"constructor/destructor" mechanism has been implemented and used in
other part of the system.

This patch takes back the old idea and updates it to the last version of
glib to allow static compilation on Windows.

WARNING: because DllMain doesn't exist anymore in static compilation
mode, there is no easy way of knowing when a Windows thread finishes.
This patch implements a workaround for glib threads created by calling
g_thread_new(), so all glib threads created through glib API will behave
exactly the same way in static and dynamic compilation modes.
Unfortunately, Windows threads created by using CreateThread() or
_beginthread/ex() will not work with glib TLS functions. If users need
absolutely to use a thread NOT created with glib API under Windows and
in static compilation mode, they should not use glib functions within
their thread or they may encounter memory leaks when the thread finishes.

This should not be an issue as users should use exclusively the glib API
to manipulate threads in order to be cross-platform compatible and this
would be very unlikely and cumbersome that they may mix up Windows native
threads API with glib one.

Closes #692
2022-01-26 10:14:02 +01:00
Sebastian Dröge
3b3022dff1 Merge branch 'doc_sync_signals' into 'main'
Make clear in doc that signals are emitted synchroniously

See merge request GNOME/glib!2423
2022-01-18 08:53:21 +00:00
Alexander Schwinn
28d833a075 Make clear in doc that signals are emitted synchroniously 2022-01-18 08:53:20 +00:00
Emmanuel Fleury
66ebcbced4 Merge tests/gobject/paramspec-test.c into gobject/tests/param.c
Helps issue #1434
2022-01-17 20:43:27 +00:00
Emmanuel Fleury
86fedcfb93 Merge tests/gobject/gvalue-test.c with gobject/tests/value.c
Helps issue #1434
2022-01-12 21:51:05 +01:00
Bilal Elmoussaoui
2f9b3ec6cc paramspec: fix unref annotation 2021-12-30 12:40:47 +00:00
Emmanuel Fleury
c8274a51cd Fix defined but not used warning in gobject/gobject.c
gobject/gobject.c:1189:1: warning: ‘floating_check’ defined but not used
2021-12-17 15:30:18 +01:00
Emmanuel Fleury
ae345e56c2 Distribute cxx test tests/cxx-test.cpp to each module tests directory
tests/cxx-test.cpp is removed and splitted into gio/tests/cxx.cpp,
gmodule/tests/cxx.cpp and gobject/tests/cxx.cpp.

Helps issue #1434
2021-12-14 14:43:03 +01:00
Emmanuele Bassi
1ec331266a Defer GObject::notify during object destruction
Notifying during object destruction is a dubious "feature": objects
might end up recreating a bunch of state just before clearing it;
language bindings might get spurious notifications during garbage
collection runs.

We freeze the notification queue before running the dispose() chain; if
the object was temporarily vivified during dispose, we thaw the
notification queue, otherwise we let the instance clear it when we
finalize it.

See: https://gitlab.gnome.org/GNOME/gjs/-/issues/445
2021-11-29 15:43:59 +00:00
Nishal Kulkarni
1529c2ca4d gobject: Use new g_newa0() function
Replace old `g_newa()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Nishal Kulkarni
34cf69ef17 gsignal: Use new g_newa0() function
Replace old `g_alloca()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Sebastian Dröge
c3f4f9c215 Merge branch 'reformat-enums' into 'main'
tests: Reformat mkenums.py slightly to make run-black.sh happy

See merge request GNOME/glib!2342
2021-11-22 13:54:42 +00:00
Philip Withnall
7a8756d247 gobject: Add advice on larger alignment requirements for GObject members
We now guarantee that GObjects will always be allocated at least as
aligned as the basic types. If you want to put an element in your
GObject which has higher alignment requirements, we can’t guarantee it
will be aligned*. If you need it to be aligned, you’ll need to put it on
the heap (aligned appropriately), or add appropriate padding in your
GObject struct.

*Actually, GSlice will guarantee that the whole GObject is aligned to at
least the power of 2 greater than or equal to the size of the GObject,
which means any element in the GObject struct should always be
appropriate aligned if the compiler pads it appropriately. If malloc()
is used, however, it doesn’t make that guarantee, so we can’t make that
guarantee overall.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
ed553e8e30 gtype: Eliminate -Wcast-align warnings with G_TYPE_CHECK_INSTANCE_CAST
Regardless of the actual alignment of the GTypeInstance in question,
these do a runtime check on the type, so if the type was originally
aligned correctly when allocated, it should be aligned correctly if the
type check succeeds. -Wcast-align is meant to warn about casts between
types, which this isn’t (if the check succeeds).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
0749643daa gobject: Assert that GObjects are at least as aligned as basic types
See the reasoning in the patch for why we believe GObjects *are*
(already) as aligned as the basic types.

We want to make this guarantee so that it’s guaranteed to be safe for
people to ignore -Wcast-align warnings for GObjects which contain basic
types. This typically happens with gdouble on 32-bit ARM platforms.

The checks are slightly complicated by the need to support GObjects with
custom constructors. We should expect that a custom construction
function will chain up to g_object_constructor (which calls
g_type_create_instance() as normal), but it’s possible that someone has
done something crazy and uses a custom allocator which doesn’t return
with the same alignment as GSlice. Hand them a warning in that case. If
that is true, the code which uses their custom-constructed GObject can
presumably already deal with the alignment it gets given.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
c6dca3459b tests: Reformat mkenums.py slightly to make run-black.sh happy
This should remove some warnings from the CI, making it easier to see
legitimate CI failures.

For example, see https://gitlab.gnome.org/GNOME/glib/-/jobs/1621041.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-17 10:37:07 +00:00
Michael Catanzaro
98e0789fea Merge branch 'weak-refs-docs' into 'main'
gobject: Clarify behaviour of adding weak refs during disposal

See merge request GNOME/glib!2255
2021-10-27 23:37:22 +00:00
Philip Withnall
2423419a29 Merge branch 'static-analysis' into 'main'
fix issues found by svace static code analyzer

See merge request GNOME/glib!2285
2021-10-18 11:03:33 +00:00
Egor Bychin
5419228f63 gtype: Fix pointer being dereferenced despite NULL check 2021-10-15 14:15:43 +03:00
Philip Withnall
a4c9049486 build: Don’t pass false to install_dir
This fixes a Meson deprecation warning which appeared in Meson 0.50.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-07 17:15:13 +01:00
Simon McVittie
6ccb387197 Merge branch 'object-weak-ref-docs' into 'main'
gobject: Document it’s unsafe to call g_object_ref() from GWeakNotify

See merge request GNOME/glib!2246
2021-09-28 09:24:47 +00:00
Philip Withnall
579ff9f6c9 Merge branch 'ebassi/floating-warning' into 'main'
Add a (diagnostic) warning for finalized floating objects

Closes #2489

See merge request GNOME/glib!2247
2021-09-21 11:09:16 +00:00
Marco Trevisan (Treviño)
468246bb3b gobject: Ensure an object has toggle references before notifying it
When an object with toggle reference is notifying a change we just
assume that this is true because of previous checks.
However, while locking, another thread may have removed the toggle
reference causing the waiting thread to abort (as no handler is set at
that point).

To avoid this, once we've got the toggle references mutex lock, check
again if the object has toggle reference, and if it's not the case
anymore just ignore the request.

Add a test that triggers this, it's not 100% happening because this is
of course timing related, but this is very close to the truth.

Fixes: #2394
2021-09-20 17:56:25 +02:00