Commit Graph

449 Commits

Author SHA1 Message Date
Philip Withnall
2c379a35ba Merge branch 'backport-4065-girepository-bitfield-glib-2-80' into 'glib-2-80'
Backport !4065 “girepository: Don't assume a bitfield has a fixed size” to glib-2-80

See merge request GNOME/glib!4074
2024-05-16 21:38:28 +00:00
Marco Trevisan (Treviño)
5fc08f60b5
girepository/introspection: Properly check for sanitizer value
The sanitizer option is set to 'none' when not used
2024-05-15 12:59:48 +01:00
Adam Sampson
62b11360da
girepository: Don't assume a bitfield has a fixed size
The type used when declaring a bitfield member of a struct doesn't
affect the amount of space allocated for it - only whether it's signed
or unsigned. In standard C99 (6.2.7.1), only _Bool, signed int and
unsigned int or typedefs to them are allowed as bitfield types, but GCC
allows other integer types as an extension.

In this case, the GIBaseInfo and GIBaseInfoStack structs are meant to
have identical layout. However, type_is_embedded was declared as an
unsigned bitfield in the former and a uint32_t in the latter. This was
harmless on most platforms because the following member is an aligned
pointer, but (for example) on m68k-linux-gnu pointers only need to be
16-bit aligned, so GCC only allocates 16 bits for the bitfield.

Change the type in the declaration to unsigned int, and add an padding
bitfield following it to ensure there's space for 32 bits on all
platforms in the future.

Signed-off-by: Adam Sampson <ats@offog.org>
2024-05-15 12:57:44 +01:00
Marco Trevisan (Treviño)
b48b7b2a84
girrepository/tests: Add full gir dependencies on tests
Tests may have runtime dependencies that are related to the typelib
dependencies, so we need to satify them or the tests will fail at
runtime if we're not building their prerequisite for other reasons.

That's saying that the tests are currently failing when explicitly
running as standalone in meson.

Co-Authored-By: Philip Withnall <philip@tecnocode.co.uk>
2024-05-09 15:36:54 +01:00
Philip Withnall
39f0e6d435
girffi: Fix ffi_cif leaks on error return paths
Spotted by scan-build.

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

Helps: #1767
2024-04-26 10:32:53 +01:00
Philip Withnall
4141eea257
girffi: Add hints to indicate ownership transfer into ffi_cif
scan-build thinks that the `atypes` array is leaked, but it’s not.
Ownership is transferred into the `ffi_cif` structure, and it’s
eventually freed in `gi_callable_info_destroy_closure()`.

Try and help the static analysis by adding an explicit ownership
transfer annotation. It probably won’t help.

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

Helps: #1767
2024-04-26 10:32:47 +01:00
Emmanuele Bassi
66363efb73 Remove unused cmph files
The cmph utility tool is not built, and the licensing of wingetopt.[ch]
is dubious at best.
2024-04-12 10:04:31 -05:00
Simon McVittie
d9ee53d0eb girparser: Add a pseudo-doc-comment for signedness()
We could consider adding this to gmacros if it's useful anywhere else.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-18 10:48:31 +00:00
Simon McVittie
c7e0f3e6b8 girparser: Adjust signedness() to avoid compiler warnings
No functional change intended.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-18 10:45:28 +00:00
Philip Withnall
8c9b9bca35 Merge branch 'wip/smcv/inline-sizeof' into 'main'
girparser: Make sizes in integer_aliases more obviously correct

See merge request GNOME/glib!3970
2024-03-18 10:34:01 +00:00
Simon McVittie
31b9c2f589 girparser: Make sizes in integer_aliases more obviously correct
We don't actually need to use the Meson-detected size macros here,
because the result of `sizeof()` is an integer constant expression.

No functional change.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-17 12:34:09 +00:00
Simon McVittie
fa45ea2ac9 girparser: Allow time_t, off_t, etc. to appear in GIR XML
g-ir-scanner currently maps these to lower-level types at scan time by
assuming that time_t is an alias for long, off_t is an alias for size_t
and so on. This is not always accurate: some ILP32 architectures have
64-bit time_t (for Y2038 compatibility) and 64-bit off_t (for large file
support), and that mismatch is tracked as GNOME/gobject-introspection#494.

One option for resolving this g-ir-scanner bug is to have it pass these
types through to the GIR XML, and teach g-ir-compiler and its replacement
gi-compile-repository to convert them to the corresponding concrete
type tag, as they already do for abstract types such as `long long` and
`size_t`.

Loosely based on GNOME/gobject-introspection!451 by Shuyu Liu.

Co-authored-by: Shuyu Liu <liushuyu011@gmail.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-16 10:25:30 +00:00
Simon McVittie
d2a6c379e8 girparser: Don't assume sizeof(size_t) == sizeof(void *)
We don't actually need to use the results of configure-time checks here:
sizeof is a perfectly reasonable integer constant expression, so we can
use that directly.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-16 10:24:58 +00:00
Simon McVittie
1a8e2228f6 girepository: Provide placeholders for positional parameters
Otherwise, correct invocation isn't clear from the --help output.

This does not introduce new translated strings: FILE was already
translated.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-28 11:27:15 +00:00
Simon McVittie
9541b43eef girepository: Provide placeholders for --includedir
If we don't do this, the --help text is formatted as though the option
did not expect an argument.

This does not introduce new translated strings: DIRECTORY was already
translated.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-28 11:26:59 +00:00
Philip Withnall
bd17a09862 girepository: Combine input file validation code paths in utilities
The code and strings are the same, so let’s simplify things and reduce
LoC for no functional change.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-26 18:10:56 +00:00
Philip Withnall
08b3f14a32 compiler: Correctly use g_strerror() instead of strerror()
This ensures the return value is always UTF-8.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-26 18:10:56 +00:00
Philip Withnall
57a8834d7b girepository: Add translation support to utility tools
This fixes a few formatting and newline issues in the strings at the
same time, but nothing major.

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

Fixes: #3263
2024-02-26 18:10:56 +00:00
Kleis Auke Wolthuizen
72d76922dc girepository: Fix static build under Windows
Properly define `GI_STATIC_COMPILATION` when static build is enabled.
Use `library()` instead of `shared_library()` to allow selecting static builds.
2024-02-21 12:38:40 +01:00
Philip Withnall
90b2185c56 Merge branch 'wip/smcv/decompiler-order' into 'main'
gi-decompile-typelib: Interpret --includedir as most-important-first

See merge request GNOME/glib!3928
2024-02-15 19:02:24 +00:00
Philip Withnall
a9fabe5fc0 Merge branch 'wip/smcv/decompiler' into 'main'
girwriter: Take the GIRepository as a parameter

See merge request GNOME/glib!3925
2024-02-15 12:26:45 +00:00
Philip Withnall
fe2c18a835 Merge branch 'wip/smcv/gi-unused-options' into 'main'
gi- tools: Remove unused options, improve --debug/--verbose

See merge request GNOME/glib!3926
2024-02-15 11:11:56 +00:00
Philip Withnall
f1d4d547a8 Merge branch '3255-clear-base-info' into 'main'
gibaseinfo: Allow gi_base_info_clear() to be idempotent

Closes #3255

See merge request GNOME/glib!3929
2024-02-15 01:19:44 +00:00
Simon McVittie
64762fdef6 gi-decompile-typelib: Interpret --includedir as most-important-first
This is a behaviour change from g-ir-generate, which treats it as
least-important-first (the last directory on the command-line is
searched first).

gi-compile-repository --includedir and gcc -I are most-important-first
(the first directory on the command-line is searched first) so it seems
like it makes most sense to be consistent with that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 12:00:05 +00:00
Philip Withnall
06a7258a8c girepository: Add g_autoptr() and g_auto() support
This should make the code a bit more usable in situations where people
aren’t potentially using MSVC.

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

Helps: #3255
2024-02-14 11:54:48 +00:00
Philip Withnall
39afe18221 girepository: Add GI_REPOSITORY_LOAD_FLAG_NONE
This just makes code using the load flags a little more readable.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-14 11:54:21 +00: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
75820a6941 gibaseinfo: Remove an unused private macro
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-14 11:52:02 +00:00
Philip Withnall
ec9a73a262 gibaseinfo: Allow gi_base_info_clear() to be idempotent
When called on an already-cleared `GIBaseInfo` it should do nothing.

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

Fixes: #3255
2024-02-14 11:51:08 +00:00
Simon McVittie
f80e978f00 girwriter: Take the GIRepository as a parameter
We certainly won't find the requested namespace in a newly-created
repository with no typelibs loaded.

Fixes: 9ab84bc1 "girwriter: Stop using the singleton GIRepository"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 11:13:04 +00:00
Simon McVittie
e6d2c2c040 g-ir-compiler: Only accept one input file
The positional parameters are declared as G_OPTION_ARG_FILENAME_ARRAY,
but only the first one is used.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 11:11:14 +00:00
Simon McVittie
4180a2069c gi-decompile-repository: Remove unused --shlib option
This seems to have been a remnant of support for embedding the typelib
in the shared library, which was removed from this tool in commit 4bf5ef6b
"[girepository] Actually verify header of loaded typelibs in
g_irepository_require" (originally gobject-introspection@05ffd857).

The feature of embedding the typelib in a shared library was itself
removed in commit b2df59c3 "compiler: Remove --code argument",
originally gobject-introspection@ac81f3e8, with a note that because
we rely on being able to load the shared library into g-ir-scanner,
anything that links g-ir-scanner output into the shared library would be
a circular dependency.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 10:42:39 +00:00
Simon McVittie
d40e1b9db3 gi-compile-repository: Make file-scoped variables static
This means the compiler will warn us if they become unused.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 10:36:34 +00:00
Simon McVittie
3f6de0706e girparser: Don't rely on gi-compile-repository exporting debug level
It seems cleaner to store this in the parser, rather than having the
compiler export a global variable that the parser must read.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 10:36:34 +00:00
Simon McVittie
a41496643b gi-compile-repository: Remove unused variable
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 10:21:44 +00:00
Simon McVittie
d3325bf879 gi-compile-repository: Remove unused --module option
This hasn't actually done anything since commit 45a04358
"[gircompiler] Clean up parsing" (originally
gobject-introspection@8942500c).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-14 10:20:08 +00:00
Simon McVittie
2b2b6de70b girepository test: Don't assume doubles are naturally-aligned
On i386 Linux, the minimal ABI alignment of a double is only 4, and
therefore the alignment of GDoubleIEEE754 is also 4.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-13 11:33:54 +00:00
Philip Withnall
19308d6c18 introspection: Re-add platform specific APIs to GLib-2.0.gir and Gio-2.0.gir
To avoid a big introspection API break.

These APIs are now listed in the new `{GLib,Gio}{Unix,Win32}-2.0.gir`
files, but for backwards compatibility they need to continue to be
listed in `Gio-2.0.gir` and `GLib-2.0.gir` as well, until the next major
introspection API break (and none is planned).

No new platform specific APIs should be added to these GIR files, but
these existing ones must remain.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3892#note_2001361

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-12 17:54:36 +00:00
Philip Withnall
4314944e56 introspection: Drop Unix and Win32 prefixes from platform specific APIs
So now introspection users will have to call `GLibUnix.open_pipe()`
rather than `GLibUnix.unix_open_pipe()` — or
`GLibWin32.check_windows_version()` rather than
`GLibWin32.win32_check_windows_version()`.

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

Helps: #3037
2024-02-12 17:54:36 +00:00
Philip Withnall
2b4bfadfb7 tests: Remove an unnecessary include from test-common.h
It causes a build failure on mingw32, as `_WIN32_WINNT` is redefined.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-12 17:54:36 +00:00
Philip Withnall
5021d002ab introspection: Generate separate GIR files for platform specific APIs
For both GLib and GIO. (GObject, GIRepository and GModule don’t have any
platform specific APIs.)

This is needed for two reasons:
 * If the same GIR file is shipped on multiple platforms, it has no way
   to conditionally define/not-define an API based on the platform (like
   an `#ifdef` in a C header). So we either end up shipping differing
   GIR APIs on different platforms, or shipping a GIR file which
   declares APIs which aren’t resolvable by `dlopen()` on certain
   platforms, and will cause a language runtime error.
 * The API reference documentation is now generated from the GIR, and
   similar problems are present there: if the GIR contains different
   symbols depending on the platform, there is no way to generate API
   documentation for the union of all of them.

The fix is to ensure that there are no conditional symbols in a GIR, by
splitting out the platform specific symbols into platform specific GIR
files. Platform specific documentation can then be generated from these,
in addition to the main, platform agnostic, documentation.

The documentation changes will following in a subsequent commit.

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

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
0d9170c6b8 gio: Remove unnecessary appinfo_sources variable
There was no obvious logical need to list the `GAppInfo` subclass
sources separately in the build. It makes more sense to add them to the
platform-specific source lists, since they are platform specific.

This will be used in an upcoming commit which generates
platform-specific GIR files, so needs the full platform-specific lists
of sources.

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

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
3a7dfb14c6 Merge branch '3245-boxed-info-typing' into 'main'
gibaseinfo: Stop building GIBoxedInfo instances and use gi_registered_type_info_is_boxed() instead

Closes #3245

See merge request GNOME/glib!3905
2024-02-12 14:11:36 +00:00
Marco Trevisan
730a348574 Merge branch '3244-typelib-path' into 'main'
girepository: Export builddir typelib and GIR paths

Closes #3244

See merge request GNOME/glib!3880
2024-02-12 13:45:00 +00:00
Philip Withnall
5ddd4b91b8 girepository: Drop unneeded include from girepository-private.h
It was causing a build failure on some platforms:
```
In file included from ../girepository/gthash.c:29:
In file included from ../girepository/gitypelib-internal.h:30:
../girepository/girepository-private.h:26:10: fatal error: 'ffi.h' file not found
 #include <ffi.h>
          ^~~~~~~
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-12 13:30:17 +00:00
Philip Withnall
f51398af91 girepository: Drop GIBoxedInfo
See the previous commit for details.

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

Helps: #3245
2024-02-12 13:17:04 +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
dbc38b28aa Merge branch 'wip/smcv/cmph-typo' into 'main'
cmph: Fix a typo

See merge request GNOME/glib!3913
2024-02-12 12:25:53 +00:00
Philip Withnall
2ee2397622 Merge branch '3155-update-generate-and-inspect' into 'main'
Rename g-ir-generate and g-ir-inspect and update to girepository-2.0

See merge request GNOME/glib!3909
2024-02-09 23:31:21 +00:00