[gobject-introspection] Add support for the (skip) annotation on parameters or return values
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Add support for the (skip) annotation on parameters or return values
- Date: Fri, 13 May 2011 18:20:53 +0000 (UTC)
commit 9c6797e0478b5025c3f2f37b1331c1328cf34f4d
Author: David Zeuthen <davidz redhat com>
Date: Fri May 13 12:20:05 2011 -0400
Add support for the (skip) annotation on parameters or return values
This was discussed in bug 649657.
https://bugzilla.gnome.org/show_bug.cgi?id=649657
Signed-off-by: David Zeuthen <davidz redhat com>
girepository/giarginfo.c | 22 +++++++++++++++
girepository/giarginfo.h | 1 +
girepository/gicallableinfo.c | 22 +++++++++++++++
girepository/gicallableinfo.h | 1 +
girepository/girnode.c | 2 +
girepository/girnode.h | 1 +
girepository/girparser.c | 14 +++++++++
girepository/girwriter.c | 6 ++++
girepository/gitypelib-internal.h | 8 ++++-
giscanner/girwriter.py | 4 +++
giscanner/maintransformer.py | 3 ++
tests/scanner/Foo-1.0-expected.gir | 52 ++++++++++++++++++++++++++++++++++++
tests/scanner/foo.c | 43 +++++++++++++++++++++++++++++
tests/scanner/foo.h | 12 ++++++++
14 files changed, 189 insertions(+), 2 deletions(-)
---
diff --git a/girepository/giarginfo.c b/girepository/giarginfo.c
index dc1d116..069ecce 100644
--- a/girepository/giarginfo.c
+++ b/girepository/giarginfo.c
@@ -165,6 +165,28 @@ g_arg_info_may_be_null (GIArgInfo *info)
}
/**
+ * g_arg_info_is_skip:
+ * @info: a #GIArgInfo
+ *
+ * Obtain if an argument is only useful in C.
+ *
+ * Returns: %TRUE if argument is only useful in C.
+ */
+gboolean
+g_arg_info_is_skip (GIArgInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ ArgBlob *blob;
+
+ g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE);
+
+ blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ return blob->skip;
+}
+
+/**
* g_arg_info_get_ownership_transfer:
* @info: a #GIArgInfo
*
diff --git a/girepository/giarginfo.h b/girepository/giarginfo.h
index e38d16f..9daafa2 100644
--- a/girepository/giarginfo.h
+++ b/girepository/giarginfo.h
@@ -38,6 +38,7 @@ gboolean g_arg_info_is_return_value (GIArgInfo *info);
gboolean g_arg_info_is_optional (GIArgInfo *info);
gboolean g_arg_info_is_caller_allocates (GIArgInfo *info);
gboolean g_arg_info_may_be_null (GIArgInfo *info);
+gboolean g_arg_info_is_skip (GIArgInfo *info);
GITransfer g_arg_info_get_ownership_transfer (GIArgInfo *info);
GIScopeType g_arg_info_get_scope (GIArgInfo *info);
gint g_arg_info_get_closure (GIArgInfo *info);
diff --git a/girepository/gicallableinfo.c b/girepository/gicallableinfo.c
index 1d43968..475346e 100644
--- a/girepository/gicallableinfo.c
+++ b/girepository/gicallableinfo.c
@@ -153,6 +153,28 @@ g_callable_info_may_return_null (GICallableInfo *info)
}
/**
+ * g_callable_info_skip_return:
+ * @info: a #GICallableInfo
+ *
+ * See if a callable's return value is only useful in C.
+ *
+ * Returns: %TRUE if return value is only useful in C.
+ */
+gboolean
+g_callable_info_skip_return (GICallableInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SignatureBlob *blob;
+
+ g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), FALSE);
+
+ blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
+
+ return blob->skip_return;
+}
+
+/**
* g_callable_info_get_caller_owns:
* @info: a #GICallableInfo
*
diff --git a/girepository/gicallableinfo.h b/girepository/gicallableinfo.h
index 54d2cac..a1d22c7 100644
--- a/girepository/gicallableinfo.h
+++ b/girepository/gicallableinfo.h
@@ -47,6 +47,7 @@ gboolean g_callable_info_iterate_return_attributes (GICallableInfo
char **value);
GITransfer g_callable_info_get_caller_owns (GICallableInfo *info);
gboolean g_callable_info_may_return_null (GICallableInfo *info);
+gboolean g_callable_info_skip_return (GICallableInfo *info);
gint g_callable_info_get_n_args (GICallableInfo *info);
GIArgInfo * g_callable_info_get_arg (GICallableInfo *info,
gint n);
diff --git a/girepository/girnode.c b/girepository/girnode.c
index fe10e54..9998d8e 100644
--- a/girepository/girnode.c
+++ b/girepository/girnode.c
@@ -1685,6 +1685,7 @@ _g_ir_node_build_typelib (GIrNode *node,
blob2->may_return_null = function->result->allow_none;
blob2->caller_owns_return_value = function->result->transfer;
blob2->caller_owns_return_container = function->result->shallow_transfer;
+ blob2->skip_return = function->result->skip;
blob2->reserved = 0;
blob2->n_arguments = n;
@@ -1869,6 +1870,7 @@ _g_ir_node_build_typelib (GIrNode *node,
blob->out = param->out;
blob->caller_allocates = param->caller_allocates;
blob->allow_none = param->allow_none;
+ blob->skip = param->skip;
blob->optional = param->optional;
blob->transfer_ownership = param->transfer;
blob->transfer_container_ownership = param->shallow_transfer;
diff --git a/girepository/girnode.h b/girepository/girnode.h
index e215e2c..1f9102f 100644
--- a/girepository/girnode.h
+++ b/girepository/girnode.h
@@ -147,6 +147,7 @@ struct _GIrNodeParam
gboolean optional;
gboolean retval;
gboolean allow_none;
+ gboolean skip;
gboolean transfer;
gboolean shallow_transfer;
GIScopeType scope;
diff --git a/girepository/girparser.c b/girepository/girparser.c
index f7269b9..02c0442 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -1030,6 +1030,7 @@ start_parameter (GMarkupParseContext *context,
const gchar *scope;
const gchar *closure;
const gchar *destroy;
+ const gchar *skip;
GIrNodeParam *param;
if (!(strcmp (element_name, "parameter") == 0 &&
@@ -1046,6 +1047,7 @@ start_parameter (GMarkupParseContext *context,
scope = find_attribute ("scope", attribute_names, attribute_values);
closure = find_attribute ("closure", attribute_names, attribute_values);
destroy = find_attribute ("destroy", attribute_names, attribute_values);
+ skip = find_attribute ("skip", attribute_names, attribute_values);
if (name == NULL)
name = "unknown";
@@ -1095,6 +1097,11 @@ start_parameter (GMarkupParseContext *context,
else
param->allow_none = FALSE;
+ if (skip && strcmp (skip, "1") == 0)
+ param->skip = TRUE;
+ else
+ param->skip = FALSE;
+
if (!parse_param_transfer (param, transfer, name, error))
return FALSE;
@@ -2200,6 +2207,7 @@ start_return_value (GMarkupParseContext *context,
{
GIrNodeParam *param;
const gchar *transfer;
+ const gchar *skip;
if (!(strcmp (element_name, "return-value") == 0 &&
ctx->state == STATE_FUNCTION))
@@ -2215,6 +2223,12 @@ start_return_value (GMarkupParseContext *context,
state_switch (ctx, STATE_FUNCTION_RETURN);
+ skip = find_attribute ("skip", attribute_names, attribute_values);
+ if (skip && strcmp (skip, "1") == 0)
+ param->skip = TRUE;
+ else
+ param->skip = FALSE;
+
transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
if (!parse_param_transfer (param, transfer, NULL, error))
return FALSE;
diff --git a/girepository/girwriter.c b/girepository/girwriter.c
index e90799c..f6ab34e 100644
--- a/girepository/girwriter.c
+++ b/girepository/girwriter.c
@@ -482,6 +482,9 @@ write_callable_info (const gchar *namespace,
if (g_callable_info_may_return_null (info))
xml_printf (file, " allow-none=\"1\"");
+ if (g_callable_info_skip_return (info))
+ xml_printf (file, " skip=\"1\"");
+
write_return_value_attributes (file, info);
write_type_info (namespace, type, file);
@@ -545,6 +548,9 @@ write_callable_info (const gchar *namespace,
if (g_arg_info_get_destroy (arg) >= 0)
xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg));
+ if (g_arg_info_is_skip (arg))
+ xml_printf (file, " skip=\"1\"");
+
write_attributes (file, (GIBaseInfo*) arg);
type = g_arg_info_get_type (arg);
diff --git a/girepository/gitypelib-internal.h b/girepository/gitypelib-internal.h
index e8f5c02..593c987 100644
--- a/girepository/gitypelib-internal.h
+++ b/girepository/gitypelib-internal.h
@@ -409,6 +409,7 @@ typedef union
* @destroy: Index of the destroy notfication callback parameter associated with
* the callback, or -1.
* @arg_type: Describes the type of the parameter. See details below.
+ * @skip: Indicates that the parameter is only useful in C and should be skipped.
*
* Types are specified by four bytes. If the three high bytes are zero,
* the low byte describes a basic type, otherwise the 32bit number is an
@@ -426,8 +427,9 @@ typedef struct {
guint transfer_container_ownership : 1;
guint return_value : 1;
guint scope : 3;
+ guint skip : 1;
/* <private> */
- guint reserved :21;
+ guint reserved :20;
/* <public> */
gint8 closure;
gint8 destroy;
@@ -445,6 +447,7 @@ typedef struct {
* @caller_owns_return_container: This flag is only relevant if the return type is a container type.
* If the flag is set, the caller is resonsible for freeing the
* container, but not its contents.
+ * @skip_return: Indicates that the return value is only useful in C and should be skipped.
* @n_arguments: The number of arguments that this function expects, also the length
* of the array of ArgBlobs.
* @arguments: An array of ArgBlob for the arguments of the function.
@@ -455,7 +458,8 @@ typedef struct {
guint16 may_return_null : 1;
guint16 caller_owns_return_value : 1;
guint16 caller_owns_return_container : 1;
- guint16 reserved :13;
+ guint16 skip_return : 1;
+ guint16 reserved :12;
guint16 n_arguments;
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 1eca615..ad601ee 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -196,6 +196,8 @@ and/or use gtk-doc annotations. ''')
attrs = []
if return_.transfer:
attrs.append(('transfer-ownership', return_.transfer))
+ if return_.skip:
+ attrs.append(('skip', '1'))
with self.tagcontext('return-value', attrs):
self._write_generic(return_)
self._write_type(return_.type, function=parent)
@@ -228,6 +230,8 @@ and/or use gtk-doc annotations. ''')
if parameter.destroy_name is not None:
idx = parent.get_parameter_index(parameter.destroy_name)
attrs.append(('destroy', '%d' % (idx, )))
+ if parameter.skip:
+ attrs.append(('skip', '1'))
with self.tagcontext('parameter', attrs):
self._write_generic(parameter)
self._write_type(parameter.type, function=parent)
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 1a10434..bc795c0 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -541,6 +541,9 @@ usage is void (*_gtk_reserved1)(void);"""
if tag is not None and tag.comment is not None:
node.doc = tag.comment
+ if OPT_SKIP in options:
+ node.skip = True
+
if options:
for attribute in options.getall(OPT_ATTRIBUTE):
node.attributes.append(attribute.flat())
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index fa5ee93..64f40db 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -455,6 +455,58 @@ uses a C sugar return type.</doc>
</parameter>
</parameters>
</method>
+ <method name="skip_param"
+ c:identifier="foo_object_skip_param"
+ throws="1">
+ <doc xml:whitespace="preserve">Check that the return value is skipped</doc>
+ <return-value transfer-ownership="none">
+ <doc xml:whitespace="preserve">%TRUE if the call succeeds, %FALSE if @error is set.</doc>
+ <type name="gboolean" c:type="gboolean"/>
+ </return-value>
+ <parameters>
+ <parameter name="a" transfer-ownership="none">
+ <doc xml:whitespace="preserve">Parameter.</doc>
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="out_b"
+ direction="out"
+ caller-allocates="0"
+ transfer-ownership="full">
+ <doc xml:whitespace="preserve">Return value.</doc>
+ <type name="gint" c:type="gint*"/>
+ </parameter>
+ <parameter name="c" transfer-ownership="none" skip="1">
+ <doc xml:whitespace="preserve">Other parameter.</doc>
+ <type name="gdouble" c:type="gdouble"/>
+ </parameter>
+ </parameters>
+ </method>
+ <method name="skip_return_val"
+ c:identifier="foo_object_skip_return_val"
+ throws="1">
+ <doc xml:whitespace="preserve">Check that the return value is skipped</doc>
+ <return-value transfer-ownership="none" skip="1">
+ <doc xml:whitespace="preserve">%TRUE if the call succeeds, %FALSE if @error is set.</doc>
+ <type name="gboolean" c:type="gboolean"/>
+ </return-value>
+ <parameters>
+ <parameter name="a" transfer-ownership="none">
+ <doc xml:whitespace="preserve">Parameter.</doc>
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="out_b"
+ direction="out"
+ caller-allocates="0"
+ transfer-ownership="full">
+ <doc xml:whitespace="preserve">A return value.</doc>
+ <type name="gint" c:type="gint*"/>
+ </parameter>
+ <parameter name="c" transfer-ownership="none">
+ <doc xml:whitespace="preserve">Other parameter.</doc>
+ <type name="gdouble" c:type="gdouble"/>
+ </parameter>
+ </parameters>
+ </method>
<method name="skipped_method"
c:identifier="foo_object_skipped_method"
introspectable="0">
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index 8b8b40d..6270b61 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -707,6 +707,49 @@ foo_skip_me (FooSkippable fs)
}
/**
+ * foo_object_skip_return_val:
+ * @object: a #FooObject
+ * @a: Parameter.
+ * @out_b: (out): A return value.
+ * @c: Other parameter.
+ * @error: Return location for error.
+ *
+ * Check that the return value is skipped
+ *
+ * Returns: (skip): %TRUE if the call succeeds, %FALSE if @error is set.
+ */
+gboolean
+foo_object_skip_return_val (FooObject *object,
+ gint a,
+ gint *out_b,
+ gdouble c,
+ GError **error)
+{
+ return TRUE;
+}
+
+/**
+ * foo_object_skip_param:
+ * @object: A #FooObject.
+ * @a: Parameter.
+ * @out_b: (out): Return value.
+ * @c: (skip): Other parameter.
+ *
+ * Check that the return value is skipped
+ *
+ * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
+ */
+gboolean
+foo_object_skip_param (FooObject *object,
+ gint a,
+ gint *out_b,
+ gdouble c,
+ GError **error)
+{
+ return TRUE;
+}
+
+/**
* FooForeignStruct: (foreign)
*
*/
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index e648e60..997799d 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -416,6 +416,18 @@ typedef enum {
} FooSkippable;
void foo_skip_me (FooSkippable fs);
+gboolean foo_object_skip_return_val (FooObject *object,
+ gint a,
+ gint *out_b,
+ gdouble c,
+ GError **error);
+
+gboolean foo_object_skip_param (FooObject *object,
+ gint a,
+ gint *out_b,
+ gdouble c,
+ GError **error);
+
typedef struct _FooForeignStruct FooForeignStruct;
struct _FooForeignStruct
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]