summaryrefslogtreecommitdiff
path: root/girepository/gicallableinfo.c
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2010-06-15 11:01:37 -0400
committerDavid Zeuthen <davidz@redhat.com>2010-06-24 11:53:18 -0400
commit11cfe386c37ced44a8e3efb5556bde3a43a11171 (patch)
treea01903a4e4596ca80c79abbc8d35c33dc665e526 /girepository/gicallableinfo.c
parent751ffa016e410a031028282e63f98a94cc444b7b (diff)
downloadgobject-introspection-11cfe386c37ced44a8e3efb5556bde3a43a11171.tar.gz
Allow attributes on parameters and return values
Any annotation where the key has a dot in the name will go into the attribute list. For example * @arg: (foo.bar baz): some arg the parameter @arg will get the attribute with key foo.bar and value baz. This also works for. * Returns: (foo.bar2 baz2): the return value Also add tests for this new feature. See https://bugzilla.gnome.org/show_bug.cgi?id=571548 Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'girepository/gicallableinfo.c')
-rw-r--r--girepository/gicallableinfo.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/girepository/gicallableinfo.c b/girepository/gicallableinfo.c
index 6097cb48..6b79e62c 100644
--- a/girepository/gicallableinfo.c
+++ b/girepository/gicallableinfo.c
@@ -19,6 +19,8 @@
* Boston, MA 02111-1307, USA.
*/
+#include <stdlib.h>
+
#include <glib.h>
#include <girepository.h>
@@ -259,3 +261,77 @@ g_callable_info_load_arg (GICallableInfo *info,
_g_info_init ((GIRealInfo*)arg, GI_INFO_TYPE_ARG, rinfo->repository, (GIBaseInfo*)info, rinfo->typelib,
offset + header->signature_blob_size + n * header->arg_blob_size);
}
+
+/**
+ * g_callable_info_get_return_attribute:
+ * @info: a #GICallableInfo
+ * @name: a freeform string naming an attribute
+ *
+ * Retrieve an arbitrary attribute associated with the return value.
+ *
+ * Returns: The value of the attribute, or %NULL if no such attribute exists
+ */
+const gchar *
+g_callable_info_get_return_attribute (GICallableInfo *info,
+ const gchar *name)
+{
+ GIAttributeIter iter = { 0, };
+ gchar *curname, *curvalue;
+ while (g_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue))
+ {
+ if (g_strcmp0 (name, curname) == 0)
+ return (const gchar*) curvalue;
+ }
+
+ return NULL;
+}
+
+/**
+ * g_callable_info_iterate_return_attributes:
+ * @info: a #GICallableInfo
+ * @iterator: a #GIAttributeIter structure, must be initialized; see below
+ * @name: (out) (transfer none): Returned name, must not be freed
+ * @value: (out) (transfer none): Returned name, must not be freed
+ *
+ * Iterate over all attributes associated with the return value. The
+ * iterator structure is typically stack allocated, and must have its
+ * first member initialized to %NULL.
+ *
+ * Both the @name and @value should be treated as constants
+ * and must not be freed.
+ *
+ * See g_base_info_iterate_attributes() for an example of how to use a
+ * similar API.
+ *
+ * Returns: %TRUE if there are more attributes
+ */
+gboolean
+g_callable_info_iterate_return_attributes (GICallableInfo *info,
+ GIAttributeIter *iterator,
+ char **name,
+ char **value)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ Header *header = (Header *)rinfo->typelib->data;
+ AttributeBlob *next, *after;
+ guint32 blob_offset;
+
+ after = (AttributeBlob *) &rinfo->typelib->data[header->attributes +
+ header->n_attributes * header->attribute_blob_size];
+
+ blob_offset = signature_offset (info);
+
+ if (iterator->data != NULL)
+ next = (AttributeBlob *) iterator->data;
+ else
+ next = _attribute_blob_find_first (info, blob_offset);
+
+ if (next == NULL || next->offset != blob_offset || next >= after)
+ return FALSE;
+
+ *name = (gchar*) g_typelib_get_string (rinfo->typelib, next->name);
+ *value = (gchar*) g_typelib_get_string (rinfo->typelib, next->value);
+ iterator->data = next + 1;
+
+ return TRUE;
+}