Commit Graph

31 Commits

Author SHA1 Message Date
Philip Withnall
14d196a6c1
gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

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

Helps: #3303
2024-05-16 22:47:29 +01:00
Philip Withnall
f4f38c233f girepository: Move internal gi_typelib_blob_type_to_info_type() function
`GITypeInfo` isn’t defined in `libgirepository-internals`, and that was
forcing us to do some header includes which violated the layering
between `libigrepository-internals` and `libgirepository`. Fix that by
moving the helper function to the header/source where `GITypeInfo` is
defined.

This fixes commit 54f156bd63.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-14 11:52:33 +00:00
Philip Withnall
0fd99a9f16 gibaseinfo: Stop building GIBoxedInfo instances
Instead, add a method on `GIRegisteredTypeInfo` which indicates whether
the registered type is a boxed type. This will return true for
`GIStructInfo` and `GIUnionInfo` instances which are boxed (not all
structs and unions are).

This makes `GIBoxedInfo` redundant, and it’ll be dropped in a following
commit.

---

There are several different things which typelibs need to be able to
represent:
 1. Plain old datatype (POD) structs
 2. POD unions
 3. Structs with a copy func and/or free func
 4. Unions with a copy func and/or free func
 5. Structs which are the ‘GType struct’ for an object or interface (i.e.
    the class or instance or interface struct)
 6. Structs with a copy func and free func *and* boxed GType
 7. Unions with a copy func and free func *and* boxed GType
 8. Boxed GTypes which represent something other than a struct or union

So there’s a lot going on here. In commit
e28078c70cbf4a57c7dbd39626f43f9bd2674145, a lot of this was reworked,
and support was added for boxed unions and boxed ‘others’ (the last item
on the list above).

Since then, support for boxed types other than structs seems to have
atrophied a bit, and the whole lot has got a bit confusing.

It was perhaps less confusing when all the `GIBaseInfo` subclasses were
actually aliases of each other, but now they have subtype relationships,
the position of `GIBoxedInfo` in that type hierarchy has become unclear.
How is it related to `GIStructInfo`, `GIUnionInfo` and
`GIRegisteredTypeInfo`?

Since a boxed type is necessarily a `GIRegisteredTypeInfo`, and the
methods of `GIRegisteredTypeInfo` are all written to allow a `GType` to
be optional, so that `GIStructInfo` and `GIUnionInfo` can safely derive
from it and still be used to represent plain old datatypes without
`GType`s, it makes sense to add a method to `GIRegisteredTypeInfo` to
indicate that the registered type is derived from `G_TYPE_BOXED`.

Accordingly, the things above are now represented in libgirepository’s
type system as:
 1. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info
 2. `GIUnionInfo` instance similarly
 3. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info, `gi_struct_info_get_{copy,free}_function_name()` return
    non-`NULL` values
 4. `GIUnionInfo` instance similarly
 5. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info, `gi_struct_info_is_gtype_struct()` returns true
 6. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return valid
    `GType` information, `gi_registered_type_info_is_boxed()` returns
    true, `gi_struct_info_get_{copy,free}_function_name()` return
    `NULL` values (because the copy/free functions are hidden inside the
    boxed type registration at runtime)
 7. `GIUnionInfo` instance similarly
 8. Not representable, but could be represented in future by re-adding a
    `GIBoxedInfo` type which derives from `GIRegisteredTypeInfo` and is
    used solely for boxed ‘other’ types, *not* boxed structs or unions

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

Fixes: #3245
2024-02-12 13:16:07 +00:00
Philip Withnall
54f156bd63 gitypelib: Explicitly convert from GITypelibBlobType to GIInfoType
When creating `GIBaseInfo` instances from binary blobs, so far the code
has used an undocumented implicit conversion from one enum type to the
other. That’s a bit nasty, as it means the two enum types need to be
kept in sync (without that need being documented).

Introduce an explicit conversion function to make things more explicit.
Currently it does nothing, but in an upcoming commit it will be used to
deprecate a blob type.

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

Helps: #3245
2024-02-12 13:15:38 +00:00
Philip Withnall
6929632ecb gitypelib: Add boxed type
This is needed because `GITypelib` is exposed in the public
libgirepository API, so needs to be introspectable.

This should fix a couple of warnings about `gi_repository_require()` and
related APIs not being introspectable as they return an unintrospectable
type.

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

Helps: #3155
2024-02-07 21:07:18 +00:00
Philip Withnall
5cc5f413f5 gitypelib: Switch to refcounting
Since `GITypelib` is exposed in the public libgirepository API, it needs
to be a boxed type. So we either need to add a `copy` method to mirror
the existing `free` method, or switch to refcounting. The latter option
seems better, since a `GITypelib` contains internal state about open
`GModule`s and the semantics for copying that would be potentially
complex.

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

Helps: #3155
2024-02-07 21:07:18 +00:00
Philip Withnall
80f9153a7f girepository: Move search and library paths into GIRepository
Rather than them being set and stored globally, make them members of
`GIRepository`. This helps us move away from the concept of a global
singleton `GIRepository`.

This is slightly complicated by the fact that the library paths are
needed within the module loading code in `GITypelib`, but at that point
the `GITypelib` doesn’t have access to its parent `GIRepository` to call
`gi_repository_get_library_path()`, so we have to cache them in
`typelib->library_paths`.

It also means that it’s no longer possible to retrieve the ‘unset’ paths
from the globals, so the test for that is removed from
`repository-search-paths.c`.

This commit makes some API breaks, but that’s OK because libgirepository
has not been in a stable release yet.

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

Helps: #3155
2024-01-26 12:08:17 +00:00
Philip Withnall
5ef1c7e110 girepository: Move library path functions over from gitypelib.c
This means they’re implemented in the same file as the typelib search
path, so it’s easier to refactor the code.

This adds `gi_repository_get_library_path()` to expose the library path,
both publicly and to internal users in `gitypelib.c`. And unit tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-26 12:01:01 +00:00
Philip Withnall
1eec66c898 gitypelib: Replace multiple constructors with gi_typelib_new_from_bytes()
`GBytes` provides a way of handling const memory blobs, stolen memory
blobs, and mapped files. Rather than having `GITypelib` implement all of
those itself, just take a `GBytes` as input.

This is an API break, but libgirepository hasn’t been in a stable
release yet.

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

Helps: #3155
2024-01-26 09:51:13 +00:00
Marco Trevisan (Treviño)
223acf44ba gitypelib: Replace gi_typelib_check_format with compile-time static checks only
There's no much time to have checks at runtime when the compiler can
make sure that the structures size match the expected ones.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
bd29b0bf65 gtypelib: Use size_t for size-related arguments 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
6ef67b9a0d gtypelib: Use proper formatting for sizeof value
That returns a size_t, so we should use the z printf directive.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
25ae968fc2 girepository: Use expected signed types for iterating
We are using various indexes types, but not always using the correct
sign or size, so let's adapt this to ensure we're consistent with the
values we're comparing with.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
bc2e4b3de5 girrepository: Replace usage of gsize with standard size_t
We just do a safe s/gsize/size_t/ replacement here without doing any
changes to places in which different size of size_t and gsize may be
actually different and create troubles.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
c8aecbb834 girepository: Use uint8_t pointers instead of guchar 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
5c96b0231a girnode: Use unsigned type for unsigned values
Also use proper sized casting for blob values.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
9f33015a25 girrepository: Use standard int sized types instead of g[u]int* 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
8891429a5b girepository: Use char instead of glib-specific gchar 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
eda4bfcf95 girrepository: Use void* instead of gpointer 2024-01-16 18:40:37 +01:00
Marco Trevisan (Treviño)
91fc45ea57 girepository: Replace tabs with spaces in indentation
We don't use tabs anywhere and the mixed setup just makes many editors
to cry. So let's just replace the tabs with 8 spaces.
2024-01-16 17:30:37 +01:00
Philip Withnall
513e178144 gitypelib: Rename gi_typelib_check_sanity() to gi_typelib_check_format()
It’s more descriptive and less offensive.

This is not an API break as it’s not a public API.

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

Helps: #3155
2024-01-05 13:51:28 +00:00
Philip Withnall
5ccb2d7a06 gitypelib: Port documentation to gi-docgen and update
Review and update the documentation, making sure it’s complete,
formatted in gi-docgen format, and has all appropriate GIR annotations
and `Since:` lines.

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

Helps: #3155
2023-12-18 14:14:16 +00:00
Philip Withnall
fcb328a762 gitypelib: Add missing introspection annotations in GITypelib
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3155
2023-12-12 16:58:04 +00:00
Philip Withnall
2d2263fa4f girepository: Update docs for GITypelib for gi-docgen
Move the SECTION into the struct docs, update the documentation comment
syntax, and add `Since: 2.80` everywhere.

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

Helps: #3155
2023-12-12 16:58:04 +00:00
Philip Withnall
c42e63c637 girepository: Update existing Since tags to 2.80
Since the APIs are new to libgirepository-2.0 in version 2.80.

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

Helps: #3155
2023-12-12 16:58:04 +00:00
Philip Withnall
d00bbf94a6 girepository: Ignore set-but-not-used warnings with G_DISABLE_ASSERT
This fixes some compiler warnings when building with
`-Dglib_assert=false`.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/3294022

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-14 10:37:27 +00:00
Philip Withnall
2b544c3f66 girepository: Remove _ prefix from private functions
Now that libgirepository uses `GI_AVAILABLE_IN_*` macros, that’s what
controls symbol visibility. The `_` prefixes are redundant, and out of
keeping with the rest of GLib.

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

Helps: #3155
2023-11-08 15:23:31 +00:00
Philip Withnall
b32da06a7c girepository: Rename symbols to the GI namespace
Rather than a mix of structs being in `GI` and their methods being in
`g_`.

We’ve chosen not to use the `g_` namespace because a number of the
libgirepository class names are quite generic, so we’d end up with
confusing symbols like `GScopeType` and `GArgument`.

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

Helps: #3155
2023-11-08 15:05:20 +00:00
Philip Withnall
5f012e9f12 girepository: Add missing includes of corresponding headers
Make sure that each C file in `girepository/` includes its corresponding
header file (if such a file exists).

This ensures that the first declaration the compiler sees for each
function contains the symbol visibility macros. This fixes symbol export
(`dllexport`) on Windows platforms.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3155
2023-10-25 18:11:38 +01:00
Philip Withnall
844544f72c girepository: Add SPDX license header to all obvious files
Add the SPDX license runes to all the files which have an obvious
copyright header already. This is a mechanical edit.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3155
2023-10-25 17:10:10 +01:00
Emmanuele Bassi
03d6c16434 Move girepository 2023-10-15 17:56:05 +01:00