[gi-docgen/issue-110] gir: Identify type/gpointer types
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/issue-110] gir: Identify type/gpointer types
- Date: Wed, 6 Oct 2021 15:42:57 +0000 (UTC)
commit a3f041b537c08730bfe61a6f30be11b74d193a8c
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Oct 6 16:37:04 2021 +0100
gir: Identify type/gpointer types
When using out/in-out arguments in signals, the C type assigned is
derived from G_TYPE_POINTER (so: gpointer), but the type name is
typically overridden via a (type) annotation. This produces type
definitions like:
<type name="gint" c:type="gpointer"/>
Since the C type is gpointer, we use the type name when looking up the
ast.Type in the GIR parser, and that usually ends up giving use a type
for the integral type, instead of a proper pointer type.
To avoid that, we check if the type definition takes a generic pointer
as the C type, and the type name is an integral type, and tweak the
query parameters for the types LUT.
Fixes: #110
gidocgen/gir/parser.py | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index 1d3b084..0d4bd86 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -14,26 +14,30 @@ GI_NAMESPACES = {
'glib': "http://www.gtk.org/introspection/glib/1.0",
}
-FUNDAMENTAL_TYPES = [
+FUNDAMENTAL_INTEGRAL_TYPES = [
'gint8', 'guint8', 'int8_t', 'uint8_t',
'gint16', 'guint16', 'int16_t', 'uint16_t',
'gint32', 'guint32', 'int32_t', 'uint32_t',
'gint64', 'guint64', 'int64_t', 'uint64_t',
- 'gint', 'guint', 'int', 'unsigned', 'unsigned int',
+ 'gint', 'int',
+ 'guint', 'unsigned', 'unsigned int',
'gfloat', 'float',
'gdouble', 'double', 'long double',
'gchar', 'guchar', 'char', 'unsigned char',
'gshort', 'gushort', 'short', 'unsigned short',
'glong', 'gulong', 'long', 'unsigned long',
- 'utf8', 'filename',
'gunichar',
- 'gpointer', 'gconstpointer',
- 'gchar*', 'char*', 'guchar*',
'gsize', 'gssize', 'size_t',
'gboolean', 'bool',
'va_list',
]
+FUNDAMENTAL_TYPES = FUNDAMENTAL_INTEGRAL_TYPES + [
+ 'gpointer', 'gconstpointer',
+ 'gchar*', 'char*', 'guchar*',
+ 'utf8', 'filename',
+]
+
GLIB_ALIASES = {
'gchar': 'char',
'gdouble': 'double',
@@ -342,7 +346,11 @@ class GirParser:
target = ast.Type(name=ttype.replace('*', ''), ctype=ttype)
if tname == 'none' and ttype == 'void':
target = ast.VoidType()
- elif tname != 'gpointer' and ttype == 'gpointer':
+ elif ttype == 'gpointer' and tname in FUNDAMENTAL_INTEGRAL_TYPES:
+ # API returning a pointer with an overridden fundamental type,
+ # like in-out/out signal arguments
+ ctype = self._lookup_type(name=tname, ctype=f"{tname}*")
+ elif ttype == 'gpointer' and tname != 'gpointer':
# API returning gpointer to avoid casting
target = self._lookup_type(name=tname)
elif tname:
@@ -384,7 +392,11 @@ class GirParser:
value_type=ast.Type(vtname))
else:
ctype = self._lookup_type(name=tname, ctype=ttype)
- elif tname != 'gpointer' and ttype == 'gpointer':
+ elif ttype == 'gpointer' and tname in FUNDAMENTAL_INTEGRAL_TYPES:
+ # API returning a pointer with an overridden fundamental type,
+ # like in-out/out signal arguments
+ ctype = self._lookup_type(name=tname, ctype=f"{tname}*")
+ elif ttype == 'gpointer' and tname != 'gpointer':
# API returning gpointer to avoid casting
ctype = self._lookup_type(name=tname)
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]