Binding problems with vte_terminal_event_check_regex_simple()
I'm unable to call the following function using GObject Introspection based bindings:
* vte_terminal_event_check_regex_simple:
* @terminal: a #VteTerminal
* @event: a #GdkEvent
* @regexes: (array length=n_regexes): an array of #VteRegex
* @n_regexes: number of items in @regexes
* @match_flags: PCRE2 match flags, or 0
* @matches: (out caller-allocates) (array length=n_regexes): a location to store the matches
gboolean
vte_terminal_event_check_regex_simple(VteTerminal *terminal,
GdkEvent *event,
VteRegex **regexes,
gsize n_regexes,
guint32 match_flags,
char **matches)
As noticed in this comment, two things are causing problems:
-
matches
is marked as caller-allocated, but the elements of this array (strings) are allocated inside the called function. This allocation mode is not currently supported by GObject Introspection -
Reusing
n_regexes
as the size of both input and output arrays seems not to be supported by GObject Introspection either.n_regexes
treated as an output argument, hence a pointer is passed (see Vala example) while the function expects a value (it also causes problems with pygobject). Here's the GIR snippet:
<parameter name="n_regexes"
direction="out"
caller-allocates="0"
transfer-ownership="full">
<doc xml:space="preserve"
filename="../src/vtegtk.cc"
line="2269">number of items in @regexes</doc>
<type name="gsize" c:type="gsize"/>
</parameter>
Practical examples - segfaults
This python example segfaults: (see this issue)
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Vte', '2.91')
from gi.repository import Gdk, Vte
terminal = Vte.Terminal()
regex = Vte.Regex.new_for_match('x', 1, 0x400)
event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
terminal.event_check_regex_simple(event, [regex], 0)
I've also tried to see the C code produced by this Vala example that segfaults (probably incorrect as I don't know Vala)
class Test : GLib.Object {
public static int main(string[] args) {
var terminal = new Vte.Terminal();
var event = new Gdk.Event(Gdk.EventType.BUTTON_PRESS);
Vte.Regex[] regexes = new Vte.Regex[1];
regexes[0] = new Vte.Regex.for_match("x", 1, 0x400);
string[] matches = new string[1];
terminal.event_check_regex_simple(event, regexes, 0, out matches);
return 0;
}
}
Here are the relevant lines:
gchar** _tmp8_ = NULL;
gsize _tmp9_ = 0;
vte_terminal_event_check_regex_simple (terminal, event, regexes, &_tmp9_, (guint32) 0, &_tmp8_);
Since n_regexes
is treated as an output argument, a pointer is passed there while vte_terminal_event_check_regex_simple
expects a value. (I'm not sure how to pass that matches
argument in Vala)
There's also a gtk-rs
issue which also points out problems with this function:
https://github.com/gtk-rs/gir/issues/786
Version info
I'm using Vala 0.48.2, the latest pygobject and vte 0.60.0