Skip to content

Add GLib List/SList return value copy/free support - #1573

Open
ousnius wants to merge 1 commit into
gircore:mainfrom
ousnius:list-element-copy-free
Open

Add GLib List/SList return value copy/free support#1573
ousnius wants to merge 1 commit into
gircore:mainfrom
ousnius:list-element-copy-free

Conversation

@ousnius

@ousnius ousnius commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Implement end-to-end handling for GLib.List and GLib.SList return values by loading nested G-IR element types, resolving them into GirModel metadata, and generating managed array conversions for supported element types (strings, classes/interfaces, and typed records) with transfer-aware ownership behavior.

Add internal/container list handle types and UTF-8 string helpers for safe conversion/freeing, wire new converters into return-type rendering, and keep unsupported list element cases on container fallback paths. Also add native GirTest list fixtures, binding/unit tests for element-type resolution and transfer semantics, and update the Secret sample to iterate returned collections directly.

⚠️ Breaking API change
Methods returning a GList/GSList now hand back a typed managed array whose elements are adopted or copied according to the transfer mode, instead of an opaque GLib.List wrapper that leaked its contents. 162 methods across the bound libraries changed shape — for example Gio.AppInfoHelper.GetAll() went from returning GLib.List to Gio.AppInfo[].

Once the elements are copied out into managed objects, the only thing left to free is the container itself, so transfer full and transfer container share one internal handle type (ListContainerHandle), releasing with g_list_free/g_slist_free); transfer none keeps the existing unowned handle that frees nothing. What differs per transfer mode is the element, decided in ListElement.cs: with transfer full we own each element, so it is adopted by an owned handle or an owning wrapper; with container or none we don't, so each element is copied or referenced.

Supported element types are GObject classes and interfaces, UTF-8 strings, and typed and opaque-typed records; anything else (a gpointer list, for instance) still falls back to the old GLib.List wrapper rather than losing the method.

  • I agree that my contribution may be licensed either under MIT or any version of LGPL license.

Implement end-to-end handling for GLib.List and GLib.SList return values by loading nested G-IR element types, resolving them into GirModel metadata, and generating managed array conversions for supported element types (strings, classes/interfaces, and typed records) with transfer-aware ownership behavior.

Add internal/container list handle types and UTF-8 string helpers for safe conversion/freeing, wire new converters into return-type rendering, and keep unsupported list element cases on container fallback paths. Also add native GirTest list fixtures, binding/unit tests for element-type resolution and transfer semantics, and update the Secret sample to iterate returned collections directly.
@ousnius
ousnius marked this pull request as ready for review July 29, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant