Commit Graph

29810 Commits

Author SHA1 Message Date
Simon McVittie
5e8f053d33 tests: Exercise gdbus-codegen --interface-info-header with empty input
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-06 13:55:35 +00:00
Simon McVittie
02a3417ac4 tests: Exercise gdbus-codegen --interface-info-body with empty input
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-06 13:55:33 +00:00
Philip Withnall
44e3ebccd1 tests: Add basic tests for GIUnionInfo
These would have caught the regression fixed in the previous commit.

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

Helps: #3155
2024-02-06 13:42:43 +00:00
Philip Withnall
c8946b8a92 gitypes: Fix integer values of GIInfoType
This effectively reverts commit 0910e2f6ad. I thought that `GIInfoType`
was decoupled from `GITypelibBlobType`, but it turns out that
`girepository.c` calls `gi_info_new_full()` with blob types, implicitly
converting them to info types.

This was causing anything with a type higher than the `INVALID_0` value
to be loaded as the wrong type.

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

Helps: #3155
2024-02-06 13:40:20 +00:00
Philip Withnall
e286497c1f giunioninfo: Mark get_discriminator_type() as nullable
It may (and should) return `NULL` if called on a union which isn’t
discriminated.

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

Helps: #3155
2024-02-06 13:35:23 +00:00
Philip Withnall
11e8075e51 giunioninfo: Split success and return value for get_discriminator_offset()
Otherwise there’s no obvious suitable return value to return when the
union is *not* discriminated.

This is an API break, but libgirepository has not been in a stable
release yet, so that’s fine.

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

Helps: #3155
2024-02-06 13:34:17 +00:00
Simon McVittie
1ba8386886 codegen: Document --output -
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-06 11:53:06 +00:00
Simon McVittie
6a1fdb8145 codegen: Use - instead of stdout for output to stdout
In command-line tools, ordinary filenames normally do not have
special-cased meanings, so commit 3ef742eb "Don't skip dbus-codegen tests
on Win32" was a command-line API break: in the unlikely event that a
user wanted to write to a file named exactly `stdout`, this would have
been an incompatible change.

There is a conventional pseudo-filename to represent standard output,
which is `-` (for example `cat -` is a no-op filter). Adding support
for this is technically also a command-line API break (in the very
unlikely event that a user wants to write to a file named exactly `-`,
they would now have to write it as `./-`), but filenames starting with
a dash often require special treatment anyway, so this probably will not
come as a surprise to anyone.

When the output filename is `-` we don't want to use `#ifdef _____` as
a header guard, so special-case it as `__STDOUT__` as before.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-06 11:53:06 +00:00
Philip Withnall
b06107579c gtestutils: Reformat docs for g_test_queue_destroy()
Fix a typo in them and improve the formatting while I’m there.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-06 11:05:13 +00:00
Philip Withnall
9dad94e7e5 gtestutils: Ensure test_data is freed even if a test is skipped
It’s reasonable for the `main()` function in a test suite to pass
ownership of some test data to `g_test_add_data_func_full()`, along with
a `GDestroyNotify`, and rely on GTest to free the data after all tests
have been run.

Unfortunately that only worked if the test was run, and not skipped
before its test function was called. This could happen if, for example,
it had `/subprocess` in its path.

Fix that by always freeing the test data. This required reworking how
tests are skipped, slightly, to bring all the logic for that within
`test_case_run()`, so that it could always handle the memory management.

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

Helps: #3248
2024-02-06 11:02:24 +00:00
Philip Withnall
5f6b1516ae tests: Rework how slow param test is skipped
It’s more helpful to always register the test, even if it’s normally
skipped, since then the skip is recorded in the test logs so people can
see what’s ‘missing’ from them.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-06 11:01:46 +00:00
Philip Chimento
614437107a tests: Add a test for finding methods and vfuncs in a GIObjectInfo
Helps: #3246
2024-02-05 18:40:58 +00:00
Philip Withnall
7acef299c2 girepository: Fix declaration of ‘find using interfaces’ methods
Fix the declaration and documentation of
`gi_object_info_find_method_using_interfaces()` and
`gi_object_info_find_vfunc_using_interfaces()`. The documentation was
wrong when I wrote it: the value returned is the object or interface
which declares the method or vfunc, not the one which implements it.

The returned declarer info may be a `GIObjectInfo` or a
`GIInterfaceInfo`. Since those two types have no subtype relation
between them, the return type has to be changed to `GIBaseInfo`. Using
`GIObjectInfo` would have been fine in girepository-1.0 because all
`*Info` types were aliases of each other — but since the move to
`GTypeInstance` this is no longer true.

A unit test will be in the following commit.

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

Fixes: #3246
2024-02-05 18:40:03 +00:00
Philip Withnall
25e68476fa Merge branch 'garray_maxuint' into 'main'
garray: improve boundary checks

Closes #3240

See merge request GNOME/glib!3882
2024-02-05 18:34:14 +00:00
Philip Withnall
702719dee9 build: Ensure the libgirepository docs are installed
Make the `meson.build` match the other docs `meson.build` files.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-05 18:03:52 +00:00
Philip Withnall
bad849347d docs: Add migration guide for libgirepository
This covers all the API changes from girepository-1.0 to
girepository-2.0 so far.

It was generated by manually looking through the changes in `git diff
af36393e6.. -- girepository/*.h`.

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

Helps: #3155
2024-02-05 18:03:52 +00:00
Philip Withnall
59a818c28b Merge branch '3243-get-type-info-type-type-type' into 'main'
girepository: Rename gi_arg_info_load_type() to gi_arg_info_load_type_info()

Closes #3243

See merge request GNOME/glib!3878
2024-02-05 17:46:24 +00:00
Tobias Stoeckmann
766bc75917 garray: Missing precondition checks
The function arguments index_ and length could lead to a sum which is
larger than G_MAXUINT, possibly leading to out of boundary accesses
in array_remove_range functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>

Fixes: #3240
2024-02-05 18:09:59 +01:00
Philip Withnall
f2814e36ef Merge branch 'th/gdataset-comment' into 'main'
[th/gdataset-comment] gdataset: add code comment to g_datalist_get_data()

See merge request GNOME/glib!3879
2024-02-05 16:52:00 +00:00
Thomas Haller
10d4351ec9 gdataset: add code comment to g_datalist_get_data()
It's not obvious why we wouldn't use g_quark_try_string(). Add a code
comment that this is intentional and a reference for how to find out
more.

Also, fix typo in another code comment.
2024-02-05 16:49:10 +01:00
Philip Withnall
c8132fdf78 girepository: Rename gi_arg_info_load_type() to gi_arg_info_load_type_info()
So that it matches `gi_arg_info_get_type_info()`. We can’t use
`gi_arg_info_get_type()` because that collides with the `GType` getter
for the type.

Spotted by Philip Chimento.

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

Fixes: #3243
2024-02-05 15:13:46 +00:00
Philip Withnall
bcc22d48b0 Merge branch 'th/datalist-shrink' into 'main'
[th/datalist-shrink] shrink the interal buffer of `GData`

See merge request GNOME/glib!3873
2024-02-05 15:10:33 +00:00
Thomas Haller
29314690c7 gdatalist: shrink the buffer when it becomes 75% empty
The amount of used memory should stay in relation to the number of
entries we have. If we delete most (75%) of the entries, let's also
reallocate the buffer down to 50% of its size.

datalist_append() now starts with 2 elements. This works together with
the shrinking. If we only have one entry left, we will shrink the buffer
back to size 2. In general, d->alloc is always a power of two (unless it
overflows after G_MAXUINT32/2, which we assume will never happen).

The previous buffer growth strategy of never shrinking is not
necessarily bad. It has the advantage to not require any checks for
shrinking, and it works well in cases where the amount of data actually
does not shrink (as we'd often expect).

Also, it's questionable what a realloc() to a smaller size really
brings. Is that really gonna help and will the allocator do something
useful?

Anyway. This patch introduces shrinking. The check for whether to shrink
changes from `if (d->len == 0)` to `if (d->len <= d->alloc / 4u)`, which
is probably cheap even if most of the time we don't need to shrink. For
most cases, that's the only change that this patch brings. However, once
we find out that 75% of the buffer are empty, calling realloc() seems a
sensible thing to do.
2024-02-05 13:34:31 +01:00
Philip Withnall
1757365af3 Merge branch 'dbus-codegen-tests' into 'main'
Don't skip dbus-codegen tests on Win32

Evolved from https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3857

See merge request GNOME/glib!3874
2024-02-05 10:18:28 +00:00
Philip Withnall
8109e91236 Merge branch 'moskalets/fix-gresource-leak' into 'main'
gresources: fix memory leak from libelf

Closes #3242

See merge request GNOME/glib!3875
2024-02-05 10:07:10 +00:00
Philip Withnall
7ff207b1cf Merge branch 'girepository-fixes' into 'main'
Various girepository fixes

See merge request GNOME/glib!3877
2024-02-05 10:01:20 +00:00
Artur S0
378997a8f9 Update Russian translation 2024-02-05 07:21:24 +00:00
Philip Chimento
3a01629955 girepository: Fix copy-paste error in type check macro
GI_IS_REGISTERED_TYPE_INFO() wasn't working because it was actually
defined to be the same as GI_IS_OBJECT_INFO().

Add some desultory type-checking assertions to the repository tests.
2024-02-04 10:16:31 -08:00
Philip Chimento
f19115213a girepository: Add type check to instance parameter
gi_repository_enumerate_versions() was missing a type check of the
instance parameter. This helps catch mistakes when porting from
girepository 1.x where the parameter was allowed to be null.
2024-02-04 09:14:51 -08:00
Maxim Moskalets
aa8ed92fba gresources: fix memory leak from libelf
Memory was leaking when allocating it inside libelf and losing the pointer to it (it was an automatic variable) when returning NULL from the get_elf function in some cases

Closes #3242

Signed-off-by: Maxim Moskalets <Maxim.Moskalets@kaspersky.com>
2024-02-03 15:23:15 +03:00
Thomas Haller
6c0d4c884f gdatalist: rework g_data_remove_internal() to use datalist_shrink()
The main point here is to reuse datalist_remove() and datalist_shrink().
Especially, datalist_shrink() will become more interesting next, when it
actually shrinks the buffer.

Also, I find the previous implementation with "data_end" confusing.
Instead, only use index "i_data" to iterate over the data.
2024-02-02 19:56:26 +01:00
Thomas Haller
927075277c gdatalist: extract helper function for removing element
Extract helper functions datalist_remove() and datalist_shrink(). This
is to reduce duplicate code, but also to have a default way how to do
this.

In particular, later datalist_shrink() might do more aggressive
shrinking. We need to have that code in one place.
2024-02-02 19:56:26 +01:00
Thomas Haller
dbae6b3484 gdatalist: rework g_datalist_clear() to return early
g_datalist_unlock() is probably faster than g_datalist_unlock_and_set().
Move the "if (data)" check (that we anyway had) earlier, so we can
call g_datalist_unlock() and return early.
2024-02-02 19:56:26 +01:00
Thomas Haller
759ebf3663 gdatalist: remove restriction of number of keys in g_datalist_id_remove_multiple()
If too many keys are requested, they temporary buffer is allocated
on the heap. There is no problem in principle, to remove more than
16 keys.

Well, the problem is that GData tracks entries in a linear list, so
performance will degrade when it grows too much. That is a problem,
and users should be careful to not add unreasonably many keys. But it's
not the task of g_datalist_id_remove_multiple() to decide what is
reasonable.

This limitation was present from the beginning, in commit 0415bf9412
('Add g_datalist_id_remove_multiple'). It's no longer necessary since
commit eada6be364 ('gdataset: cleanup g_data_remove_internal()').
2024-02-02 19:56:26 +01:00
Thomas Haller
48a1d8c695 dataset/tests: add test adding many queue data and remove them 2024-02-02 19:27:44 +01:00
Philip Withnall
3f4e6ddcd8 Merge branch 'thorough-tests-in-ci' into 'main'
build: Add thorough test setup

See merge request GNOME/glib!3838
2024-02-02 14:33:22 +00:00
Philip Withnall
35f42d0c8c Merge branch 'alatiera/python-test' into 'main'
gio: tests: Use slightly more explicit assert functions

See merge request GNOME/glib!3872
2024-02-02 14:29:26 +00:00
Jordan Petridis
9c65e9ba2d gio: tests: Use slightly more explicit assert functions
Found by using teyit [1] on the code

https://github.com/isidentical/teyit
2024-02-02 16:15:35 +02:00
Philip Withnall
b65657f068 Merge branch 'th/optimize-weak-ref-list' into 'main'
[th/optimize-weak-ref-list] rework GObject's `WeakRefData` to track references in an array instead of GSList

See merge request GNOME/glib!3869
2024-02-02 14:01:10 +00:00
Thomas Haller
d8e4f39aa8 gobject: track GWeakRef in object's WeakRefData with an array
GSList doesn't seem the best choice here. It's benefits are that it's
relatively convenient to use (albeit not very efficient) and that an
empty list requires only the pointer to the list's head.

But for non-empty list, we need to allocate GSList elements. We can do
better, by writing more code.

I think it's worth optimizing GObject, at the expense of a bit(?) more
complicated code. The complicated code is still entirely self-contained,
so unless you review WeakRefData usage, it doesn't need to bother you.
Note that this can be easily measure to be a bit faster. But I think the
more important part is to safe some allocations. Often objects are
long-lived, and the GWeakRef will be tracked for a long time. It is
interesting, to optimize the memory usage of that.

- if the list only contains one weak reference, it's interned/embedded in
  WeakRefData.list.one. Otherwise, an array is allocated and tracked
  at WeakRefData.list.many.

- when the buffer grows, we double the size. When the buffer shrinks,
  we reallocate to 50% when 75% are empty. When the buffer shrinks to
  length 1, we free it (so that "list.one" is always used with a length
  of 1).
  That means, at worst case we waste 75% of the allocated buffer,
  which is a choice in the hope that future weak references will be
  registered, and that this is a suitable strategy.

- on architectures like x86_68, does this not increase the size of
  WeakRefData.

Also, the number of weak-refs is now limited to 65535, and now an
assertion fails when you try to register more than that. But note that
the internal tracking just uses a linear search, so you really don't
want to register thousands of weak references on an object. If you do
that, the current implementation is not suitable anyway and you must
rethink your approach. Nor does it make sense to optimize the
implementation for such a use case. Instead, the implementation is
optimized for a few (one!) weak reference per object.
2024-02-02 14:49:09 +01:00
Thomas Haller
637c2a08ce gobject: combine ref_count/lock_field in WeakRefData
We can safely combine this, and use bit 30 of the ref-count for locking.

This leaves still 2^30-1 for the ref-count, which is more than enough,
because these references are only taken for a short time in
g_weak_ref_get() and g_weak_ref_set(). Note that one thread can at most
take one reference at a time, so the ref-count will always a smaller
number.

Also note, that obviously we will only take a bit lock while also
holding a reference. That means, when weak_ref_data_unref() decreases
the ref-count to zero, the bit will be unlocked as well.

The reason to do this is to free up some space in WeakRefData. Note that
(on x86_64) this doesn't actually make the struct smaller.  It's
probably not reasonably possible to make WeakRefData smaller than it
already is (on x86_64). However, by combining the fields we have some
space for reuse without increasing the struct size. That space will be
used next.
2024-02-02 14:49:09 +01:00
Thomas Haller
824c4da44b gobject/tests: add test that creates a large number of weak references
The implementation of GWeakRef tracks weak references in a way, that
requires linear search. That is probably best, for an expected low
number of entries (e.g. compared to the overhead of having a hash
table). However, it means, if you create thousands of weak references,
performance start to degrade.

Add a test that creates 64k weak references. Just to see how it goes.
2024-02-02 14:49:09 +01:00
Philip Withnall
1c6db4c8b4 Merge branch 'alatiera/docs-fix' into 'main'
docs: Fix include path for the build

See merge request GNOME/glib!3871
2024-02-02 11:52:51 +00:00
Jordan Petridis
e0b7ab81cf docs: Fix include path for the build
f75221c7ea moved the introspection
folder around, but we also need to adjust the relative path so
the documentation will keep building
2024-02-02 12:54:07 +02:00
Philip Withnall
53ded42fbb Merge branch 'revert-untested-codegen-changes' into 'main'
Revert "Don't skip dbus-codegen tests on Win32"

See merge request GNOME/glib!3870
2024-02-02 10:22:02 +00:00
Philip Withnall
5744f55c11 Revert "Don't skip dbus-codegen tests on Win32"
This reverts commit fbdc9a2d03.

It was not submitted through a merge request and broke CI. Reverting it
immediately to unbreak CI and hence the rest of the development
pipeline. The changes can be re-submitted as a merge request so they’re
properly tested in CI before being merged.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3857#note_1994336
2024-02-02 10:01:24 +00:00
John Ralls
fbdc9a2d03 Don't skip dbus-codegen tests on Win32
And coincidentally on Darwin either.
2024-02-01 15:17:26 -08:00
Philip Withnall
8afefe963d Merge branch '3238-hurd-configure-warnings' into 'main'
ci: Temporarily disable --fatal-meson-warnings on Hurd CI

Closes #3238

See merge request GNOME/glib!3863
2024-02-01 10:53:37 +00:00
Philip Withnall
c6ae56a9d6 Merge branch '3217-gir-stack' into 'main'
girepository: Expose GITypeInfo and GIArgInfo as stack allocatable

Closes #3217

See merge request GNOME/glib!3867
2024-02-01 10:52:13 +00:00
Philip Withnall
bcfb896fed Merge branch 'mcatanzaro/main-context-tutorial' into 'main'
Link to the main context tutorial from the main loop docs

See merge request GNOME/glib!3868
2024-02-01 10:51:30 +00:00