[gobject-introspection/wip/transformer] [major] callbacks cleanup
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/transformer] [major] callbacks cleanup
- Date: Mon, 16 Aug 2010 22:35:48 +0000 (UTC)
commit 68a6628c8bc8bfb1bc91d3b147a6d7390672e454
Author: Colin Walters <walters verbum org>
Date: Mon Aug 16 18:17:57 2010 -0400
[major] callbacks cleanup
giscanner/finaltransformer.py | 9 +++++
giscanner/primarytransformer.py | 69 +++++++++++++-----------------------
tests/scanner/Foo-1.0-expected.gir | 8 ++--
3 files changed, 38 insertions(+), 48 deletions(-)
---
diff --git a/giscanner/finaltransformer.py b/giscanner/finaltransformer.py
index 0962851..2e95efe 100644
--- a/giscanner/finaltransformer.py
+++ b/giscanner/finaltransformer.py
@@ -74,6 +74,15 @@ class FinalTransformer(object):
elif node.transfer is None:
self._parameter_warning(parent, node, "Missing (transfer) annotation")
parent.introspectable = False
+
+ if node.type.target_giname:
+ target = self._transformer.lookup_typenode(node.type)
+ if (isinstance(target, Callback)
+ and not target.create_type().target_giname in ('GLib.DestroyNotify', 'Gio.AsyncReadyCallback')
+ and node.scope is None):
+ self._parameter_warning(parent, node,
+ "Missing (scope) annotation for callback without GDestroyNotify (valid: %s, %s)" % (PARAM_SCOPE_CALL, PARAM_SCOPE_ASYNC))
+ parent.introspectable = False
def _type_is_introspectable(self, typeval, warn=False):
if not typeval.resolved:
diff --git a/giscanner/primarytransformer.py b/giscanner/primarytransformer.py
index 8f99ad4..213ffba 100644
--- a/giscanner/primarytransformer.py
+++ b/giscanner/primarytransformer.py
@@ -877,54 +877,35 @@ method or constructor of some type."""
"""Check to see if we have anything that looks like a
callback+user_data+GDestroyNotify set."""
- def _handle_closure(param, closure_idx, closure_param):
- if (closure_param.type.is_equiv(TYPE_ANY) and
- closure_param.argname.endswith('data')):
- param.closure_name = closure_param.argname
- param.closure_index = closure_idx
- return True
- return False
-
- def _handle_destroy(param, destroy_idx, destroy_param):
- if destroy_param.type.target_giname == 'GLib.DestroyNotify':
- param.destroy_name = destroy_param.argname
- param.destroy_index = destroy_idx
- param.scope = PARAM_SCOPE_NOTIFIED
- param.transfer = PARAM_TRANSFER_NONE
- return True
- return False
-
params = node.parameters
- callback_index = -1
+
+ # First, do defaults for Gio.AsyncReadyCallback
for i, param in enumerate(params):
- node = self._transformer.lookup_typenode(param.type)
- if not isinstance(node, Callback):
- continue
- # Special case GAsyncReadyCallback
- if param.type.target_giname == 'Gio.AsyncReadyCallback':
- param.scope = OPT_SCOPE_ASYNC
- param.transfer = PARAM_TRANSFER_NONE
- continue
+ argnode = self._transformer.lookup_typenode(param.type)
+ if isinstance(argnode, Callback):
+ if param.type.target_giname == 'Gio.AsyncReadyCallback':
+ param.scope = PARAM_SCOPE_ASYNC
+ param.transfer = PARAM_TRANSFER_NONE
- # j is the index where we look for closure/destroy to
- # group with the callback param
- j = i + 1
- if j == len(params):
- continue # no more args -> nothing to group
- # look at the param directly following for either a
- # closure or a destroy; only one of these will fire
- had_closure = _handle_closure(param, j, params[j])
- had_destroy = _handle_destroy(param, j, params[j])
- j += 1
- # are we out of params, or did we find neither?
- if j == len(params) or (not had_closure and not had_destroy):
+ callback_param = None
+ for i, param in enumerate(params):
+ argnode = self._transformer.lookup_typenode(param.type)
+ is_destroynotify = False
+ if isinstance(argnode, Callback):
+ if param.type.target_giname == 'GLib.DestroyNotify':
+ is_destroynotify = True
+ else:
+ callback_param = param
+ continue
+ if callback_param is None:
continue
- # we found either a closure or a destroy; check the
- # parameter following for the other
- if not had_closure:
- _handle_closure(param, j, params[j])
- if not had_destroy:
- _handle_destroy(param, j, params[j])
+ if is_destroynotify:
+ callback_param.destroy_index = i
+ callback_param.scope = PARAM_SCOPE_NOTIFIED
+ callback_param.transfer = PARAM_TRANSFER_NONE
+ elif (param.type.is_equiv(TYPE_ANY) and
+ param.argname.endswith('data')):
+ callback_param.closure_index = i
def _pass3_callable_throws(self, node):
"""Check to see if we have anything that looks like a
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index ba2a5db..7c7a01e 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -945,7 +945,7 @@ exposed to language bindings.</doc>
<parameter name="i" transfer-ownership="none">
<type name="gint" c:type="gint"/>
</parameter>
- <parameter name="callback" transfer-ownership="none" scope="call">
+ <parameter name="callback" transfer-ownership="none">
<type name="VarargsCallback" c:type="FooVarargsCallback"/>
</parameter>
</parameters>
@@ -957,7 +957,7 @@ exposed to language bindings.</doc>
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="callback" transfer-ownership="none" scope="call">
+ <parameter name="callback" transfer-ownership="none">
<type name="VarargsCallback" c:type="FooVarargsCallback"/>
</parameter>
</parameters>
@@ -969,10 +969,10 @@ exposed to language bindings.</doc>
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="callback" transfer-ownership="none" scope="call">
+ <parameter name="callback" transfer-ownership="none">
<type name="VarargsCallback" c:type="FooVarargsCallback"/>
</parameter>
- <parameter name="callback2" transfer-ownership="none" scope="call">
+ <parameter name="callback2" transfer-ownership="none">
<type name="VarargsCallback" c:type="FooVarargsCallback"/>
</parameter>
</parameters>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]