[gobject-introspection/pointer-aliases] scanner: Aliases of gpointer are pointers
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/pointer-aliases] scanner: Aliases of gpointer are pointers
- Date: Fri, 8 Oct 2021 11:04:45 +0000 (UTC)
commit 995a141b378030110202483b9f8f9c91a3e785aa
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Oct 8 12:01:57 2021 +0100
scanner: Aliases of gpointer are pointers
If we have a type alias defined as:
typedef gpointer FooPointer
and we use it inside our API like:
Bar* foo_pointer_get_bar (FooPointer self)
then we want `foo_pointer_get_bar` to be detected as a method of
`FooPointer`, instead of a global function that takes a `FooPointer` as
its only argument.
This requires checking if the first argument is a pointer type *or* an
alias to `gpointer`.
giscanner/maintransformer.py | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 0f1ea9b6..ea2865f2 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1147,6 +1147,21 @@ method or constructor of some type."""
name = typeval.get_giname()
return to_underscores_noprefix(name).lower()
+ def _is_instance_pointer(self, typeval):
+ pointer_types = (
+ ast.Boxed,
+ ast.Class,
+ ast.Interface,
+ ast.Record,
+ ast.Union,
+ )
+ if isinstance(typeval, pointer_types):
+ return True
+ # Aliases to gpointer are also pointers
+ if isinstance(typeval, ast.Alias) and typeval.target.is_equiv(ast.TYPE_ANY):
+ return True
+ return False
+
def _is_method(self, func, subsymbol):
if not func.parameters:
if func.is_method:
@@ -1155,9 +1170,7 @@ method or constructor of some type."""
return False
first = func.parameters[0]
target = self._transformer.lookup_typenode(first.type)
- if not isinstance(target, (ast.Class, ast.Interface,
- ast.Record, ast.Union,
- ast.Boxed)):
+ if not self._is_instance_pointer(target):
if func.is_method:
message.warn_node(func,
'%s: Methods must have a pointer as their first '
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]