Skip to content

ffi: Adapt load_enum to glib 2.87 changes#352

Open
aleasto wants to merge 1 commit into
lgi-devs:masterfrom
aleasto:glib-2.87
Open

ffi: Adapt load_enum to glib 2.87 changes#352
aleasto wants to merge 1 commit into
lgi-devs:masterfrom
aleasto:glib-2.87

Conversation

@aleasto
Copy link
Copy Markdown

@aleasto aleasto commented Feb 4, 2026

After glib change https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4803,
the values field is bound as an array with type table rather than record.
We can iterate over the array with ipairs().

@aleasto aleasto force-pushed the glib-2.87 branch 2 times, most recently from d214e6d to 2f7fc52 Compare February 4, 2026 17:53
@aleasto aleasto changed the title ffi: Adapt to glib 2.87 ffi: Adapt load_enum to glib 2.87 changes Feb 4, 2026
Comment thread lgi/ffi.lua
local type_class = GObject.TypeClass.ref(gtype)
local enum_class = core.record.cast(
type_class, is_flags and GObject.FlagsClass or GObject.EnumClass)
for i = 0, enum_class.n_values - 1 do
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should do this only for (GLib.MAJOR_VERSION, GLib.MINOR_VERSION) >= (2, 87) (adjusting the syntax)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have picked your commit here

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the logic inverted? We want to use ipairs in the new code, no?

Check version works differently here from what is upstream?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glib_check_version() returns NULL if version is higher or equal (https://docs.gtk.org/glib/func.check_version.html#return-value), so it seems correct as it is.

GLib 2.87.0 includes a fix
(https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4803) to how enum
values are handled, causing the value to be read as a Lua table instead
of a GLib array. This requires some slightly tweaked code when loading
an enum.
robertkirkman added a commit to robertkirkman/termux-packages that referenced this pull request Mar 23, 2026
robertkirkman added a commit to termux/termux-packages that referenced this pull request Mar 23, 2026
termux-pacman-bot added a commit to termux-pacman/termux-packages that referenced this pull request Mar 23, 2026
ImL1s pushed a commit to ImL1s/termux-packages that referenced this pull request May 1, 2026
alexytomi pushed a commit to alexytomi/termux-packages that referenced this pull request May 3, 2026
@PPN-SD
Copy link
Copy Markdown

PPN-SD commented May 4, 2026

This patch is now widely adopted, as is glib‑2.88.0. Could you consider merging it or #361?

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.

5 participants