Skip to content

GLib: Override GLib.MatchInfo

Philip Chimento requested to merge ptomato/gjs:589-gmatchinfo into master

The introspected implementation of GLib.Regex/GLib.MatchInfo is buggy, because GLib.MatchInfo expects you to keep the string passed to match() alive. If you don't, all of its methods crash because of the dangling pointer.

This overrides GLib.MatchInfo with a reimplemented version that owns a copy of the string, and overrides all the GLib.Regex methods that return a GLib.MatchInfo to instead return the overridden one.

Special care must be taken when overriding GLib.MatchInfo because we must not introduce a circular dependency between GLib and GjsPrivate, so we have to use a weird trick with a Proxy that overwrites itself.

But don't use GLib.Regex, normally! Just use JS regular expressions instead. They'll be faster due to not calling back and forth between C and JS.

Closes: #589 (closed)

Merge request reports