552 Commits

Author SHA1 Message Date
Philip Withnall
5bc310bf9e girepository: Add an assertion to help scan-build
This helps scan-build not emit a ‘potential null pointer dereference’
error for calls to `require_internal()`:
```
Access to field 'message' results in a dereference of a null pointer (loaded from variable 'local_error')
```

See https://gitlab.gnome.org/GNOME/glib/-/jobs/5482526 for details of
the error.

I don’t think there is an actual null pointer dereference here.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-09-02 16:02:26 +01:00
Emmanuele Bassi
45640dffa5 girepository: Load platform-specific GIO data
For backward compatibility, we automatically load the GioUnix or
GioWin32 namespaces if the Gio namespace has been required.

Also ensures that the platform-specific library is loaded in tests

Co-Authored-By: Marco Trevisan (Treviño) <mail@3v1n0.net>
2025-08-29 14:32:08 +02:00
Marco Trevisan (Treviño)
10366ac62f girepository: Add checks on prerequisites of gi_repository_require 2025-08-29 14:29:58 +02:00
Marco Trevisan (Treviño)
fd262e72f5 girepository: Fix indentation 2025-08-29 14:29:58 +02:00
Marco Trevisan (Treviño)
a1bc53aa98 girepository: Add test ensuring that platform specific methods are available 2025-08-29 14:29:33 +02:00
Emmanuele Bassi
db96cb45ce Remove backward compatibility introspection from Gio-2.0
The identifiers and types in Gio-2.0 that are used for backward
compatibility purposes in order to keep code importing Gio and using
platform-specific API are actually breaking the platform-specific
introspection data, because the introspection scanner favours types
found inside dependencies as opposed to types with the same name found
inside the current namespace.

In practice, the backward compatibility hack of keeping duplicate types
inside Gio-2.0 is effectively preventing people from using GioUnix-2.0
and GioWin32-2.0.

We cannot change the introspection scanner, because that could have
unforeseen results across the stack.

We cannot remove the symbols and bump the namespace version of Gio and
friends to 3.0, unless we keep generating known-to-be-broken 2.0
versions of all the namespaces. It also won't solve the issue of code
loading Gio without specifying a version, because that always imples
using the latest version of the namespace, which means backward
compatibility would still need an explicit opt in.

In practice, the only reasonable way forward is to break backward
compatibility, and remove the duplicate symbols and identifiers from
Gio-2.0, as we should have done in the first place.

Fixes: #3744
2025-08-29 14:02:44 +02:00
Marco Trevisan (Treviño)
8f25f70fc9 girepository: Always use internal functions in internal implementations
We are going to have a different logic in the public function so let's
just use the same code internally
2025-08-29 14:02:44 +02:00
Philip Withnall
2db24eeef0 Merge branch 'fopen-cloexec' into 'main'
gstdio: Add support for the `e` flag (O_CLOEXEC) to g_fopen()

See merge request GNOME/glib!4564
2025-05-29 10:59:56 +00:00
Philip Withnall
b2f0bb9592 tests: Expand PATH for Python tests on Windows
This works around a Meson bug
(https://github.com/mesonbuild/meson/issues/4668).

If we have a Python test which spawns a built native binary, that binary is
listed in the `depends` argument of the `test()`. On Linux, this results in
the directories containing the built libraries which the binary depends on
being added to the `LD_LIBRARY_PATH` of the test invocation. On Windows,
however, Meson currently doesn’t add those directories to `PATH` (which is
the equivalent of `LD_LIBRARY_PATH`), so we have to do it manually.

This takes the same approach as Christoph Reiter did in
gobject-introspection
(13e8c7ff80/tests/meson.build (L2)).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-05-28 16:10:55 +01:00
Philip Withnall
f9a7ac11f5 gstdio: Add support for the e flag (O_CLOEXEC) to g_fopen()
This adds cross-platform support for it: on glibc, musl and BSD’s libc,
the flag is natively supported. On Windows, convert it to the `N` flag,
which similarly indicates that an open file shouldn’t be inherited by
child processes.

This allows us to unconditionally pass `e` to `g_fopen()` so `O_CLOEXEC`
can easily be set on its FDs.

Also do the same for `g_freopen()`, since it shares the same underlying
mode handling code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-05-28 14:37:02 +01:00
Christian Hergert
690ba3b7b5 girepository: add singleton GIRepository back
This is needed to avoid situations where you cannot coordinate between
bindings and libraries which also need to interact with introspection
which could affect bindings.

For example, a Python application using libpeas to load plugins, also in
Python.

Fixes: #3664
2025-05-23 13:52:37 -07:00
Philip Withnall
d496e97b75 gitypes: Add ‘none’ members for flags enums
This is a little clearer than using `0` as a precondition failure
return value.

Suggested by John Ralls in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4606#note_2420640.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-30 13:18:55 +01:00
Philip Withnall
d1e28aed1a girepository: Fix -Wsign-conversion warnings in macOS library code
The members of `struct segment_command` appear to have type `uint32_t`,
so definitely need casting to the machine’s integer pointer type before
doing pointer arithmetic on them.

See https://developer.apple.com/documentation/kernel/segment_command

Tested only on macOS CI as I don’t have access to a macOS machine.

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

Helps: #3405
2025-04-30 13:18:49 +01:00
Philip Withnall
c76b9bc72e girepository: Fix various precondition failure return values to typecheck
This fixes various `-Wsign-conversion` warnings in `giarginfo.c` and
related files.

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

Helps: #3405
2025-04-30 13:18:45 +01:00
Philip Withnall
cdca951d06 gdump: Fix some GError -Wsign-conversion warnings
Because of the generic nature of `GError`, `g_set_error()` has to take
an `int`, but `g_file_error_from_errno()` returns a `GFileError`. The
macOS CI runner decides that’s a good reason to emit
`-Wsign-conversion`.

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

Helps: #3405
2025-04-30 13:18:38 +01:00
Philip Withnall
e662421d3a girnode: Make an internal struct member’s type more specific
This struct is only ever heap allocated, and enums are always the same
size as an int (or unsigned int), so it won’t change size.
The struct doesn’t correspond to any mmapped structure from a
typelib file.

This should fix some `-Wsign-conversion` warnings (curiously only seen
on the macOS CI runner) by using the most specific type.

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

Helps: #3405
2025-04-30 13:18:31 +01:00
Philip Withnall
a25e15695b Merge branch 'wsign-conversion3' into 'main'
Enable -Wsign-conversion for girepository, gthread, gmodule

See merge request GNOME/glib!4594
2025-04-22 21:47:03 +00:00
Dan Yeaw
5f12b1b400 Windows: fix wrong typelib path 2025-04-12 15:45:51 +00:00
Philip Withnall
21d8e246e7 girepository: More minor -Wsign-conversion fixes from CI
These didn’t occur on my local machine, interestingly.

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

Helps: #3405
2025-04-12 16:24:32 +01:00
Philip Withnall
3de99090d0 girepository: Enable -Wsign-conversion for girepository subdirectory
As with previous commits, we’re enabling `-Wsign-conversion` piecemeal
for all of glib.git.

The previous few commits have fixed all the `-Wsign-conversion` warnings
in libgirepository, so let’s enable the warning by default for that
directory to prevent regressions.

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

Helps: #3405
2025-04-11 23:56:49 +01:00
Philip Withnall
7c06269eef girparser: Limit the size of GIR files which can be parsed
Due to passing around file lengths variously as `gsize` or `gssize`,
we can’t reliably handle files with length greater than `G_MAXSSIZE`, as
some of the APIs in use need `-1` to indicate that their input is nul
terminated.

Add some checks for this, and gracefully return an error if an input
file is too big, rather than just exploding.

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

Helps: #3405
2025-04-11 23:56:44 +01:00
Philip Withnall
4a29abe9f7 girparser: Stop setting blob length to -1 when no length is set
When parsing a GIR or building a typelib, stop setting the array length
field to `-1` as a default. That field is unsigned, so setting it to
`-1` is actually equivalent to setting it to `G_MAXUINT`. I can’t find
anywhere which treats `G_MAXUINT` or `-1` as a magic value there, so
it’s probably better off left unset.

Given the lack of documentation for the typelib code, though, there is a
fair chance I’m making a mistake and this is actually an integral part
of the format. Let’s see what breaks.

This fixes a `-Wsign-conversion` warning, at least.

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

Helps: #3405
2025-04-11 23:56:39 +01:00
Philip Withnall
debb6a9cc0 tests: Add a basic test for GIIrParser type parsing
This follows up from the previous two commits to add a unit test.

It doesn’t attempt to cover the multitude of other possible type parsing
conditions; at the moment it’s just a regression test for the previous
two commits, and somewhere to hang new tests on in future.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 23:56:35 +01:00
Philip Withnall
cff7783a32 girparser: Fix error handling for type parsing
Reworking the code to add proper `GError` handling for type parsing,
rather than the existing `g_critical()`, turned out to actually be
fairly straightforward.

So now `gi_ir_parser_parse_string()` returns
`G_MARKUP_ERROR_INVALID_CONTENT` on unparseable types, just like it does
with various other bits of invalid GIR.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-11 23:56:30 +01:00
Philip Withnall
e6d34fa5a8 girparser: Fix a potential buffer overflow with g_strndup()
If parsing a generic type which has no closing `>`, there was no check
that the `strchr()` call succeeded, which could have resulted in a
negative length being passed to `g_strndup()`, which would result in a
long positive length after implicit type casting.

Fix that by bringing an old error handling path back into use. This
results in a `g_critical()` in the calling function, which is good
enough for now. Potentially all this code could be reworked to use
`GError`, but that’s a much bigger project (a lot more of the
`girparser.c` code would need to change).

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

Helps: #3405
2025-04-11 23:56:26 +01:00
Philip Withnall
8ab78a66a4 girepository: Fix -Wsign-conversion warnings with string arithmetic
There are a few `g_strndup()` calls which use a length calculated from
the return value of `strchr()` minus the original string. That’s fine,
as long as `strchr()` doesn’t return `NULL`. Add some asserts to ensure
that.

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

Helps: #3405
2025-04-11 23:56:21 +01:00
Philip Withnall
f44511bc54 girepository: Fix straightforward -Wsign-conversion warnings
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2025-04-11 23:56:17 +01:00
Philip Withnall
d854836aff girparser: Fix a strict-aliasing warning with g_clear_pointer()
Casting the type for a `g_clear_pointer()` call breaks strict aliasing
rules.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-03 15:38:45 +01:00
Philip Withnall
7ea714e658 Merge branch 'wip/3v1n0/sanitizer-memory-fixes' into 'main'
Memory sanitizer fixes

See merge request GNOME/glib!4484
2025-04-03 13:04:05 +00:00
Marco Trevisan (Treviño)
0a47b69b46 girepository/parser: Clarify ownership of nodetype nodes
We may had free'd a list of items without freeing the items in there.
So now, properly steal the data instead and free everything.
2025-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
98de5367d3 girepository/compiler: Cleanup the parser error on failure 2025-04-03 13:57:18 +02:00
Marco Trevisan (Treviño)
cc070e1a7d girepository/compiler: Cleanup the parser on write failures 2025-04-03 13:57:18 +02:00
Philip Withnall
416bab52eb tests: Fix a memory leak if a callable-info test is skipped
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-04-03 13:57:18 +02:00
Philip Withnall
aee0664e6f girparser: Ignore new doc:format element in GIR files
As of gobject-introspection 1.83.2, a new `<doc:format name="…"/>`
element is supported (as a child of `<repository>`) in GIR files.

For the moment, this information isn’t needed in libgirepository — but
the GIR parser does have to know about the element in order to not throw
an error claiming it’s invalid.

This is a slightly tweaked version of the code added to
gobject-introspection.git in commit
9544cd6c962fab2c3203898779948309833e2439 by Corentin Noël
<corentin.noel@collabora.com>, reformatted slightly to fit in with
GLib’s style guidelines.

This is backwards compatible and does not require a new
gobject-introspection version.

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

Fixes: #3634
2025-03-10 15:21:15 +00:00
Simon McVittie
2c358ec7f8 build: Factor out a variable for the GIR XML directory suffix
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 20:12:48 +00:00
Simon McVittie
9f18bb6258 tests: Search the appropriate directories for our GIR XML inputs
During "as-installed" testing, we should search the GIR_DIR for GIR XML,
instead of hard-coding that it is `${prefix}/share/gir-1.0`. This is
not the case on at least Debian, in order to make it possible to
install more than one architecture's flavour of `GLib-2.0.gir`,
which contains some architecture-specific `#define`s.

Also search GOBJECT_INTROSPECTION_DATADIR/GIR_SUFFIX (in practice
something like `/usr/share/gir-1.0` in all cases) to accommodate
distributions like Debian that move the architecture-independent
majority of GIR XML into /usr/share to avoid duplication, leaving
only the architecture-specific minority of files like `GLib-2.0.gir`
in the GIR_DIR.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 16:40:47 +00:00
Simon McVittie
135850a534 tests: Reformat gi-compile-repository.py according to black(1)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 16:05:43 +00:00
Marco Trevisan (Treviño)
044e77a384 girepository/tests: Add tests for basic inspector operations
Add some initial tests for the inspector
2025-02-12 17:37:25 +01:00
Marco Trevisan (Treviño)
6160747fe5 girepository/tests: Add tests for the compiler basic operations
Adding some initial test for the compiler behavior and its expected
output.

Also, when using sanitizers we want to be able to test the compiler memory
management.
2025-02-11 21:02:56 +01:00
Marco Trevisan (Treviño)
bf9ea337a2 girepository/tests: Add tests on compiler open/write failures 2025-02-11 21:02:56 +01:00
Philip Withnall
a127f9b7d2 tests: Fix a memory leak if a callable-info test is skipped
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-02-11 11:40:29 +00:00
Philip Chimento
7471ab20d1 girepository: Add test for static vfunc info
This is a test for the functionality in the previous commit. It depends
on g-ir-scanner being able to scan static vfuncs, and is otherwise
skipped.

The g-ir-scanner functionality is in
https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/361
2025-01-19 13:49:55 -08:00
Marco Trevisan (Treviño)
7ea9840cf4 girepository: Read static vfunc attribute exposing via callable is_method()
Read the static attribute for virtual functions, and make sure that
g_callable_info_is_method() returns false for such cases.
2025-01-19 13:49:55 -08:00
Philip Chimento
fe142e3b32 girepository: Add baseline tests for gi_callable_info_is_method()
This tests existing functionality.
2025-01-18 14:27:24 -08:00
Philip Chimento
3d71dcaa64 gicallableinfo: Fix inaccuracy in is_method docs
The docs say that gi_callable_info_is_method() on a GICallbackInfo
always returns TRUE. But the source code says it always returns FALSE.
2025-01-18 14:16:55 -08:00
Simon McVittie
feca93e51e girepository: Correct --c-include arguments for GIO Unix/Windows headers
The deprecated construct '@0@'.format(h) (where h is a file object)
expanded to the filename relative to the project root, which in this
particular case happens to be what we wanted:
`--c-include=gio/gunixmounts.h` resulted in a recommendation to
`#include <gio/gunixmounts.h>` and so on. Replacing it with
h.full_path() resulted in GIR XML and documentation that recommended
constructs like `#include </home/me/src/glib/gio/gunixmounts.h>`,
which is not what was intended (and caused new differences between
different architectures' Gio-2.0.gir on multiarch systems, which is
how I discovered this).

Hard-coding `gio/` and appending the basename of the header seems like
the simplest non-deprecated spelling that will do what we wanted.

Fixes: 51e3e7d9 "build: Bump Meson dependency to 1.4.0"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3564
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-13 23:34:10 +00:00
Evan Welsh
bb0dd59a6b girepository: Expose gi-compile-repository in pkg-config
Expose the binary path to gi-compile-repository similar to how
glib-compile-resources is exposed so meson and other external
tools can locate it.
2024-12-10 17:58:41 +00:00
Barnabás Pőcze
7a528d0ff0 girepository: gi_object_info_find_signal(): Avoid repeated allocations
Previously `gi_object_info_find_signal()` used `gi_object_info_get_signal()`
to retrieve the *i*th signal and compare its name to the desired name.
However, `gi_object_info_get_signal()` returns an allocated object.
If the names were not matching, the allocated object was simply dropped,
and this resulted in a lot of unnecessary allocations compared to the
desired number of allocations, which is one.

To avoid much of the overhead pertaining to the creation of these allocated
`GISignalInfo` objects, introduce a new function that inspects the signal
blobs directly and returns an allocated `GISignalInfo` object just for the
matching signal. The function is largely a copy-and-paste of `gi_base_info_find_vfunc()`,
which does the same thing, only for virtual functions.

See https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/504
2024-11-23 19:25:17 +01:00
Emmanuele Bassi
20134e6942 gir: Ignore function-inline and method-inline elements
Static inlines are available in the GIR, but they do not translate to
ABI, so they cannot go in the typelib. We handle them just like function
macros.
2024-10-03 18:35:38 +02:00
Olivier Blin
190f9249cd girepository: Make _blob_is_registered_type static inline
This follows the usage in the glib codebase and recommendations at
main/docs/toolchain-requirements.md

It also fixes a build warning with ancient gcc 4.8:
../girepository/gitypelib-internal.h:202:1: warning:
no previous prototype for ‘_blob_is_registered_type’ [-Wmissing-prototypes]
2024-09-25 10:45:05 +02:00