Commit Graph

39 Commits

Author SHA1 Message Date
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
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
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
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
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
Philip Withnall
0909b2e3ac girnode: Improve int types in GIIrNodeUnion
`GIIrNodeUnion` is built dynamically at runtime (rather than being
mmapped from disk), so its types can accurately reflect their runtime
semantics, rather than an on-disk format.

As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()`
for parsing the relevant fields from a GIR XML file. This means we now
get error handling for invalid integers.

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

Helps: #3155

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-26 09:29:30 +00:00
Philip Withnall
501ff95cea girnode: Improve int types in GIIrNodeField
`GIIrNodeField` is built dynamically at runtime (rather than being
mmapped from disk), so its types can accurately reflect their runtime
semantics, rather than an on-disk format.

As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()`
for parsing the relevant fields from a GIR XML file. This means we now
get error handling for invalid integers.

This also includes some offset validity changes which were forgotten
from commit 515b3fc1dc.

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

Helps: #3155
2024-01-26 09:29:30 +00:00
Philip Withnall
48d9f356c3 girnode: Improve int types in GIIrNodeVFunc
`GIIrNodeVFunc` is built dynamically at runtime (rather than being
mmapped from disk), so its types can accurately reflect their runtime
semantics, rather than an on-disk format.

As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()`
for parsing the relevant fields from a GIR XML file. This means we now
get error handling for invalid integers.

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

Helps: #3155
2024-01-26 09:29:30 +00:00
Philip Withnall
e7f26b1440 girnode: Improve int types in GIIrNodeType
`GIIrNodeType` is built dynamically at runtime (rather than being
mmapped from disk), so its types can accurately reflect their runtime
semantics, rather than an on-disk format.

As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()`
for parsing the relevant fields from a GIR XML file. This means we now
get error handling for invalid integers.

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

Helps: #3155
2024-01-26 09:29:30 +00: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)
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)
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)
9f33015a25 girrepository: Use standard int sized types instead of g[u]int* 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)
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
Marco Trevisan (Treviño)
2ee2088f4a girrepository: Drop trailing new line on GMessages 2024-01-15 21:26:53 +00:00
Philip Withnall
e1de1fb316 girparser: Port documentation to gi-docgen and update
Review and update the documentation, making sure it’s complete,
formatted in gi-docgen format, and has all appropriate GIR annotations
and `Since:` lines.

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

Helps: #3155
2023-12-18 14:14:15 +00:00
Philip Withnall
2b544c3f66 girepository: Remove _ prefix from private functions
Now that libgirepository uses `GI_AVAILABLE_IN_*` macros, that’s what
controls symbol visibility. The `_` prefixes are redundant, and out of
keeping with the rest of GLib.

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

Helps: #3155
2023-11-08 15:23:31 +00:00
Philip Withnall
b32da06a7c girepository: Rename symbols to the GI namespace
Rather than a mix of structs being in `GI` and their methods being in
`g_`.

We’ve chosen not to use the `g_` namespace because a number of the
libgirepository class names are quite generic, so we’d end up with
confusing symbols like `GScopeType` and `GArgument`.

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

Helps: #3155
2023-11-08 15:05:20 +00:00
Emmanuele Bassi
b0f4a6bcc4 gir: Rename girnode.h to girnode-private.h
It's a private header.
2023-11-08 00:09:04 +00:00
Emmanuele Bassi
f9580e90c4 gir: Rename girparser.h to girparser-private.h
It's a private header.
2023-11-08 00:07:11 +00:00
Emmanuele Bassi
48984375dc gir: Rename girmodule.h to girmodule-private.h
It's private header.
2023-11-08 00:06:01 +00:00
Philip Withnall
216066d90c girparser: Add a missing G_GNUC_FALLTHROUGH
This fixes a compiler warning.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3155
2023-10-25 18:38:30 +01:00
Philip Withnall
844544f72c girepository: Add SPDX license header to all obvious files
Add the SPDX license runes to all the files which have an obvious
copyright header already. This is a mechanical edit.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3155
2023-10-25 17:10:10 +01:00
Emmanuele Bassi
03d6c16434 Move girepository 2023-10-15 17:56:05 +01:00