Commit Graph

494 Commits

Author SHA1 Message Date
Emmanuele Bassi
52cc4d7b52 Remove unused cmph files
The cmph utility tool is not built, and the licensing of wingetopt.[ch]
is dubious at best.
2024-04-12 15:26:22 +01:00
Ville Skyttä
b20647c2e2 docs: spelling and grammar fixes
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2024-04-01 11:01:06 +00: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
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
Christoph Reiter
c24a174437 Add a --version option to g-ir-compiler and g-ir-generate. Fixes #55 2024-02-08 13:53:59 +00:00
Christoph Reiter
4c150f199e build: enable -Wshadow 2024-02-08 13:53:59 +00:00
Christoph Reiter
d70551e624 g-ir-generate: fix missing error handling for command line parsing
The error arg was used but the result never checked.
2024-02-08 13:53:59 +00:00
Chun-wei Fan
ea917797bb g-ir-inspect: Ensure variables are at the top of block
We did not yet advertise C99 requirements for G-I yet, so let's not
assume this yet.
2024-02-08 13:53:59 +00:00
Ting-Wei Lan
55bca7b445 g-ir-{compiler,generate,inspect}: Call setlocale in main function
It is required to correctly show translated messages on some locales.

https://bugzilla.gnome.org/show_bug.cgi?id=760419
2024-02-08 13:53:59 +00:00
Igor Gnatenko
43d2206bcf g-ir-inspect: make description for --version a bit better
Reported-and-tested-by: Dominique Leuenberger <dimstar@opensuse.org>
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
Reviewed-by: Colin Walters <walters@verbum.org>
2024-02-08 13:53:59 +00:00
Igor Gnatenko
68162605ba g-ir-inspect: remove last usage of g_autoptr()
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>

https://bugzilla.gnome.org/show_bug.cgi?id=769600
2024-02-08 13:53:59 +00:00
Igor Gnatenko
77e08288a5 g-ir-inspect: Inspect GI typelibs
Various distributions (mainly RPM based so far) make use of automatic
dependencies extracted from typelib files (they can require other typelibs
and also shared libraries)

Current features
* Print used shared libraries
* Print used typelib dependencies

Based-on-patch-by: Dominique Leuenberger <dimstar@opensuse.org>
Reference: https://bugzilla.gnome.org/show_bug.cgi?id=665672
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Dominique Leuenberger <dimstar@opensuse.org>
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2024-02-08 13:53:59 +00:00
Colin Walters
42654f0979 Drop calls to g_type_init()
And bump our GLib requirement.
2024-02-08 13:53:59 +00:00
Colin Walters
4dc7b03bce Add Emacs mode lines to C sources 2024-02-08 13:53:59 +00:00
Johan Dahlin
dac19120aa [GIRepository] Rename GTypelib to GITypelib
Keep a typedef for backwards compatibility, until
the major bindings has moved over.
2024-02-08 13:53:59 +00:00
Colin Walters
a52046e847 Fix two compilation warnings 2024-02-08 13:53:59 +00:00
Colin Walters
4bf5ef6bd7 [girepository] Actually verify header of loaded typelibs in g_irepository_require
Take a GError * for typelib loading code, validate the header.  This
fixes bizarre errors from gjs where g_irepository_require would happily
load old typelibs.
2024-02-08 13:53:59 +00:00
Johan Dahlin
a01e97f46f [girwriter] Refactor out of generate.c
Move out the girwriter out of generate.c. Still a private API,
but that will probably change in the future.
2024-02-08 13:53:59 +00:00
Johan Dahlin
af10e6bd6e [generate] Get rid of globals
Get rid of all globals in gir generator, in preparation for
moving all code into libgirepository
2024-02-08 13:53:59 +00:00
Johan Dahlin
ccdceb1e09 [gtypelib.ch] Rename to gitypelib.ch
Rename gtypelib.h -> gitypelib-internal.h and rename
gtypelib.c to gitypelib.c
2024-02-08 13:53:59 +00:00
Johan Dahlin
a9a3352d8a [g-ir-generate] Write out array type
For GLib arrays, write out the array type to the tgir
2024-02-08 13:53:59 +00:00
Colin Walters
ecd9c2f3e7 Support (out caller-allocates)
People have wanted support for marking (out) on functions of the
form:

/**
 * clutter_color_from_pixel:
 * @pixel: A pixel
 * @color: (out): Color to initialize with value of @pixel
 */
void
clutter_color_from_pixel (guint32 pixel, ClutterColor *color);

Where the caller is supposed to have allocated the argument; the
C function just initializes it.  This patch adds support for this
argument passing style to introspection.  In this case, we see the
(out), and notice that there's only a single indirection (*) on
the argument, and assume that this means (out caller-allocates).

https://bugzilla.gnome.org/show_bug.cgi?id=604749
2024-02-08 13:53:59 +00:00
Johan Dahlin
320dd66c62 Add support for foreign structs
Foreign structs are special in the sense that there might
be native bindings (for instance PyCairo for PyGI) that provides
the same functionallity as the introspected variant.

https://bugzilla.gnome.org/show_bug.cgi?id=610357
2024-02-08 13:53:59 +00:00
Johan Dahlin
567a6d2195 Remove trailing whitespace 2024-02-08 13:53:59 +00:00
Tomeu Vizoso
90c166144c Implement callbacks as part of struct fields. Fixes #557383
gir: embed <callback> inside <field>
typelib: if a field contains a callback, store it just after the FieldBlob
girepository API: no additions
2024-02-08 13:53:59 +00:00
Andreas Rottmann
7a6056cbeb Bug 576605 - Get rid of GI_SCOPE_TYPE_OBJECT
Remove support for (scope object) as it lacks a real use case.
2024-02-08 13:53:59 +00:00
Colin Walters
f979d003ce Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype
Parse the c:prefix from the .gir, include it in the header.  Armed with this
information, we can now optimize lookups of GTypes because we
have the requirement that GTypes must start with the c:prefix.  We do
fall back though if a lookup fails.
2024-02-08 13:53:59 +00:00
Colin Walters
02bb4f8d6a Bug 557383 - Virtual method support
Broadly speaking, this change adds the concept of <vfunc> to the .gir.
The typelib already had most of the infrastructure for virtual functions,
though there is one API addition.

The scanner assumes that any class callback slot that doesn't match
a signal name is a virtual.  In the .gir, we write out *both* the <method>
wrapper and a <vfunc>.  If we can determine an association between
them (based on the names matching, or a new Virtual: annotation),
then we notate that in the .gir.

The typelib gains an association from the vfunc to the function, if
it exists.  This will be useful for bindings since they already know
how to consume FunctionInfo.
2024-02-08 13:53:59 +00:00
Colin Walters
43c682703c Bug 571548 - Generic attributes
We now support an extensible mechanism where arbitrary key-value
pairs may be associated with almost all items, including objects,
methods, and properties.

These attributes appear in both the .gir and the .typelib.
2024-02-08 13:53:59 +00:00
Andreas Rottmann
ae73e2e4e6 Add --all option to g-ir-generate
Add --all option, which is intended to show some information not
usually included in the GIR.

Currently, it shows the size of structs and unions.

Signed-off-by: Andreas Rottmann <a.rottmann@gmx.at>
2024-02-08 13:53:59 +00:00
Colin Walters
cd2dcdf1f4 Bug 572434 - Associate interfaces with their C structures
Similar to GObject class structs, we pair up GInterfaces with
their C structures.

Also, move some GLib-specific things into glibast.py, and make
the naming more generic.
2024-02-08 13:53:59 +00:00
Colin Walters
d90d14cf67 Bug 551738 - Associate classes with their structs
Inside glibtransformer, we now look at structures ending in "Class" and
see if they have an associated GlibObject (i.e. a structure of the same
name without the "Class" suffix).  If found, pair them up.

The .gir file for <class> gains an attribute denoting its associated
class struct.  Any <record> many now have a glib:is-class-struct-for
annotation which tells which (if any) <class> for which it defines the
layout.

In the .typelib, we record the association between the class and
its structure.  Generic structures however just have a boolean
saying whether they're a class struct.  (Going from a generic class
struct to its class should not be necessary).

Finally, we expose GIRepository APIs to access both bits of information
from the .typelib.

svn path=/trunk/; revision=1088
2024-02-08 13:53:59 +00:00
Andreas Rottmann
981e55ef57 Bug 556489 – callback annotations
2008-01-03  Andreas Rottmann  <a.rottmann@gmx.at>

	Bug 556489 – callback annotations
	
	* giscanner/transformer.py 

	* tools/generate.c (write_callable_info): Write out the new scope,
	closure and destroy attributes.

	* giscanner/transformer.py (Transformer._type_is_callback): New
	method, checking if a given type is a callback.
	(Transformer._augment_callback_params): New method; adds
	information (closure, destroy) to callback parameters.
	(Transformer._handle_closure, Transformer._handle_destroy): New methods, 
	auxiliary to _augment_callback_params.
	(Transformer._create_function): Call _augment_callback_params().
	(Transformer._create_parameter): Handle scope option.

	(Transformer._create_typedef_callback): New method, creates a
	callback, and registers it in the typedef namespace
	(Transformer._create_typedef): Use _create_typedef_callback()
	instead of the plain _create_callback().

	* giscanner/ast.py (Parameter): Added callback-related fields.
	* giscanner/girwriter.py: Write out new Parameter fields.

	* girepository/girnode.h (GIrNodeParam): Added fields scope, 
	closure and destroy.
	* girepository/gtypelib.h (ArgBlob): Ditto.
	* girepository/girparser.c (start_parameter): Handle new fields.

	* girepository/girmodule.c (g_ir_module_build_typelib): Adjust
	arg_blob_size, bump major version due to this change.
	* girepository/girnode.c (g_ir_node_get_full_size_internal)
	(g_ir_node_build_typelib)
	* girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
	adjustments.
	(g_ir_node_build_typelib): Fill in new ArgBlob flags from param. 

	* girepository/girepository.h (GIScope): New enumeration, listing
	the different possible scopes for callbacks.

	* girepository/ginfo.c (g_arg_info_get_scope)
	(g_arg_info_get_closure, g_arg_info_get_destroy): Accessors for
	callback-related argument indices (callback scope, closure for a
	callback, destroy notification for a callback).

	* tests/scanner/: Added testcases for new features.

svn path=/trunk/; revision=998
2024-02-08 13:53:59 +00:00
Colin Walters
fcdfe8dbd9 Also generate new syntax
svn path=/trunk/; revision=933
2024-02-08 13:53:59 +00:00
Owen Taylor
1892f7dcfd Remove field offsets from g-ir-generate output and test inputs
Field offsets are a) architecture dependent so they shouldn't be part
of the architecture-independent gir format which is installed in
datadir. b) Are architecture-dependent so they shouldn't be in test
expected output. Remove field offsets from girs.
(Virtual function and discriminator offsets are not removed, as they
aren't fully hooked up to the field-offset computation machinery yet.)

svn path=/trunk/; revision=877
2024-02-08 13:53:59 +00:00
Colin Walters
2d1e6e2c5c Bug 557786 - support fixed size arrays
svn path=/trunk/; revision=814
2024-02-08 13:53:59 +00:00
Tommi Komulainen
d9ab34b17c Bug 556739 – transfer-ownership attribute should be mandatory in .gir
2008-10-23  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* girepository/girparser.c (parse_param_transfer):
	* giscanner/transformer.py (_create_parameter, _create_return):
	* giscanner/girwriter.py (_write_return, _write_parameter):
	* tools/generate.c (write_callable_info): always write and
	require "transfer-ownership" for return-values and parameters

	* tests/boxed.gir:
	* tests/invoke/testfns-1.0.gir:
	* tests/object.gir:
	* tests/scanner/DrawableAdditions.xml:
	* tests/scanner/GtkFrob-1.0-expected.tgir:
	* tests/scanner/annotation-1.0-expected.tgir:
	* tests/scanner/drawable-1.0-expected.tgir:
	* tests/scanner/drawable-injected-1.0-expected.gir:
	* tests/scanner/drawable-injected-1.0-expected.tgir:
	* tests/scanner/foo-1.0-expected.tgir: Updated

svn path=/trunk/; revision=797
2024-02-08 13:53:59 +00:00
Tommi Komulainen
e4542c021c Bug 557379 – g-ir-generate not writing the 'abstract' attribute
2008-10-22  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* tests/scanner/drawable-1.0-expected.tgir:
	* tests/scanner/drawable-injected-1.0-expected.tgir:
	* tests/scanner/foo-1.0-expected.tgir:
	* tools/generate.c (write_object_info): write 'abstract'
	attribute for classes

svn path=/trunk/; revision=785
2024-02-08 13:53:59 +00:00
Tommi Komulainen
659a300f87 Bug 557405 – Use 'allow-none' consistently
2008-10-22  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* docs/typelib-format.txt:
	* girepository/ginfo.c (g_arg_info_may_be_null):
	* girepository/girnode.c (g_ir_node_build_typelib):
	* girepository/girnode.h (struct _GIrNodeParam):
	* girepository/girparser.c (start_parameter):
	* girepository/girwriter.c (function_generate):
	* girepository/gtypelib.h (ArgBlob):
	* tests/errors.gir:
	* tests/function.gir:
	* tools/generate.c (write_callable_info): Use 'allow-none'
	consistently throughout

svn path=/trunk/; revision=782
2024-02-08 13:53:59 +00:00
Colin Walters
cb720c675e Write out throws attribute
svn path=/trunk/; revision=776
2024-02-08 13:53:59 +00:00
Tommi Komulainen
d3e2ead0db Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* girepository/girparser.c (start_parameter):
	* tests/boxed.gir:
	* tests/invoke/testfns-1.0.gir:
	* tools/generate.c (write_callable_info): write
	'transfer-ownership' attribute consistently with both
	return-value and parameter elements

svn path=/trunk/; revision=745
2024-02-08 13:53:59 +00:00
Tommi Komulainen
66a5209b6c Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* tools/generate.c (write_callable_info): write 'direction'
	attribute only if other than 'in' to be consistent with
	girwriter.py
	* tests/boxed.gir:
	* tests/object.gir: remove direction="in" which is the default

svn path=/trunk/; revision=744
2024-02-08 13:53:59 +00:00
Tommi Komulainen
3bddeae0fa Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* giscanner/ast.py (Field): add readable and writable properties
	* giscanner/girparser.py (_parse_field): copy 'readable' and
	'writable' attributes
	* giscanner/transformer.py (_create_member): create fields as
	read-write
	* giscanner/glibtransformer.py (_introspect_object,
	_pair_class_struct): make object instance and class fields
	read-only
	* giscanner/girwriter.py (_write_field):
	* tools/generate.c (write_field_info): write field 'readable'
	and 'writable' attributes only if non-default (read-only)
	* girepository/girparser.c (start_field): in the absence of
	attributes assume fields are read-only
	* tests/boxed.gir:
	* tests/struct.gir: remove redundant readable="1" from fields
	* tests/scanner/foo-1.0-expected.gir:
	* tests/scanner/utility-1.0-expected.gir: add writable="1" to
	all record and union fields

svn path=/trunk/; revision=743
2024-02-08 13:53:59 +00:00
Tommi Komulainen
80429426af Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* giscanner/girwriter.py (_write_property): write properties
	'construct' attribute if set
	* tools/generate.c (write_property_info): write properties
	'readable' and 'writable' attributes only if non-default
	* tests/object.gir: add writable="0"
	* tests/scanner/foo-1.0-expected.gir: add construct="1"

svn path=/trunk/; revision=742
2024-02-08 13:53:59 +00:00
Tommi Komulainen
477412eeca Bug 556543 – reduce compiler warnings
2008-10-16  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556543 – reduce compiler warnings

	* girepository/ginfo.c:
	* girepository/girepository.c (register_internal,
	count_interfaces, find_interface, find_namespace_version,
	parse_version, g_irepository_require):
	* girepository/girmodule.c (g_ir_module_build_typelib):
	* girepository/girnode.c (init_stats, dump_stats,
	_g_irnode_init_stats, _g_irnode_dump_stats,
	g_ir_node_can_have_member):
	* girepository/girparser.c (firstpass_end_element_handler,
	locate_gir, parse_basic, parse_type_internal, resolve_aliases,
	start_alias, start_type, end_type_top, parse_include, cleanup,
	post_filter):
	* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
	* giscanner/giscannermodule.c (directive_get_options,
	type_get_child_list):
	* giscanner/scannerlexer.l (parse_gtkdoc):
	* giscanner/scannerparser.y (ctype_free):
	* giscanner/sourcescanner.c:
	* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
	* tests/types/gitesttypes.c:
	* tools/compiler.c (main):
	* tools/generate.c (write_repository): Remove unused variables
	and code, add missing includes, declarations and case
	statements.

svn path=/trunk/; revision=730
2024-02-08 13:53:59 +00:00
Colin Walters
c874b58562 Fix up g-ir-generate for new include= syntax
svn path=/trunk/; revision=726
2024-02-08 13:53:59 +00:00
Tommi Komulainen
deba627f8f reduce code duplication
2008-10-15  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* tools/generate.c (write_type_name, write_type_info,
	write_type_info, write_object_info, write_object_info,
	write_interface_info, write_error_domain_info): reduce code
	duplication

svn path=/trunk/; revision=718
2024-02-08 13:53:59 +00:00
Tommi Komulainen
65a653d3a9 Bug 556174 – parse types for lists etc.
2008-10-15  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556174 – parse types for lists etc.

	* girepository/girparser.c (end_type_recurse):
	* tests/boxed.gir:
	* tools/generate.c (write_type_info, write_field_info,
	write_callable_info, write_callable_info, write_constant_info,
	write_property_info): use nested <type>s for lists and hashes

svn path=/trunk/; revision=717
2024-02-08 13:53:59 +00:00