Commit Graph

25366 Commits

Author SHA1 Message Date
Thomas Haller
ee247c0a2d array: add support for %NULL termination in GPtrArray
GArray supports a "zero_terminated" flag, but GPtrArray doesn't.
This is odd, because especially for a pointer array it makes sense
to have a %NULL sentinel. This would be for example useful to track
or construct a strv array with a GPtrArray.

As workaround for this missing feature you could use a GArray instead
(ugly) or to explicitly add the %NULL element. However the latter increases
the "len" of the array, which can be problematic if you want to still use
the GPtrArray for other purposes.

Add API for marking a GPtrArray as %NULL terminated. In that case, the
API will ensure that there is always a valid %NULL sentinel after the
array. Note that the API does not enforce that a %NULL terminated API
actually has any data allocated. That means, even with a %NULL terminated
array, pdata can still be %NULL (only if len is zero).

Add g_ptr_array_new_null_terminated() constructor. The null-terminated flag
cannot be cleared. Once the GPtrArray is flagged to be %NULL terminated, it
sticks. The purpose is that once a user checks whether a GPtrArray instance
is safe to be treated as a %NULL terminated array, the decision does
not need to be re-evaluated.

Also add a g_ptr_array_is_null_terminated(). That is useful because it
allows you to check whether a GPtrArray created by somebody else is safe
to use as a %NULL terminated array. Since there is no API to make an
array not %NULL terminated anymore, this is not error prone.

The new flag is tracked as a guint8 in GRealPtrArray. On common 64 bit
architectures this does not increase the size of the struct as it fits
in an existing hole. Note that this is not a bitfield because it's
probably more efficient to access the entire guint8. However, there is
still a 3 bytes hole (on common 32 and 64 architectures), so if we need
to add more flags in the future, we still have space for 24 bits,
despite the new flag not being a bitfield.

The biggest downside of the patch is the runtime overhead that most
operations now need to check whether %NULL termination is requested.

Includes some tweaks and additional tests by Philip Withnall.

https://gitlab.gnome.org/GNOME/glib/-/issues/353
2022-05-27 15:27:19 +01:00
Philip Withnall
a9321c3652 garray: Add missing (transfer full) introspection annotations
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 14:27:52 +01:00
Emmanuele Bassi
1c7966b58e Merge branch 'source-once-no-allocs' into 'main'
gmain: Refactor idle-once and timeout-once to avoid a closure allocation

See merge request GNOME/glib!2693
2022-05-27 12:51:15 +00:00
Philip Withnall
6db112f9a7 gmain: Refactor idle-once and timeout-once to avoid a closure allocation
Instead store a bit inside `GTimeoutSource` and `GIdleSource` to
indicate that they are one-shot sources, and that their callbacks have a
different type and should always be assumed to return `G_SOURCE_REMOVE`.

This should make one-shot idle and timeout sources a teeny weeny little
bit cheaper to set up.

From a suggestion here: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2684#note_1462917

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
c1477f79e7 gmain: Factor out common GIdleSource code
This allows it to be reused and extended (internally) a little more.
This commit introduces no functional changes, but allows for more easy
additions in a following commit.

It introduces `GIdleSource` as a simple wrapper around `GSource`, which
will be extended in a following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
af02a614a2 gmain: Factor out common GTimeoutSource code
This allows it to be reused and extended (internally) a little more.
This commit introduces no functional changes, but allows for more easy
additions in a following commit.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 13:28:33 +01:00
Philip Withnall
93bf87528d Merge branch 'ebassi/source-once' into 'main'
Add one-shot idle and timeout functions

See merge request GNOME/glib!2684
2022-05-27 12:25:51 +00:00
Philip Withnall
c1f94cd1a5 gmain: Minor documentation updates to idle-once and timeout-once funcs
As suggested on !2684.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-27 12:58:10 +01:00
Emmanuele Bassi
50c316ef36 Port various timeout/idle callbacks to the once API
So we excercise it in our test coverage.
2022-05-27 12:58:10 +01:00
Emmanuele Bassi
12571a0821 Add one-shot idle and timeout functions
Many idle and timeout sources are installed as "one shot": called once
and immediately removed. While it's easy to write a simple callback that
returns G_SOURCE_REMOVE, it would also be useful to have some sort of
"visual" marker when reading the code; a way to immediately see that a
callback (which may be defined elsewhere in the code) is meant to be
invoked just once.

Includes additional unit tests by Philip Withnall.
2022-05-27 12:57:55 +01:00
Philip Withnall
87646793e7 tests: Drop redundant collate test data files
These were made redundant in 5b08ef84e4
and cddce179f5,
when the test data was moved into the test program as strings.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-26 19:50:05 +01: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
Emmanuel Fleury
a8baa8d0d8 Convert tests/gobject/singleton.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
d0577293a2 Convert tests/gobject/signals.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
2767e1614d Convert tests/gobject/references.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
662d8458f5 Convert tests/gobject/override.c to glib test framework 2022-05-26 19:13:19 +01:00
Emmanuel Fleury
17ddf79e1d Convert tests/gobject/dynamictype.c to glib test framework 2022-05-26 19:13:16 +01:00
Emmanuel Fleury
b61d3edc33 Convert tests/gobject/defaultiface.c to glib test framework 2022-05-26 19:12:15 +01:00
Philip Withnall
d1cb96b5e3 Merge branch 'refcount_tests' into 'main'
Moving tests/refcount/ directory to gobject/tests/

See merge request GNOME/glib!2553
2022-05-26 18:03:00 +00:00
Emmanuel Fleury
d378108b10 Convert tests/gobject/accumulator.c to glib test framework 2022-05-26 18:51:57 +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
Emmanuel Fleury
b65260abe4 Convert tests/refcount/signals.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
d97c1a148e Convert tests/refcount/properties4.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
94ef5ae4c7 Convert tests/refcount/properties3.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
ddadb89d7c Convert tests/refcount/properties2.c to glib test framework 2022-05-26 18:37:35 +01:00
Emmanuel Fleury
76fccc78c0 Convert tests/refcount/properties.c to glib test framework 2022-05-26 18:37:34 +01:00
Emmanuel Fleury
715ff4ea29 Convert tests/refcount/objects2.c to glib test framework 2022-05-26 18:37:34 +01:00
Emmanuel Fleury
62b5fe5991 Convert tests/refcount/objects.c to glib test framework 2022-05-26 18:37:34 +01:00
Philip Withnall
ce585ba4d2 Merge branch 'slice-test' into 'main'
Slice test

See merge request GNOME/glib!2579
2022-05-26 17:01:52 +00:00
Philip Withnall
8625d8144b Merge branch 'module_tests' into 'main'
Move tests/module-test.c to gmodules/tests/

See merge request GNOME/glib!2660
2022-05-26 16:42:02 +00:00
Philip Withnall
0dca8bb6aa tests: Remove redundant meson commands
The `tests` array is now empty, so everything to do with it can be
removed from this file.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-26 17:27:03 +01:00
Emmanuel Fleury
c71d0c53b5 Move tests/module-test.c to gmodules/tests/
Helps issue #1434
2022-05-26 17:26:58 +01:00
Emmanuel Fleury
f62be5660d Convert tests/modules-test.c to glib test framework 2022-05-26 16:32:48 +01:00
Philip Withnall
a20a432100 Merge branch 'nacho/uwp-warnings' into 'main'
win32appinfo: change log level from warning to debug

Closes #2640

See merge request GNOME/glib!2661
2022-05-26 14:29:11 +00:00
Matthias Clasen
694e91c130 Merge branch 'gobject-speedups3' into 'main'
gobject: Keep a count of construct params

See merge request GNOME/glib!2690
2022-05-26 14:07:26 +00: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
4af76e2d9b Merge branch 'junit' into 'main'
gitlab-ci: left-over from junit cleanup

See merge request GNOME/glib!2687
2022-05-26 13:36:31 +00:00
Philip Withnall
eacb41f62e Merge branch 'meson-dependency-lookups' into 'main'
meson: use builtin dependency lookups for zlib/intl

See merge request GNOME/glib!2685
2022-05-26 12:57:20 +00:00
Philip Withnall
cdc5bf0227 Merge branch 'wip/chergert/fix-sysprof-wrapper' into 'main'
build: update sysprof configuration options

See merge request GNOME/glib!2689
2022-05-26 11:34:29 +00:00
Christian Hergert
114eb5bc5a build: update sysprof configuration options
Sysprof recently cleaned up it's build configuration options. This is
perhaps a good time to update GLib to point at an updated commit'ish and
use the new options.

If now is not a good time to do the update, that is completely fine, but
I wanted to give you a turn-key MR nonetheless.
2022-05-25 23:02:14 -07:00
Philip Withnall
44ba3a5f0e Merge branch 'param-spec-cleanup' into 'main'
gparamspecs: Remove redundant NULL checks

See merge request GNOME/glib!2688
2022-05-25 16:04:29 +00: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
Philip Withnall
321fe5d0a4 Merge branch 'param-speedups2' into 'main'
param: Add a value_is_valid vfunc

See merge request GNOME/glib!2677
2022-05-25 13:41:12 +00:00
Marc-André Lureau
a8058cb12c gitlab-ci: left-over from junit cleanup
This should have been part of GNOME/glib!2686 (sorry!)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-25 15:27:37 +02: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