diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2022-10-29 18:09:23 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2023-01-08 14:50:28 +0000 |
commit | e9e3866133275cedcec6b9953adaf88fefcabbf8 (patch) | |
tree | 813abc2433ad2d50c23303a6cc0c7b09a8646a92 /girepository/girwriter.c | |
parent | 221b006625f2185b5a4d81d544bd0a2acf70ef60 (diff) | |
download | gobject-introspection-e9e3866133275cedcec6b9953adaf88fefcabbf8.tar.gz |
Add copy and free function annotations for POD types
Plain Old Data (POD) types with or without a representation in the GType
type system can still have a copy and/or a free function. We should
allow annotating these types with their corresponding functions for
copying their data into a new instance, and freeing their data.
From a language bindings perspective, POD types should have a boxed
GType wrapper around them, so they can use the generic GBoxed API to
copy and free instances; from a documentation perspective, though, it'd
be good to have a way to match a structured type, like a struct or a
union, with its copy and free functions.
In order to do that, we add two new header block annotations:
- (copy-func function_name)
- (free-func function_name)
These annotations work exactly like ref-func and unref-func for typed
instances:
/**
* GdkRGBA: (copy-func gdk_rgba_copy)
* (free-func gdk_rgba_free)
* @red: ...
* @green: ...
* @blue: ...
* @alpha: ...
*
* ...
*/
The function is stored in the GIR data as two new attributes for the
`<record>` and `<union>` elements:
<record name="RGBA"
c:type="GdkRGBA"
copy-function="gdk_rgba_copy"
free-function="gdk_rgba_free"
glib:type-name="GdkRGBA"
glib:get-type="gdk_rgba_get_type"
c:symbol-prefix="gdk_rgba">
The annotations are not mandatory.
See: #14
Diffstat (limited to 'girepository/girwriter.c')
-rw-r--r-- | girepository/girwriter.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/girepository/girwriter.c b/girepository/girwriter.c index ea148f32..276bb676 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -642,6 +642,7 @@ write_struct_info (const gchar *namespace, const gchar *name; const gchar *type_name; const gchar *type_init; + const gchar *func; gboolean deprecated; gboolean is_gtype_struct; gboolean foreign; @@ -676,6 +677,14 @@ write_struct_info (const gchar *namespace, if (is_gtype_struct) xml_printf (file, " glib:is-gtype-struct=\"1\""); + func = g_struct_info_get_copy_function (info); + if (func) + xml_printf (file, " copy-function=\"%s\"", func); + + func = g_struct_info_get_free_function (info); + if (func) + xml_printf (file, " free-function=\"%s\"", func); + write_attributes (file, (GIBaseInfo*) info); size = g_struct_info_get_size (info); @@ -1237,6 +1246,7 @@ write_union_info (const gchar *namespace, const gchar *name; const gchar *type_name; const gchar *type_init; + const gchar *func; gboolean deprecated; gint i; gint size; @@ -1260,6 +1270,14 @@ write_union_info (const gchar *namespace, if (file->show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); + func = g_union_info_get_copy_function (info); + if (func) + xml_printf (file, " copy-function=\"%s\"", func); + + func = g_union_info_get_free_function (info); + if (func) + xml_printf (file, " free-function=\"%s\"", func); + write_attributes (file, (GIBaseInfo*) info); if (g_union_info_is_discriminated (info)) |