Commit Graph

224 Commits

Author SHA1 Message Date
Philip Withnall
d82675ffd3 gicallableinfo: Make abstract and add derived types
Previously (and incorrectly), `GICallableInfo`, `GIFunctionInfo`,
`GICallbackInfo`, `GISignalInfo` and `GIVFuncInfo` were all derived
directly from `GIBaseInfo`. `GICallableInfo` is supposed to represent
all of the other types, though, so that type hierarchy was incorrect. It
dated from when all the types were aliases of each other and the type
management was done entirely at runtime.

Fix that by making the other four types derive from `GICallableInfo`,
and marking `GICallableInfo` as abstract.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3216
2024-01-18 13:15:22 +00:00
Philip Withnall
4d5b6599fc gibaseinfo: Allow parent types to be specified for derived types
This doesn’t change the type hierarchy for now (i.e. it introduces no
functional changes), but it will allow us to add some intermediate types
into the `GIBaseInfo` hierarchy in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3216
2024-01-18 13:15:22 +00:00
Philip Withnall
71a19a6f65 gibaseinfo: Allow type flags to be specified for derived types
This doesn’t change any of the flags for now (i.e. it introduces no
functional changes), but it will allow us to make some of the types
abstract in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3216
2024-01-18 13:15:22 +00:00
Philip Withnall
8e3d98fc98 girepository: Add get_type() wrapper macros
This makes `GIBaseInfo` and derived types more consistent with GObject
convention, and thus a bit more comfortable to use.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3216
2024-01-18 13:15:22 +00:00
Philip Withnall
9377a0dd54 girepository: Split GIValueInfo out of gienuminfo.c
It’s a separate type, so it would be less confusing if it were in its
own file.

This doesn’t change any API.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-18 13:15:22 +00:00
Philip Withnall
515b3fc1dc giroffsets: Uniformly handle alignments as size_t
Do this by tracking the state of the size/alignment calculations
separately, rather than bunging it into the `alignment` field using
magic values.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-18 13:09:29 +00:00
Philip Withnall
9fcec66115 giarginfo: Return indexes as uints
As with previous commits, don’t use up half the return value space to
indicate an invalid index.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-17 10:36:45 +00:00
Philip Withnall
fe6f9a661b gitypeinfo: Change gi_type_info_get_array_length_index() to return uint
Rather than mixing `-1` and valid indexes, split out the indication of
whether the type is an array with a length argument from the actual
index of the length argument.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-16 23:26:02 +00:00
Philip Withnall
33f157bd6b gitypeinfo: Remove invalid return value from gi_type_info_get_array_type()
`-1` isn’t part of `GIArrayType`, so it’s not particularly type safe to
return it from `gi_type_info_get_array_type()`. Instead, make it an
error to call that function on a type which isn’t an array type.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-16 23:17:19 +00:00
Philip Withnall
6a7806da4d gitypeinfo: Change gi_type_info_get_array_fixed_size() to return size_t
Return information about whether the type is a fixed-size array
separately from the array size, which allows us to use the full `size_t`
for the array size.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
2024-01-16 23:13:01 +00:00
Philip Withnall
bb37da24a6 Merge branch 'gir-standard-types' into 'main'
girepository: Use standard types instead of glib specific

See merge request GNOME/glib!3780
2024-01-16 18:43:54 +00:00
Marco Trevisan (Treviño)
6cc655f86e girepository: Use single-bit sized elements for the GIIrNode structures
Leave to the compiler some more hints to optimize these structures for
being packed when possible.
2024-01-16 18:56:57 +01:00
Marco Trevisan (Treviño)
e9bdbfaf4b cmph-bdz-test: Use more size_t 2024-01-16 18:56:57 +01:00
Marco Trevisan (Treviño)
a201cbd719 girepository: Various indentation cleanups
Various random syntax cleanups found while refactoring
2024-01-16 18:56:57 +01:00
Marco Trevisan (Treviño)
b68857e707 giroffsets: Use size types for size and alignments
Note that for alignments we should actually use size_t, but this would
imply some refactors since this value can be acually set to -1 in our
implementation.

So we use gssize for now, that at least on gcc is defined.
2024-01-16 18:55:45 +01: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)
c8eeca9492 girnode: Use size_t to compute gir node size and ensure value is valid 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
a73cc6d5a2 girepository: Use size_t to keep track of the number of interfaces 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)
91a3399027 girmodule: Ensure we actually use unsigned for gi_ir_module_fatal line 2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
13791b47f6 gistructinfo: Use proper types for offset lookup
This is a private function so we can just use the expected types.

Also this avoids a signed/unsigned conversion.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
19476db825 girepository: Ensure indexed access on members is not overflowing
Even though we expose member access as size_t, a GI info blob can
typically just access to an a number of values that is never bigger
than uint16_t, as that's how the typelib is defined (cfr. typelib
internal header blob sizes and n_* elements).

So let's avoid this to happen by adding a check.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
acabaa1568 gibaseinfo: Ensure the typelib offset is within the allowed limits
Even though we expose the offset as a size_t value, we actually have
a less space for it, so let's ensure this is the case at runtime.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
157f93d2ee girepository: Use size_t for size-related arguments and return types
We used to use unsigned values, while they should be big enough to old
the data we're handling here, it's cleaner and clearer if we use size_t
as type for such values, as it makes straight forward to understand what
a value should contain. It also makes these values more future proof.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
de8ac339fb gitypeinfo: Use gssize to return the array length index
Use a bigger integer value, even though int is more than enough, but
to make it clearer that we're returning a size-related value.
2024-01-16 18:40:42 +01:00
Marco Trevisan (Treviño)
a3d29b6437 giarginfo: Use gssize to return the closure and destroy indexes
Use a bigger integer value, even though int is more than enough, but
to make it clearer that we're returning a size-related value.
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)
e3aac4281d girrepository: Remove unneeded static check
The check was added to ensure compatibility with previous versions but
this is not something we care anymore with this API/ABI break.
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)
e5353ef0c1 girnode: Assign negative value to signed integer 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)
44e4555765 girepository/cmph-bdz-test: Avoid using unused temporary variable 2024-01-16 17:30:49 +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
David King
bd56539f73 g-ir-compiler: Fix leaks in write_out_typelib
Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2024-01-15 22:44:41 -08:00
Christoph Reiter
98daf20188 Add a --version option to g-ir-compiler and g-ir-generate. Fixes #55 2024-01-15 22:44:41 -08:00
Ting-Wei Lan
496669495c 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-01-15 22:44:41 -08:00
Garrett Regier
380ec88f48 g-ir-compiler: Allow multiple --shared-library
https://bugzilla.gnome.org/show_bug.cgi?id=744535
Signed-off-by: Garrett Regier <garrett.regier@riftio.com>
2024-01-15 22:44:41 -08:00
Ben Boeckel
276bbf8f94 g-ir-compiler: message when arguments are wrong
Otherwise the error is "no input files" which is very confusing.

https://bugzilla.gnome.org/show_bug.cgi?id=753160

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2024-01-15 22:44:41 -08:00
Dieter Verfaillie
9c428a6a9e g-ir-compiler: remove references to --code, remove --no-init options
The "--code" option was removed years ago in d5b8d8d523c3bc26aa9fe6c364d3a17d325b55b6
so remove references to it from README and g-ir-compiler(1)

Remove the "--no-init" option from g-ir-compiler and g-ir-compiler(1)
as it was documented to "can only be used if --code is also specified",
so no reason to keep it around.
2024-01-15 22:44:41 -08:00
Colin Walters
3f1cd04b20 Drop calls to g_type_init()
And bump our GLib requirement.
2024-01-15 22:44:41 -08:00
Colin Walters
1820dcacf1 Add Emacs mode lines to C sources 2024-01-15 22:44:41 -08:00
Owen W. Taylor
5fa171ea21 Fix error handling when writing out typelib
Return a non-zero result when opening the output file fails and
don't use g_error() for other failures when writing out the file,
since such errors should not produce a core dump.
2024-01-15 22:44:41 -08:00
Colin Walters
70a1394652 girepository: Consistently prefix internal functions with _
This should better avoid them being exported.  Rename
girepository-parser.la to girepository-internals.la for clarity.
2024-01-15 22:44:41 -08:00
Johan Dahlin
35c46e2e2e [GIRepository] Rename GTypelib to GITypelib
Keep a typedef for backwards compatibility, until
the major bindings has moved over.
2024-01-15 22:44:41 -08:00
Colin Walters
45a04358b6 [gircompiler] Clean up parsing
We never actually include multiple modules in the compiler,
so just nuke that.  Also rather than passing around GIrModule
consistently pass around a GIrTypelibBuild structure which
has various things.

This lets us maintain a stack there which we can walk for
better error messages.

Also, fix up the node lookup in giroffsets.c; previously
it didn't really handle includes correctly.  We really need to
switch to always using Foo.Bar (i.e. GIName) names internally...
2024-01-15 22:44:41 -08:00