Commit Graph

2040 Commits

Author SHA1 Message Date
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