[gobject-introspection] Better scope in GAsyncReadyCallback/GDestroyNotify
- From: Johan Dahlin <johan src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Better scope in GAsyncReadyCallback/GDestroyNotify
- Date: Wed, 2 Dec 2009 12:33:35 +0000 (UTC)
commit f74823dbcb647dee950c066119876db9f0edc32f
Author: Johan Dahlin <johan gnome org>
Date: Tue Nov 24 22:18:27 2009 -0200
Better scope in GAsyncReadyCallback/GDestroyNotify
GAsyncReadyCallback should have use the async scope per
default and GDestroyNotify should be notified if the
previous parameters are a callback and user data.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=602862
giscanner/annotationparser.py | 19 +++++++++++++-
tests/scanner/Makefile.am | 3 +-
tests/scanner/annotation-1.0-expected.gir | 1 +
tests/scanner/annotation-1.0-expected.tgir | 2 +-
tests/scanner/foo-1.0-expected.gir | 39 ++++++++++++++++++++++++++++
tests/scanner/foo-1.0-expected.tgir | 33 +++++++++++++++++++++++
tests/scanner/foo.h | 10 +++++++
tests/scanner/utility-1.0-expected.gir | 1 +
tests/scanner/utility-1.0-expected.tgir | 2 +-
9 files changed, 106 insertions(+), 4 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 1cedfb9..f03c624 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -73,6 +73,9 @@ OPT_ARRAY_FIXED_SIZE = 'fixed-size'
OPT_ARRAY_LENGTH = 'length'
OPT_ARRAY_ZERO_TERMINATED = 'zero-terminated'
+OPT_SCOPE_ASYNC = 'async'
+OPT_SCOPE_CALL = 'call'
+OPT_SCOPE_NOTIFIED = 'notified'
class InvalidAnnotationError(Exception):
pass
@@ -410,6 +413,16 @@ class AnnotationApplier(object):
def _parse_callable(self, callable, block):
self._parse_node_common(callable, block)
+ for i, param in enumerate(callable.parameters):
+ if param.type.name != 'GLib.DestroyNotify':
+ continue
+ if i < 2:
+ break
+ callback_param = callable.parameters[i-2]
+ if callback_param.closure_index != -1:
+ callback_param.scope = OPT_SCOPE_NOTIFIED
+ callback_param.transfer = PARAM_TRANSFER_NONE
+
self._parse_params(callable, callable.parameters, block)
self._parse_return(callable, callable.retval, block)
if block:
@@ -490,11 +503,15 @@ class AnnotationApplier(object):
def _parse_param(self, parent, param, tag):
options = getattr(tag, 'options', {})
- if isinstance(parent, Function):
+ if isinstance(parent, Function) and not param.scope:
scope = options.get(OPT_SCOPE)
if scope:
param.scope = scope.one()
param.transfer = PARAM_TRANSFER_NONE
+ elif param.type.name == 'Gio.AsyncReadyCallback':
+ param.scope = OPT_SCOPE_ASYNC
+ param.transfer = PARAM_TRANSFER_NONE
+
destroy = options.get(OPT_DESTROY)
if destroy:
param.destroy_index = parent.get_parameter_index(destroy.one())
diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am
index a14cf8d..001a582 100644
--- a/tests/scanner/Makefile.am
+++ b/tests/scanner/Makefile.am
@@ -12,7 +12,7 @@ testlibdir = $(prefix)/unused
install-testlibLTLIBRARIES: # prevent it from being installed
AM_CPPFLAGS = -I$(top_srcdir)/girepository
-AM_CFLAGS = $(GOBJECT_CFLAGS) $(GTHREAD_CFLAGS)
+AM_CFLAGS = $(GIO_CFLAGS) $(GOBJECT_CFLAGS) $(GTHREAD_CFLAGS)
AM_LDFLAGS = -avoid-version
LIBS = $(GOBJECT_LIBS) $(GTHREAD_LIBS)
@@ -68,6 +68,7 @@ foo-1.0.gir: libfoo.la foo.c foo.h utility-1.0.gir $(SCANNER_BIN) $(SCANNER_LIBS
$(CHECK_DEBUG) $(SCANNER) \
--include=GObject-2.0 \
--include=utility-1.0 \
+ --include=Gio-2.0 \
--c-include="foo.h" \
--libtool="$(LIBTOOL)" \
--library=libfoo.la \
diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir
index df707fd..33d5e7c 100644
--- a/tests/scanner/annotation-1.0-expected.gir
+++ b/tests/scanner/annotation-1.0-expected.gir
@@ -455,6 +455,7 @@ type.">
<parameters>
<parameter name="func"
transfer-ownership="none"
+ scope="notified"
closure="2"
destroy="3">
<type name="ForeachFunc" c:type="AnnotationForeachFunc"/>
diff --git a/tests/scanner/annotation-1.0-expected.tgir b/tests/scanner/annotation-1.0-expected.tgir
index bf0e35b..835a547 100644
--- a/tests/scanner/annotation-1.0-expected.tgir
+++ b/tests/scanner/annotation-1.0-expected.tgir
@@ -339,7 +339,7 @@
<type name="none"/>
</return-value>
<parameters>
- <parameter name="func" transfer-ownership="none" closure="2" destroy="3">
+ <parameter name="func" transfer-ownership="none" scope="notified" closure="2" destroy="3">
<type name="ForeachFunc"/>
</parameter>
<parameter name="user_data" transfer-ownership="none">
diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir
index fa3d73c..d14218c 100644
--- a/tests/scanner/foo-1.0-expected.gir
+++ b/tests/scanner/foo-1.0-expected.gir
@@ -8,6 +8,7 @@ and/or use gtk-doc annotations. -->
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GLib" version="2.0"/>
<include name="GObject" version="2.0"/>
+ <include name="Gio" version="2.0"/>
<include name="utility" version="1.0"/>
<package name="gobject-2.0"/>
<c:include name="foo.h"/>
@@ -702,6 +703,44 @@ uses a C sugar return type.">
</parameter>
</parameters>
</callback>
+ <function name="async_ready_callback"
+ c:identifier="foo_async_ready_callback">
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="cancellable" transfer-ownership="none">
+ <type name="Gio.Cancellable" c:type="GCancellable*"/>
+ </parameter>
+ <parameter name="callback" transfer-ownership="none" scope="async">
+ <type name="Gio.AsyncReadyCallback" c:type="GAsyncReadyCallback"/>
+ </parameter>
+ <parameter name="user_data" transfer-ownership="none">
+ <type name="any" c:type="gpointer"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="destroy_notify_callback"
+ c:identifier="foo_destroy_notify_callback">
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="callback"
+ transfer-ownership="none"
+ scope="notified"
+ closure="1"
+ destroy="2">
+ <type name="Callback" c:type="FooCallback"/>
+ </parameter>
+ <parameter name="data" transfer-ownership="none">
+ <type name="any" c:type="gpointer"/>
+ </parameter>
+ <parameter name="destroy" transfer-ownership="none">
+ <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+ </parameter>
+ </parameters>
+ </function>
<function name="enum_type_method" c:identifier="foo_enum_type_method">
<return-value transfer-ownership="none">
<type name="int" c:type="int"/>
diff --git a/tests/scanner/foo-1.0-expected.tgir b/tests/scanner/foo-1.0-expected.tgir
index bcba5a2..096efa5 100644
--- a/tests/scanner/foo-1.0-expected.tgir
+++ b/tests/scanner/foo-1.0-expected.tgir
@@ -4,6 +4,7 @@
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="utility" version="1.0"/>
+ <include name="Gio" version="2.0"/>
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
<namespace name="foo" version="1.0" shared-library="libfoo.so" c:prefix="foo">
@@ -568,6 +569,38 @@
<type name="utility.Struct"/>
</field>
</record>
+ <function name="async_ready_callback" c:identifier="foo_async_ready_callback">
+ <return-value transfer-ownership="none">
+ <type name="none"/>
+ </return-value>
+ <parameters>
+ <parameter name="cancellable" transfer-ownership="none">
+ <type name="Gio.Cancellable"/>
+ </parameter>
+ <parameter name="callback" transfer-ownership="none" scope="async">
+ <type name="Gio.AsyncReadyCallback"/>
+ </parameter>
+ <parameter name="user_data" transfer-ownership="none">
+ <type name="any"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="destroy_notify_callback" c:identifier="foo_destroy_notify_callback">
+ <return-value transfer-ownership="none">
+ <type name="none"/>
+ </return-value>
+ <parameters>
+ <parameter name="callback" transfer-ownership="none" scope="notified" closure="1" destroy="2">
+ <type name="Callback"/>
+ </parameter>
+ <parameter name="data" transfer-ownership="none">
+ <type name="any"/>
+ </parameter>
+ <parameter name="destroy" transfer-ownership="none">
+ <type name="GLib.DestroyNotify"/>
+ </parameter>
+ </parameters>
+ </function>
<function name="enum_type_method" c:identifier="foo_enum_type_method">
<return-value transfer-ownership="none">
<type name="int"/>
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index b8f88a7..61c2ca4 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -2,6 +2,7 @@
#define __FOO_OBJECT_H__
#include <glib-object.h>
+#include <gio/gio.h> /* GAsyncReadyCallback */
#include "utility.h"
#define FOO_SUCCESS_INT 0x1138
@@ -344,6 +345,14 @@ void foo_test_varargs_callback2 (FooVarargsCallback callback);
void foo_test_varargs_callback3 (FooVarargsCallback callback,
FooVarargsCallback callback2);
+/* Make sure callbacks get the right scope by default */
+void foo_async_ready_callback(GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+void foo_destroy_notify_callback(FooCallback callback,
+ gpointer data,
+ GDestroyNotify destroy);
+
typedef enum {
FOO_ERROR_GOOD,
FOO_ERROR_BAD,
@@ -382,4 +391,5 @@ typedef enum {
} FooSkippable;
void foo_skip_me (FooSkippable fs);
+
#endif /* __FOO_OBJECT_H__ */
diff --git a/tests/scanner/utility-1.0-expected.gir b/tests/scanner/utility-1.0-expected.gir
index 1b2fe84..a597d5d 100644
--- a/tests/scanner/utility-1.0-expected.gir
+++ b/tests/scanner/utility-1.0-expected.gir
@@ -74,6 +74,7 @@ and/or use gtk-doc annotations. -->
</parameter>
<parameter name="func"
transfer-ownership="none"
+ scope="notified"
closure="3"
destroy="4">
<type name="FileFunc" c:type="UtilityFileFunc"/>
diff --git a/tests/scanner/utility-1.0-expected.tgir b/tests/scanner/utility-1.0-expected.tgir
index ec4597a..a58a132 100644
--- a/tests/scanner/utility-1.0-expected.tgir
+++ b/tests/scanner/utility-1.0-expected.tgir
@@ -54,7 +54,7 @@
<parameter name="path" transfer-ownership="none">
<type name="utf8"/>
</parameter>
- <parameter name="func" transfer-ownership="none" closure="3" destroy="4">
+ <parameter name="func" transfer-ownership="none" scope="notified" closure="3" destroy="4">
<type name="FileFunc"/>
</parameter>
<parameter name="user_data" transfer-ownership="none">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]