Commit Graph

438 Commits

Author SHA1 Message Date
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
Philip Withnall
d03727c07d girwriter: Stop using gi_base_info_get_info_type()
While it’s an internal API which `girwriter.c` has access to, it’s not
available inside `libgirepository-internals.so`. This wasn’t spotted
before commit 343027d5d landed because none of the existing users of
`libgirepository-internals.so` use the relevant code in `girwriter.c`,
so it got compiled out (`libgirepository-internals.so` is statically
linked and can be optimised like this).

Now that `gi-decompile-repository` uses the relevant code from
`girwriter.c`, the problem is obvious and `gi-decompile-repository`
fails to link.

Fix that by no longer using `gi_base_info_get_info_type()` in
`girwriter.c`. These are changes which would have eventually been made
anyway in issue #3253.

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

Helps: #3253
2024-02-09 20:41:44 +00:00
Philip Withnall
8248382d8b gi-inspect-repository: Change --version argument to --typelib-version
`--version` is conventionally used to find the version of the program
itself. While that’s not currently implemented in
`gi-inspect-repository`, let’s not box ourselves into a corner.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-09 20:41:17 +00:00
Philip Withnall
268871426a gi-inspect-repository: Port to girepository-2.0
Update the code to the latest standards and to use girepository-2.0
after it’s been imported to this repository.

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

Helps: #3155
2024-02-09 20:40:47 +00:00
Philip Withnall
aaed30f3dc gi-decompile-repository: Port to girepository-2.0
Update the code to the latest standards and to use girepository-2.0
after it’s been imported to this repository.

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

Helps: #3155
2024-02-09 20:40:47 +00:00
Philip Withnall
5c3c2cf6b3 girepository: Rename g-ir-generate and g-ir-inspect
Rename them to `gi-decompile-repository` and `gi-inspect-repository` to
match the existing `gi-compile-repository`. The names have to differ
from those used in girepository-1.0 to avoid collisions.

‘generate’ has been changed to ‘decompile’ because it does the inverse
of what `gi-compile-repository` does: it converts a typelib to a GIR
file. ‘generate’ never really made much sense for this anyway — it’s
almost a synonym of ‘compile’.

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

Helps: #3155
2024-02-09 20:40:17 +00:00
Philip Withnall
a59499ab0a Merge branch 'no-override-g-ir-compiler' into 'main'
build: Only override g-ir-compiler when GIR generation is enabled

See merge request GNOME/glib!3876
2024-02-09 20:18:39 +00:00
Evan Welsh
e36839818a build: Only override g-ir-compiler when GIR generation is enabled
GLib is used a subproject with GObject Introspection and overriding
this binary breaks that usage. For now we will make overriding the
binary conditional until Meson is updated to handle the binary changes.
2024-02-09 06:56:38 -08:00
Simon McVittie
8a8ce72a7a cmph: Fix a typo
In the project from which this copy of cmph was forked, this was fixed
in version 2.0.2 by commit
bbf77c63c9/

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 14:44:34 +00:00
Philip Withnall
59d454a20d Merge branch '3155-quickly-drop-info-type' into 'main'
girepository: Make GIInfoType private

Closes #3155

See merge request GNOME/glib!3906
2024-02-08 22:45:17 +00:00
Philip Withnall
57c02e4c07 girepository: Export builddir typelib and GIR paths
These can then be used by a parent project if GLib is used as a Meson
subproject.

In particular, GJS wants to use `GLib-2.0.typelib`
from GLib-as-a-subproject, but doesn’t want to hardcode the path to it
inside the GLib builddir.

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

Fixes: #3244
2024-02-08 15:17:18 +00:00
Philip Withnall
931931d8f1 girepository: Add SPDX lines to newly imported tools
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-08 14:01:57 +00:00