GNOME Bugzilla – Bug 704143
Crash when using both object-oriented and Exporter-based modules in a Gtk3-Perl program
Last modified: 2013-09-24 17:41:48 UTC
The example code below makes perl 5.16 dump core, and 5.18 die with this error: Can't call method "export" on an undefined value at /usr/lib/perl5/current/Exporter/Heavy.pm line 214. BEGIN failed--compilation aborted at Utils.pm line 4. Compilation failed in require at MainWindow.pm line 6. BEGIN failed--compilation aborted at MainWindow.pm line 6. Compilation failed in require at ./example.pl line 5. BEGIN failed--compilation aborted at ./example.pl line 5. If I use only object-oriented or only Exporter-based modules, then it works and does not crash. Mixing both types triggers the bug. Gtk2 version of the programs also works correctly in any case. example.pl: #!/usr/bin/perl -w use strict; use Gtk3 '-init'; use MainWindow; my $window = MainWindow->new(); $window->show_all(); Gtk3->main(); MainWindow.pm: package MainWindow; use strict; use Gtk3; use parent -norequire, 'Gtk3::Window'; use Utils; sub new { my($class) = @_; my $self = bless Gtk3::Window->new('toplevel'), $class; $self->add(entry_with_clear_button()); $self->set_title('Gtk3-Perl Bug Example'); $self->signal_connect(delete_event => sub { Gtk3->main_quit(); }); return $self; } 1; Utils.pm: package Utils; use strict; use Gtk3; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(entry_with_clear_button); sub entry_with_clear_button { my $entry = Gtk3::Entry->new(); $entry->set_icon_from_stock('secondary', 'gtk-clear'); $entry->set_icon_activatable('secondary', 1); $entry->signal_connect(icon_release => \&clear_entry); return $entry; } sub clear_entry { my($self, $pos, $event) = @_; if($pos eq 'secondary') { $self->set_text(''); } } 1;
Created attachment 249139 [details] [review] Avoid memory corruption when registering boxed synonyms repeatedly
This appears to be due to a memory-corrupting bug in Glib. It doesn't seem to be related to Exporter; all you need is three imports of Gtk3: #!/usr/bin/perl package Bla; use Gtk3; package BlaBla; use Gtk3; package main; use Gtk3; The above patch should fix the issue; please try it.
The patch appears to work. Thank you!
Attachment 249139 [details] pushed as cda1f5a - Avoid memory corruption when registering boxed synonyms repeatedly