Commit Graph

2126 Commits

Author SHA1 Message Date
Michael Catanzaro
b8e1ecdd6b Automatically disable cast checks when building with optimization
Cast checks are slow. We seem to have some rough consensus that they are
important for debug builds, but not for release builds. Problem is, very
few apps define G_DISABLE_CAST_CHECKS for release builds. Worse, it's
undocumented, so there's no way apps could even be expected to know
about it.

We can get the right default is almost all situations by making this
depend on the __OPTIMIZE__ preprocessor definition. This is a GCC-specific
thing, although Clang supports it too. If the compiler does not define
__OPTIMIZE__, then this commit does no harm: you can still use
G_DISABLE_CAST_CHECKS as before. When checking __OPTIMIZE__, we are
supposed to ensure our code has the same behavior as it would if we do
not, which will be true except in case the check fails (which is
programmer error).

Downside: this will not automatically do the right thing with -Og,
because __OPTIMIZE__ is always defined to 1. We don't want to disable
cast checks automatically if using -O0 or -Og. There's no way to
automatically fix this, but we can create an escape hatch by allowing
you to define G_DISABLE_CAST_CHECKS=0 to force-enable cast checks. In
practice, I don't think this matters much because -Og kinda failed:
GCC's man page says it should be a superior debugging experience to -O0,
but it optimizes variables away so it's definitely not.

Another downside: this is bad if you really *do* want cast checks in
release builds. The same solution applies: define
G_DISABLE_CAST_CHECKS=0 and you'll get your cast checks.
2022-08-03 16:18:17 -05:00
Emmanuele Bassi
8f68c1e646 Rename G_MARKUP_PARSE_FLAGS_NONE
The prefix for GMarkupParseFlags enumeration members is G_MARKUP; this
means that G_MARKUP_PARSE_FLAGS_NONE gets split into
GLib.MarkupParseFlags.PARSE_FLAGS_NONE by the introspection scanner.

The `/*< nick=none >*/` trigraph attribute is a glib-mkenum thing, and
does not affect the introspection scanner; it would also only affect the
GEnumValue nickname, which is not used by language bindings to resolve
the name of the enumeration member. Plus, GMarkupParseFlags does not
have a corresponding GType anyway.
2022-07-25 22:30:22 +01:00
Simon McVittie
72868c026d gobject/tests/performance: Only run a quick version as installed-tests
ginsttest-runner defaults to timing out each test after 5 minutes,
but gobject/tests/performance/performance.c defaults to running each
of 18 tests for 15 seconds. The result is close enough to 5 minutes
that the setup overhead is enough to make it time out.

We're only running these tests to prove that they still work, not to
get meaningful performance numbers, so cut them down to 1 second per
test-case (the result of which is that performance.c takes about a
minute).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 17:34:55 +01:00
Simon McVittie
0714bcb7f4 gobject/tests/performance: Use the other installed-tests template
These are not GTest tests, and don't output TAP.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 17:15:47 +01:00
Philip Withnall
55928d6ac0 Merge branch 'more-atomic-ops' into 'main'
Use atomic exchange operations more

See merge request GNOME/glib!2759
2022-07-23 11:35:08 +00:00
Philip Withnall
b33ba73532 Merge branch 'gsignal-threading-cleanup' into 'main'
gsignal: Perform signal unlocked handlers block, unblock and disconnect ops

See merge request GNOME/glib!2823
2022-07-15 21:36:28 +00:00
James Hilliard
d0b9ebbaac meson: fix build without cpp toolchain
We don't need a cpp toolchain for building glib so lets just
automatically disable tests requiring one when not available.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-07-15 12:58:41 -06:00
Marco Trevisan (Treviño)
42d52033db gsignal: Do not try to lookup the signal id and work on unlocked node
In g_signal_parse_name we were looking up for the signal from the name
keeping the mutex locked, but we then retrieved and checked the node
data without keeping the lock, so with another thread potentially
changing that.
2022-07-15 16:09:14 +02:00
Marco Trevisan (Treviño)
ae14f3219a gsignal: Perform signal unlocked handlers block, unblock and disconnect ops
We used to perform unneeded lock/unlock dances to perform block, unblock
and disconnect actions, and these were potentially unsafe because we
might have looped in data that could be potentially be changed by other
threads.

We could have also done the same by saving the handlers ids in a
temporary array and eventually remove them, but I don't see a reason for
that since we can just keep all locked without the risk of creating
deadlocks.

Coverity CID: #1474757, #1474771, #1474429
2022-07-15 16:05:35 +02:00
Marco Trevisan (Treviño)
28dc989fc1 gobject/tests: Add test to verify that custom dispatch is called on init
As per this, rename the old test so that it's more in line with the
new one and with what it does.
2022-07-09 00:24:13 +02:00
Marco Trevisan (Treviño)
ed130c8d3b gobject/tests/custom-dispatch: Mark the foo property as explicit-notify
We're calling g_object_notify so let's not make gobject to call it for
us.

This also allows to test that changing a property again doesn't lead to
dispatch properties being called.
2022-07-08 23:54:43 +02:00
Peter Bloomfield
3290ebfadc gobject: Small speedup in weak-ref-set 2022-07-08 14:37:53 +00:00
Matthias Clasen
edcd2d4df4 Add a test for custom dispatch_properties_changed
This tests that we call a custom dispatch_properties_changed,
even in the absence of connected notify handlers. (A recent
optimization broke that and caused a regression in GTK).
2022-07-08 14:03:34 +01:00
Matthias Clasen
c0a618a716 gobject: Don't skip custom dispatch_properties_changed
When I optimized GObject to skip property notification
in some cases, I looked for whether the class has a
custom notify vfunc. I overlooked that that
dispatch_properties_changed can also be customized,
and if it is, we better not skip change notification.

This showed up as breakage in the adjustment tests
in the GTK testsuite.
2022-07-08 13:57:40 +01:00
Philip Withnall
ed564b71dd Merge branch '2672-dataset-tests-and-fixes' into 'main'
gdataset: Preserve destruction order

Closes #2672 and #2676

See merge request GNOME/glib!2776
2022-07-07 11:52:19 +00:00
Philip Withnall
8385f52db7 Merge branch 'inline-macros' into 'main'
gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINE

See merge request GNOME/glib!2781
2022-07-06 13:40:10 +00:00
Marco Trevisan (Treviño)
a6f8fe071e cleanup: Replace G_GNUC_NO_INLINE with G_NO_INLINE
As per this we can also now mark G_GNUC_NO_INLINE as
GLIB_AVAILABLE_MACRO_IN_2_58, given that we don't have anymore headers
using it.
2022-07-06 14:57:06 +02:00
Philip Withnall
41691cc4c8 Merge branch 'more-spdx' into 'main'
Add more SPDX license headers

See merge request GNOME/glib!2706
2022-07-05 11:06:49 +00:00
Peter Bloomfield
4ef2025d47 gobject/tests/binding: Add a test with run-dispose
Add tests in which `g_object_run_dispose()` is called on the source or target
of a `GBinding`. After commit a4fa456e67,
the target test caused a failed assertion in `g_weak_ref_set()` that was not
found by the existing tests.  Commit 94ba14d542
weakens the assertion to allow the test to succeed.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2676
2022-07-04 13:16:21 -04:00
Peter Bloomfield
94ba14d542 gobject: Weaken an assertion in g_weak_ref_set()
When weak references are being cleaned up, it is possible for the `qdata` for
both `quark_weak_locations` and `quark_weak_refs` to have been deallocated,
so that `g_datalist_id_get_data()` returns `NULL` for both. This happens
when `g_object_run_dispose()` is called for the target of a `GBinding`,
and is not an error.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2676
2022-07-03 14:56:44 -04:00
Emmanuele Bassi
c4f9b926d8 Add versioning to the new macros
They are available in 2.74.
2022-06-30 01:46:54 +01:00
Emmanuele Bassi
c0766caf20 Use varargs for enum types definition macros
Makes the syntax a little bit better.
2022-06-30 01:46:54 +01:00
Emmanuele Bassi
fa05ebe27c docs: Mention alternatives for defining enumeration types
We should mention glib-mkenums in the documentation for
G_DEFINE_ENUM_TYPE and G_DEFINE_FLAGS_TYPE.

We should also mention the macros in the documentation for glib-mkenums.

This way, developers can choose the most appropriate tool for their use
case.
2022-06-30 01:46:54 +01:00
Emmanuele Bassi
6cbf7a7461 Port enums tests to the appropriate assert functions
Do not use `g_assert()` inside tests, as the symbol can be disabled.
Instead, use `g_assert_null()` and `g_assert_nonnull()`.
2022-06-30 01:46:54 +01:00
Emmanuele Bassi
2a9ef1e0b4 Test the newly added G_DEFINE macros for enumeration types 2022-06-30 01:46:54 +01:00
Emmanuele Bassi
9a4a10fbc8 Add G_DEFINE macros for enum and flags types
While you might want to use automated tools like glib-mkenums to
generate enumeration types for your library, it's often not entirely
necessary to complicate your build system in order to handle a couple of
enumerations with few values.

Just like we have G_DEFINE macros for object, interface, pointer, and
boxed types, we should provide macros for defining enum and flags types.
2022-06-30 01:46:54 +01:00
Emmanuel Fleury
5699b7b169 Fix some coding style issues in python tests pointed out by black and flake8 2022-06-28 11:19:21 +01:00
Simon McVittie
d4043eced5 Revert "gobject: Use g_datalist_id_remove_multiple"
This reverts commit fa8c7c0 "gobject: Use g_datalist_id_remove_multiple"
(or more specifically the parts of it that were not already reverted
in 01ac1d9 "gobject: Fix crash when disposing a GtkAccelGroup".

Workaround for https://gitlab.gnome.org/GNOME/glib/-/issues/2676

Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2676
2022-06-26 18:00:52 +01:00
Marco Trevisan (Treviño)
920f54e795 gatomicarray: Use atomic exchange for data value
We can use pointer exchange now to avoid doing two operations to switch
to the new data pointer.

Since we're asserting in case of invalid data, we can just do this check
at later point, without involving any different behavior.

This changes in the unlikely case that G_DISABLE_ASSERT is defined, as in such
case we should undo the operation.
2022-06-23 20:01:12 +02:00
Philip Withnall
191923ce61 Merge branch 'wip/smcv/none-flags' into 'main'
Add a NONE or DEFAULT member to most flags-sets

See merge request GNOME/glib!2576
2022-06-23 16:09:38 +00:00
Marc-André Lureau
a5d551e2be gobject/tests/performance: fix leaks
Easily spotted by ASAN.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-06-23 17:18:21 +04:00
Simon McVittie
879b9cd669 gregex: Add G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:39 +01:00
Simon McVittie
0d4e401ede gmarkup: Add G_MARKUP_PARSE_FLAGS_NONE
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:27 +01:00
Simon McVittie
de8672fe0b gtestutils: Add G_TEST_SUBPROCESS_DEFAULT, G_TEST_TRAP_DEFAULT
This makes calls to test subprocesses with default behaviour more
self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:47:13 +01:00
Simon McVittie
7045260c22 gsignal: Add G_CONNECT_DEFAULT
This makes calls to g_signal_connect_data() and g_signal_connect_object()
with default flags more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:46:45 +01:00
Simon McVittie
5e164c6615 gtype: Add G_TYPE_FLAG_NONE
This makes code that sets no flags a bit more self-documenting:
using G_TYPE_FLAG_NONE makes it clearer that no special behaviour is
required than literal 0, and clearer that there is no weird casting
between types than (GTypeFlags) 0.

GTypeFlags and GTypeFundamentalFlags occupy the same namespace and the
same bitfield, so I intentionally haven't added
G_TYPE_FUNDAMENTAL_FLAGS_NONE.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-23 10:45:31 +01:00
Marco Trevisan
cb0cc996ee Merge branch 'test-suite-fixes' into 'main'
tests: Various fixes for TAP output of tests

See merge request GNOME/glib!2749
2022-06-22 18:48:59 +00:00
Philip Withnall
f805635e11 Merge branch 'coverity-signal-emissions' into 'main'
gsignal: Change signal instance ref semantics under static analysis

See merge request GNOME/glib!2762
2022-06-21 12:54:41 +00:00
Philip Withnall
95d548ab03 gsignal: Change signal instance ref semantics under static analysis
As with commit 0932f71460, which did this for refs/unrefs of the
object in `g_object_notify()`, we need to do a similar thing for
refs/unrefs of the instance with `g_signal_emit()`, for all the same
reasons.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 13:27:52 +01:00
Philip Withnall
1aaf1e7de1 tests: Allow signal-handler performance tests to be smoketested
As with the previous commit, allow them to be smoketested when run
without `-m perf`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:57:33 +01:00
Philip Withnall
6f435e40cd tests: Run GObject performance tests under meson test
Pass arguments to them so that they take minimal time. This will not
produce useful performance profiling results, but will smoketest that
the tests still run, don’t crash, and therefore probably aren’t
bitrotting too badly.

This is useful because a fair amount of work has gone into these
performance tests, and they’re useful every few years to analyse and
compare GObject performance. We don’t want them to bitrot between uses.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:57:33 +01:00
Philip Withnall
6747702d77 tests: Fix use of deprecated threading API in performance-threaded
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
6b8240f061 tests: Fix performance-threaded test when run for zero seconds
When running the test with `-s 0` it would previously crash. Fix that,
and make it so that it only does a single test run in that case.

This will be useful in an upcoming commit for smoketesting the test to
avoid bitrot.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
74e71c78c0 tests: Fix a non-TAP formatted debug message in the basics-gobject test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
1b377e6574 build: Drop MALLOC_PERTURB_ from test environments
It’s set already by Meson, to an actually random value.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-21 12:50:31 +01:00
Philip Withnall
01ac1d902f gobject: Fix crash when disposing a GtkAccelGroup
This is a partial revert of commit fa8c7c0da using the approach
suggested (and tested) by Kjell Ahlstedt.

It is intended to be temporary pending a proper dig into what’s causing
the regression, just so we can get the 2.73.1 release out.

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

Helps: #2672
2022-06-20 16:32:00 +01:00
Philip Withnall
b2f4df95e8 Merge branch 'coverity-is-stupid' into 'main'
gobject: Change GObject notify semantics under static analysis

See merge request GNOME/glib!2747
2022-06-17 15:47:39 +00:00
Philip Withnall
0932f71460 gobject: Change GObject notify semantics under static analysis
Coverity notices the `g_object_unref()` call in `g_object_notify()`, but
not the paired `g_object_ref()` call. It therefore incorrectly assumes
that every call to `g_object_notify()` frees the object. This causes a
lot (hundreds) of false positive reports about double-frees or
use-after-frees.

I can’t find a way to fix this using a model file, so the other options
are:
 * Manually mark every report as a false positive and keep updating them
   as the code changes over time. This would take a lot of maintainer
   effort.
 * Comment out the `g_object_ref()`/`g_object_unref()` calls when
   running static analysis (but not in a normal production build). This
   is ugly, but cheap and shouldn’t impact maintainability much.

So this commit implements option 2.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-14 11:25:50 +01:00
Philip Withnall
af7ba68a00 gobject: ifdef out some inline functions if they’re not used
This prevents `-Wunused-function` warnings on platforms which don’t have
`HAVE_OPTIONAL_FLAGS` defined.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-14 11:10:09 +01:00
Matthias Clasen
10a1c16b59 Avoid atomics during construction
During construction, we have exclusive access to
the object, so there is no need to use atomics
for setting or reading the optional_flags member.
2022-06-14 11:09:53 +01:00
Matthias Clasen
b92f1fcbc5 Handle notify freezing with custom constructors
g_object_new_with_custom_constructor needs to handle
freezing notifications in the same way as
g_object_new_internal.

Fixing a bug pointed out by Christian Hergert.
2022-06-12 12:01:25 -04:00
Matthias Clasen
dccab10d9f Add another testcase
This is similar to the notify-in-init testcase
added recently, but with a custom constructor.
2022-06-12 12:01:16 -04:00
Matthias Clasen
58ab960a87 Handle a corner-case of notify avoidance
The corner-case we are handling here is that
we don't freeze the notify queue in g_object_init
(because there's no custom ->notify vfunc, but
then we gain a notify handler during instance
init, and instance init also triggers a
notification. Handle this by jit freezing
notification in g_object_notify_by_spec_internal.

Note that this is bad code - instance init really
shouldn't be doing things like this.

Testcase included.

Fixes: #2665
2022-06-12 12:01:08 -04:00
Matthias Clasen
9444ace2c8 Unconditionally mark objects as in-construction
This will be used for things other than
custom constructors in the following commits.
2022-06-12 12:01:08 -04:00
Matthias Clasen
fb380b9899 Add a testcase for notify-in-instance-init
This is reproducing a problem that was observed
in gtk3's gtk_check_button_init.
2022-06-12 12:01:08 -04:00
Matthias Clasen
98bd4eabf2 gobject: Don't thaw excessively
We need to match the conditions in g_object_init
for when we already have a freeze. Without that,
we underflow the freeze count and trigger a
warning.

Fixes: #2666
2022-06-10 14:09:08 +01:00
Matthias Clasen
12152788f9 tests: Add a singleton construct-property test
Beef up the singleton testcase to reproduce a
freeze count underflow when setting properties
at construction time, with a custom constructor.

Helps: #2666
2022-06-10 14:09:07 +01:00
Philip Withnall
9af0444b92 tests: Simplify singleton test code using G_DECLARE_FINAL_TYPE
This doesn’t functionally change the test, just drops some boilerplate.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-10 14:09:07 +01:00
Philip Withnall
7a4560e052 tests: Port GObject singleton test to GTest framework
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-10 14:09:07 +01:00
Philip Withnall
edd497fc99 Merge branch 'binding-code-duplication' into 'main'
gbinding: Remove some duplicated code for checking property names and improve tests slightly

See merge request GNOME/glib!2740
2022-06-10 11:24:09 +00:00
Philip Withnall
103a9d5ae1 Merge branch 'gobject-query' into 'main'
gobject-query: Minor cleanups and add unit tests

See merge request GNOME/glib!2739
2022-06-09 17:33:13 +00:00
Philip Withnall
67a168c5d1 tests: Test g_binding_get_source() and g_binding_get_target()
These are deprecated, but it’s easy enough to test them anyway. This
bumps up code coverage a bit and hopefully ensures we don’t accidentally
regress on them in future.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 18:20:29 +01:00
Philip Withnall
714a0aa47d gbinding: Remove some duplicated code for checking property names
GObject already exports a public symbol for this with identical code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 18:20:06 +01:00
Philip Withnall
c49f481967 tests: Add basic tests for gobject-query utility
At the moment these tests basically just ensure that the program’s
compiled properly and doesn’t crash on startup. They don’t check
functionality very deeply.

But they’re a start.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:26:15 +01:00
Philip Withnall
fbdbbfa580 gobject-query: Add a --version argument
This has been documented in `man gobject-query` for a long time, but
seemingly never implemented.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:25:35 +01:00
Philip Withnall
6211e25953 gobject-query: Combine two identical if-branches
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:23:11 +01:00
Philip Withnall
ad77557277 gobject-query: Print --help output to stdout rather than stderr
UNIX tools print `--help` output to stdout by convention.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:22:51 +01:00
Philip Withnall
993f3f4407 gobject-query: Make a --help string slightly more helpful
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:06:25 +01:00
Philip Withnall
98e6ac788e gobject-query: Remove extraneous blank line between each output line
I don’t think it improves the output format.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:06:03 +01:00
Philip Withnall
91ff469f7e gobject-query: Use proper Unicode tree drawing characters
This makes the output a lot nicer to read:
```
│
├void
│
├GInterface
│ │
│ └GTypePlugin
│
├gchar
⋮
```
rather than
```
|
`void
|
`GInterface
  |
  `GTypePlugin
|
`gchar
⋮
```

It includes a change to correctly use vertical tees at the top level by
correctly setting the sibling node rather than always setting it to
zero.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 13:04:49 +01:00
Philip Withnall
17a1c29850 gobject-query: Delete unused code
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-09 12:51:06 +01:00
Philip Withnall
d463de05b1 tests: Move GObject performance tests to gobject/tests/performance/
This doesn’t change the tests’ behaviour, but moves them to a slightly
more logical location.

They are still not installed or run by default.

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

Helps: #1434
2022-06-08 11:30:31 +01:00
Philip Withnall
5d498f4d1c Merge branch 'move_testgobject' into 'main'
Move tests/gobject/testgobject.c to gobject/tests/basics-gobject.c

See merge request GNOME/glib!2696
2022-06-08 09:52:55 +00:00
Matthias Clasen
426724d51c Add some tests around properties
Install the properties with a mixture of
g_object_class_install_properties and
g_object_class_install_properties, and verify
that finding them still works, regardless of
whether we use string literals or not.
2022-06-07 22:49:30 -04:00
Matthias Clasen
df43536a68 Consistently use param_spec_follow_override 2022-06-07 12:39:58 -04:00
Matthias Clasen
47c12389a0 gobject: Speed up property lookup
When the param specs are provided as an array
with g_object_class_install_properties, keep
a copy of that array around and use it for
looking up properties without the param spec
pool.

Note that this is an opportunistic optimization -
currently, it only works for properties of the
class itself, not for parent classes, and it
only works if the property names are identical
string literals (we're at the mercy of the linker
for that).

If we don't get lucky, we fall back to using
the pspec pool as usual.
2022-06-07 12:39:58 -04:00
Philip Withnall
12dc714437 Merge branch 'gobject-speedup11' into 'main'
Keep a separate flag for notify handlers

See merge request GNOME/glib!2725
2022-06-07 13:43:50 +00:00
Philip Withnall
18a7b19a99 Merge branch 'revert-final-type-check' into 'main'
Revert "gtype: Speed up type checks for final types"

Closes #2661

See merge request GNOME/glib!2727
2022-06-07 11:50:58 +00:00
Philip Withnall
3076c60e9c Merge branch 'gobject-speedup10' into 'main'
gobject: Avoid redundant atomics

See merge request GNOME/glib!2724
2022-06-07 11:46:23 +00:00
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