Commit Graph

287 Commits

Author SHA1 Message Date
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
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
Jason Francis
2a842b1173 gobject: Add g_signal_group_connect_closure 2022-04-05 15:32:20 +01: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
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
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
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
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
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
Marco Trevisan (Treviño)
a7262d6357 gobject: Cleanup weak locations data as part of dispose
Weak locations were not fully cleaned on run_dispose() and after dispose
vfunc was called, so ensure that this is the case.

Fixes: #865
2021-09-17 12:28:01 +02:00
Marco Trevisan (Treviño)
e861f60dcb gobject: Cleanup weak locations when the last one has been removed
As per the previous change, an object that had weak locations set may
need to lock again the weak locations mutex during qdata cleanup, but
we can avoid this when we know we're removing the last location, by
removing the qdata entry and freeing the data.

In case a new location is needed for the same object, new data will be
added.

However, by doing this the weak locations during dispose may be
invalidated once the weak locations lock is passed, so check again if
this is the case while removing them.
2021-09-17 12:27:59 +02:00
Marco Trevisan (Treviño)
ea68b22135 gobject: Cleanup GWeakRef locations on object finalization
It can happen that a GWeakRef is added to an object while it's disposing
(or even during finalizing) and this may happen in a thread that (weak)
references an object while the disposal isn't completed yet or when
using toggle references and switching to GWeakRef on notification (as
the API suggests).

In such scenario the weak locations are not cleaned up when the object
is finalized, and will point to a free'd area.

So, during finalization and when we're sure that the object will be
destroyed for sure, check again if there are new weak locations and
unset them if any as part of the qdata destruction.
Do this adding a new utility function so that we can avoid duplicating
code to free the weak locations.

Added various tests simulating this case.

Fixes: #2390
2021-09-17 12:21:23 +02:00
Emmanuele Bassi
9aacb4dd6f Add unit for the "final" GType flag
Check that we're emitting the correct set of warnings when trying to
derive a final type.
2021-07-27 12:27:53 +01:00
GOUJON Évan
6e46edea5b gobject/tests/param: Fix a memory leak 2021-07-23 22:21:33 +02:00
Allison Ryan Lortie
3764c6730e GObject: add g_object_take_ref()
This works in the same way as g_variant_take_ref(), and for the same
reason.

Updated and Rebased by Nitin Wartkar <nitinwartkar58@gmail.com>

Closes #1112
2021-06-11 18:13:34 +05:30
Philip Withnall
7e9585177d tests: Drop use of g_test_bug_base()
Include the base URI in the `g_test_bug()` calls instead. This resolves
inconsistencies between the old bug base (bugzilla.gnome.org) and the
new bug base (gitlab.gnome.org). It also has the advantage that the URI
passed to `g_test_bug()` is now clickable in the code editor, rather
than being split across two locations.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/275#note_303175

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-13 22:16:27 +01:00
Marco Trevisan (Treviño)
b8a9f4b436 boxed: Register GPatternSpec as boxed type 2021-04-27 16:25:09 +02:00
Philip Withnall
856aeba9e4 glib-mkenums: Parse and skip deprecation/availability annotations
Teach `glib-mkenums` how to parse and ignore:
 - `GLIB_AVAILABLE_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx_FOR(x)`

Future work could expose the deprecation/availability information as
substitutions in the template file, but this commit does not do that.

It does, however, add some unit tests for the annotations.

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

Fixes: #2327
2021-03-11 13:37:49 +00:00
Philip Withnall
f10101b909 gobject: Use g_memdup2() instead of g_memdup() in obvious places
Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 14:13:21 +00:00
Matthias Klumpp
1261461840 mkenums: Support public/private trigraphs again
This change was previously implemented in
9ba17d511e but got dropped during the
Python conversion of the Perl script.

See the commit message of this commit as well as
https://bugzilla.gnome.org/show_bug.cgi?id=782162
for more information.
This patch also adds a new test so we don't loose this feature again.
2021-01-10 20:51:54 +01:00
Sebastian Dröge
3581eda9a2 gsignal: Allow return types for RUN_FIRST-only signals too
Also adds a test that checks that the G_SIGNAL_RUN flags are handled
correctly and the class signal handler is called at the right times.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/513
2020-12-21 17:22:51 +00:00
Sebastian Dröge
9d1455444c gsignal: Add a new GSignalFlag to mark the first run of an accumulator function
Also add a test for signal accumulators. There was none before, and this
one now also covers the new flag.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/514
2020-12-21 17:10:19 +00:00
Emmanuel Fleury
6ca38ccdd4 Fix missing initializer warning in gobject/tests/ifaceproperties.c:base_object_get_type()
gobject/tests/ifaceproperties.c: In function ‘base_object_get_type’:
gobject/tests/ifaceproperties.c:321:1: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
  321 | static DEFINE_TYPE_FULL (BaseObject, base_object,
      | ^~~~~~
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/ifaceproperties.c:21:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 23:59:17 +01:00
Emmanuel Fleury
ff5d09af5e Fix missing initializer warning in gobject/tests/ifaceproperties.c:test_iface_get_type()
gobject/tests/ifaceproperties.c: In function ‘test_iface_get_type’:
gobject/tests/ifaceproperties.c:144:1: error: missing initializer for field ‘class_finalize’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
  144 | static DEFINE_IFACE (TestIface, test_iface, NULL, test_iface_default_init)
      | ^~~~~~
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/ifaceproperties.c:21:
gobject/gtype.h:1054:26: note: ‘class_finalize’ declared here
 1054 |   GClassFinalizeFunc     class_finalize;
      |                          ^~~~~~~~~~~~~~
2020-12-16 23:57:08 +01:00
Emmanuel Fleury
805053d09b Fix signedness warning in gobject/tests/signals.c:test_introspection()
gobject/tests/signals.c: In function ‘test_introspection’:
gobject/tests/signals.c:1180:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1180 |   for (i = 0; i < n_ids; i++)
      |                 ^
2020-12-16 23:26:34 +01:00
Emmanuel Fleury
176b204754 Fix signedness warnings in gobject/tests/properties.c:properties_get_property()
gobject/tests/properties.c: In function ‘properties_get_property’:
gobject/tests/properties.c:562:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  562 |   for (i = 0; i < G_N_ELEMENTS (test_props); i++)
      |                 ^
gobject/tests/properties.c:583:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  583 |   for (i = 0; i < G_N_ELEMENTS (test_props); i++)
      |                 ^
2020-12-16 23:26:34 +01:00
Philip Withnall
db70edb6ec Merge branch 'fix_more_warnings' into 'master'
Fix more warnings

See merge request GNOME/glib!1773
2020-12-16 11:45:41 +00:00
Emmanuel Fleury
8fb696e003 Fix missing initializer warning in gobject/tests/dynamictests.c:test_module_get_type()
gobject/tests/dynamictests.c: In function ‘test_module_get_type’:
gobject/tests/dynamictests.c:97:7: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
   97 |       };
      |       ^
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/dynamictests.c:23:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 10:56:32 +01:00
Philip Withnall
39f33412db python: Reformat some files to keep style-check-diff happy
The version of `black` on the CI server wanted these changes. Make them
to keep the `style-check-diff` CI job from constantly failing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:40:57 +00:00
Emmanuel Fleury
bbb9ef19ce Fix signedness warnings in gobject/tests/value.c:test_valuearray_basic()
gobject/tests/value.c: In function ‘test_valuearray_basic’:
gobject/tests/value.c:253:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  253 |   for (i = 0; i < a->n_values - 1; i++)
      |                 ^
gobject/tests/value.c:257:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  257 |   for (i = 0; i < a->n_values; i++)
      |                 ^
2020-12-05 17:11:55 +01:00
Sebastian Dröge
52261f0abe Deprecate g_binding_get_source() and get_target() in favour of dup_source() and dup_target()
The old functions are not thread-safe by design.
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
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
8a112c3c6e tests: Drop unnecessary volatile qualifiers from tests
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
fab561f8d0 gobject: Drop use of volatile from get_type() macros
http://isvolatileusefulwiththreads.in/c/

It’s possible that the variables here are only marked as volatile
because they’re arguments to `g_once_*()`. Those arguments will be
modified in a subsequent commit.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
d270b6c3db py: Various flake8 cleanups
None of these are particularly significant, but they do get the CI
output clean.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Philip Withnall
905b22a17e py: Reformat all Python files consistently
This commit is the unmodified results of running
```
black $(git ls-files '*.py')
```
with black version 19.10b0. See #2046.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Matthias Clasen
0b1f909691 Add a test for signals returning interface types
Add a test for a signal returning interface types, using
the generic marshaller. This will hopefully exercise newly
added code in value_from_ffi_type().
2020-11-02 17:36:18 +00:00
Matthias Clasen
52357aac44 Add a binding test involving interfaces
This tests the new functionality that
g_type_interface_instantiable_prerequisite
was added for.

Before the changes, this fails with
GObject-WARNING **: Unable to convert a value of type \
                    GObject to a value of type Foo

We do the same test with g_object_bind_property_with_closures
as well, to exercise g_cclosure_marshal_generic.
2020-11-02 17:36:18 +00:00
Benjamin Otte
458e3b7a84 value: Allow automatic transforms to/from interfaces
Use the new g_type_interface_instantiable_prerequisite() to check
compatibility for transform functions.

In particular, this allows interfaces (in my case GDK_TYPE_PAINTABLE) to
be transformed to/from any GObject type (in my case G_TYPE_OBJECT) using
the transform function registered to transform between any 2 objects
(g_value_object_transform_value() does a type check and uses NULL if the
types don't match).

And this in turn allows be to g_object_bind_property() a gobject-typed
generic property (GtkListItem::item) to a GtkImage::paintable.

Tests for the new functionality are included.
2020-11-02 17:36:18 +00:00
Benjamin Otte
98f0a5a7da gtype: Add g_type_interface_instantiatable_prerequisite()
This function returns the most specific instantiatable type
that is a prerequisite for a given interface.

This type is necessary in particular when dealing with GValues
because a GValue contains an instance of a type.

This commit includes tests for the new API.
2020-11-02 17:36:18 +00:00
Benjamin Otte
1f6c73747e Suggest braces around empty body in ‘if’ statements 2020-11-02 17:36:18 +00:00
Andrew Potter
3dc62171eb Add boxing for GTree
Closes issue #1233
2020-10-07 11:00:11 +01:00
Philip Withnall
648986a290 glib: Avoid redefining GLIB_DISABLE_DEPRECATION_WARNINGS
It may be defined by the environment (we document that as being allowed)
— if so, individual files should not try to redefine it, as that causes
a preprocessor warning.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-27 15:41:09 +01:00
Edward Hervey
e21ab81ce0 gvalue: Do copy non-interned strings
The G_VALUE_NOCOPY_CONTENTS for strings can only be used when collecting them
and not when copying them.

Instead only avoid copies for strings that are interned.

Fixes #2141
2020-06-23 10:30:55 +00:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Sebastian Dröge
e992b9978e Merge branch 'value-interned' into 'master'
GValue: Add interned string support

Closes #2109

See merge request GNOME/glib!1497
2020-05-20 08:25:40 +00:00
Edward Hervey
1a95ce84ed GValue: Add interned string support
This adds support to be able to explicitely stored interned strings into
G_TYPE_STRING GValue.

This is useful for cases where the user:
* *knows* the string to be stored in the GValue is canonical
* Wants to know whther the string stored is canonical

This allows:
* zero-cost GValue copy (the content is guaranteed to be unique and exist
  throughout the process life)
* zero-cost string equality checks (if both string GValue are interned, you just
  need to check the pointers for equality or not, instead of doing a strcmp).

Fixes #2109
2020-05-19 17:52:55 +02:00