Commit Graph

498 Commits

Author SHA1 Message Date
Philip Withnall
39671c196d
girepository: Fix hole in GIFunctionInfoFlags
It’s unclear why there was a hole in this. Let’s keep things less
confusing by eliminating it.

Fixes commit 453dd4be9e.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-08-26 12:08:28 +01:00
Philip Withnall
0a60b57fd4
girepository: Fix API version ‘since’ numbers
Fixes commit 453dd4be9e.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-08-26 12:08:13 +01:00
Philip Withnall
10177cf3ea
girepository: Coding style fixes
Fixes commit 453dd4be9e.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-08-26 12:07:49 +01:00
Evan Welsh
453dd4be9e girepository: Add APIs for sync, async, and finish function annotations 2024-08-26 12:07:25 +01:00
Chun-wei Fan
297d808c6b introspection: Correct GIO-Windows pkg-config name
It's gio-windows-2.0.pc, not gio-win32-2.0.pc.

Otherwise, we get warnings/errors where the package cannot be located
but since we are linking to the same GIO library file, this did not
manifest itself.
2024-07-17 16:28:34 +08:00
Philip Withnall
98854efa74
introspection: Add libgirepository as a dep to all generate_gir() calls
libgirepository is not needed by most of the modules, but it is needed
by the `g-ir-scanner` generated dumper program. If we don’t explicitly
include the local version of it here, Meson will implicitly link against
it anyway, and that might pull in a different version, or try to link
against a half-built local version as the build ordering dependency tree
won’t reflect this relationship.

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

Fixes: #3401
2024-06-26 12:48:32 +01:00
Philip Withnall
74c6c4c221 Merge branch 'fix-introspection-windows' into 'main'
Introspection: Fix running g-ir-scanner 1.80.x+ on Windows

See merge request GNOME/glib!3988
2024-06-13 20:12:33 +00:00
Philip Withnall
c2e7b2f3b0
girepository: Fix type of precondition return values
This fixes a compiler warning (`-Wnon-literal-null-conversion`) on
clang 13 on macOS.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-04 17:27:28 +01:00
Simon McVittie
a0ed94a11d Provide private G_SIGNEDNESS_OF macro in glib-private.h
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-06-04 16:57:18 +01:00
Simon McVittie
7c41a6529b girparser: Use INTEGER_ALIAS to reduce repetition
As a special case, keep the historical behaviour of treating gchar
as being signed, both on platforms where it is genuinely signed (for
example x86 Linux) and where it is unsigned (for example ARM, s390x
and PowerPC Linux). Changing gchar to use INTEGER_ALIAS would have a
regression risk, so if we want to do that, it should be as a separate
change.

No functional change intended.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-06-04 16:57:18 +01:00
Philip Withnall
d02f5816bf Merge branch 'wip/pwithnall/gdump-tests' into 'main'
tests: Add basic tests for gdump.c in libgirepository

See merge request GNOME/glib!4102
2024-06-04 15:17:03 +00:00
Philip Withnall
5b26ef2e46
tests: Add basic tests for gdump.c in libgirepository
It’s currently completely untested. Let’s add a few basic tests so that
adding more tests in future is easier.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-04 15:52:05 +01:00
Andoni Morales Alastruey
c93c4d41e8 girepository: add default search paths tests for relocations 2024-06-04 13:00:45 +02:00
Andoni Morales Alastruey
9d0988ca62 girepository: fix find_by_type tests in macOS 2024-06-04 13:00:45 +02:00
Andoni Morales Alastruey
99382cfb4b girepository: fix autoptr tests build
In macOS compilation fails with the following error:
```
In file included from ../girepository/tests/autoptr.c:23:
../girepository/girffi.h:30:10: fatal error: 'ffi.h' file not found
```
2024-06-04 13:00:45 +02:00
Andoni Morales Alastruey
62fb5eb6d4 girepository: add support for relocations
Relocation is a common scenario in macOS applications and frameworks.
This commit provides a mechanism to support relocations by inferring
the typelib dir from the path of the loaded image libgirepository-1.0.dylib.
2024-06-04 13:00:42 +02:00
Emmanuele Bassi
d242bad64e Dump pointer types in the introspection blob
Instead of skipping types that inherit from G_TYPE_POINTER, add a new
ancillary element into the raw dump that gets processed by g-ir-scanner.

See: https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/470
2024-05-31 18:40:21 +01:00
Emmanuele Bassi
e7ef715883 build: Add docs.c to the GLib GIR
For historical reasons, some doc blocks are included in an ancillary
file. Add it to the list of sources parsed by g-ir-scanner, to increase
the coverage of various macros.

Fixes: #3372
2024-05-20 13:34:19 +01:00
Chun-wei Fan
ef73ce4f7f Introspection: Fix running g-ir-scanner 1.80.x+ on Windows
Since we are now building introspection files for GLib while building
GLib, so we want to make sure that we indeed load the freshly-built
DLLs when running g-ir-scanner, so we add the various needed subdirs
(and if needed, subprojects), to set the GI_EXTRA_BASE_DLL_DIRS
envvar so that g-ir-scanner will look for the newly-built GLib DLLs.

Ideally, upstream g-ir-scanner will need to be updated accordingly to do
something similar to what we are doing here, but this is needed until
the time that we require a g-ir-scanner that contains the update.

This will also fix the g-ir-scanner erroring out when there is no
pre-existing GLib on the system, as the needed DLLs are now found.

Related issue: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/499
Related MR in G-I:
https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/458
2024-05-17 18:37:32 +08:00
Philip Withnall
04a6ee3e9b Merge branch 'wip/3v1n0/gi-repository-leak-fixes' into 'main'
girepository/build: Actually use our compiler to generate GLib typelibs and fix parser leaks

See merge request GNOME/glib!4064
2024-05-16 23:15:16 +00:00
Marco Trevisan (Treviño)
b27fbf503b girepository/girparser,girmodule: Use a GPtrArray to hold the dependencies
It's just better than a list of strings for various reasons, but mostly
here it allows also to avoid copying the lists but making the
ownership clearer through references
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
2e2e606208 girparser: Simplify the ownership of context modules and parsed ones
There's no need to copy the list of modules and free it again, we can
just handle this by moving the modules to the parser promptly.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
23d3a5e859 girepository/girparser: Free the temporary context modules list when done
When we're about to return the found module we can just drop the list
of modules that we had previously copied in the temporary context
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
b59c3f73ee girepository/girparser: Free the parsed modules list elements
We were removing the modules themselves, but not the list items
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6e38293fec girepository/girparser: Move dependencies ownership to each module
In this way the module can survive without that the parser is fully
alive.

At the moment a module has not a ref-count system, but this makes things
clearer when we return the module from a parser.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
9d65076eba girepository/girparser: Cleanup the node stack if anything destroyed it
If we've leftover nodes in the stack we should cleanup it
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
997d32e9cd girepository/girparser: Free the struct or union node if was not tracked
In case the node was pushed to a non-empty node stack, then we were not
tracking it in the entries list, and so nothing was freeing it on
destruction.

As per this, once parsing is done, we can free it or we'd leak.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
98dce8a1c6 girepository/girparser: Do not allocate the same node name twice
We were setting the node name two times, and the latter was overwriting
the first one, making impossible to free the value when destroying the
node
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
a359333dd0 girepository/girnode: Fully free the members and discriminators lists
We were removing the contents but not the lists themselves
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
4cdf53a15c girepository/girmodule: Cleanup the temporary dependencies string
It's used during build phase, as a temporary variable but never freed
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6a4f8e5bb7 girepository/girmodule: Use clearer scope for the build struct
Allocate it only when needed avoiding manual memset
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
05f606f3c5 girepository/girmodule: Cleanup the build stack once we've done
The stack is allocated with a list that we need to free once done
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
6f69fd53df girepository/girnode: Simplify the ownership fo the serialized type string 2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
9f4b97bb92 girepository/girmodule: Cleanup the builder types hash keys
We were adding new keys but never removing them, so use the proper
destroy notify for them and clarify the ownership on the caller.
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
1b8ef05321 girepository/girmodule: Free the version, shared library and c prefix
Those strings are explicitly duplicated but never free'd
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
47cf6387ad girepository/compiler: Free the parser when not needed
The compiler code was full of leaks and nothing really checked on them.

While it's not a big deal per se, per the nature of it, it's still
better to ensure that memory management is well done so that there are
no problems when using it with sanitizers.

So, the source of the problems was not freeing the parser, but that
wasn't enough, more to come...
2024-05-16 22:51:12 +01:00
Marco Trevisan (Treviño)
311367620a girepository/build: Actually use our compiler to generate GLib typelibs
We are overriding the default g-ir-compiler for local usage, but this
is not actually happen since that's computed while parsing introspection

So generate the compiler as first thing, then in case handle the
introspection data
2024-05-16 22:51:12 +01:00
Philip Withnall
03248e7b18
girepository: Make gi_repository_get_loaded_namespaces() deterministic
As with the previous two commits, the results of calling
`gi_repository_get_loaded_namespaces()` were previously
non-deterministic due to being generated by iterating over a hash table,
which has a non-deterministic iteration order.

Fix that by using the new `ordered_typelibs` and `ordered_lazy_typelibs`
arrays to provide deterministic ordering.

At the same time, significantly reduce the number of allocations needed
to build the return value — previously the results would be built as a
linked list before being turned into an array. The linked list is now
banished to history.

Add some more unit tests to maximise test coverage of this method.

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

Fixes: #3303
2024-05-16 22:47:49 +01:00
Philip Withnall
0d199d6199
girepository: Make gi_repository_find_by_error_domain() deterministic
As with the previous commit, finding a `GIBaseInfo` matching the given
error domain was non-deterministic because it iterated through a hash
table of typelibs. Hash table iteration is non-deterministic.

Change the method to instead use the `ordered_typelibs` and
`ordered_lazy_typelibs` arrays to give deterministic iteration order.

Add a unit test, although it can’t test the interesting case of an error
domain which is present in both `GioUnix`/`GioWin32` and `Gio`, because
no such error domain exists.

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

Helps: #3303
2024-05-16 22:47:42 +01:00
Philip Withnall
81b16a88d1
girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 22:47:35 +01:00
Philip Withnall
14d196a6c1
gitypelib: Fix iterating through typelib prefixes
The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

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

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

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

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

Helps: #3303
2024-05-16 22:47:29 +01:00
Philip Withnall
e0533125d3
girepository: Fix a typo in a code comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-05-16 22:47:23 +01:00
Philip Withnall
1ed2cf63ed
girepository: Keep an ordered list of the loaded typelibs
There are various places where the set of typelibs is iterated over or
returned in an ordered way. In order to keep results deterministic and
reproducible, we need to keep this set ordered.

Keep a `GPtrArray` of the typelibs (one for fully-loaded ones and one
for lazy ones) alongside the existing hash tables. This will be used for
iteration in the next few commits.

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

Helps: #3303
2024-05-16 22:47:16 +01:00
Adam Sampson
ae33e87117 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:09:21 +01:00
Marco Trevisan (Treviño)
caf2f2fbda girepository/introspection: Set asan option only on address sanitizer
It's the only sanitizer failing when generating the introspection data
2024-05-10 04:16:17 +02:00
Marco Trevisan (Treviño)
0eb6c85606 build: Define glib_sanitizers variable to easily get the sanitizers in use
It's an array containing the list of sanitizers in use, normally it
contains a value, but in some cases may have more than one (e.g.
'address' and 'undefined').

And so use it to avoid repeated checks
2024-05-10 02:15:52 +02:00
Marco Trevisan (Treviño)
c78d0ad514 girepository/introspection: Properly check for sanitizer value
The sanitizer option is set to 'none' when not used
2024-05-09 17:51:10 +02:00
Marco Trevisan (Treviño)
3de5264f24 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:48:58 +02:00
Philip Withnall
f1d5a71bbc
girparser: Silence a scan-build NULL pointer dereference warning
It’s very obviously a false positive, as `str` has been added to on the
previous line, so can’t be `(void *) 0`. Not sure what scan-build is
thinking.

I’d rather not have this assertion (it doesn’t help the programmer’s
understanding of the code), but I would also rather have scan-build
running with no warnings so that it can helpfully catch newly-introduced
errors in future.

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

Helps: #1767
2024-04-25 23:57:59 +01:00
Philip Withnall
ec36370dcb
girepository: Fix various implicit conversions from size_t to smaller types
Basically various trivial instances of the following MSVC compiler
warning:
```
../gio/gio-tool-set.c(50): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-25 00:41:34 +01:00