[perl-Gtk2] Avoid a stack handling error in Gtk2::TreeModel::get on perl >= 5.23



commit eb29c8b6faf1a1774b943405a021fdad215498ae
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Sat Nov 21 13:11:45 2015 +0100

    Avoid a stack handling error in Gtk2::TreeModel::get on perl >= 5.23

 t/GtkTreeModel.t   |   13 ++++++++++++-
 xs/GtkTreeModel.xs |   16 ++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/t/GtkTreeModel.t b/t/GtkTreeModel.t
index 05044f5..be6b522 100644
--- a/t/GtkTreeModel.t
+++ b/t/GtkTreeModel.t
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Gtk2::TestHelper tests => 74, noinit => 1;
+use Gtk2::TestHelper tests => 75, noinit => 1;
 
 # $Id$
 
@@ -210,6 +210,17 @@ foreach my $signal_name (qw/rows_reordered rows-reordered/) {
 
 ###############################################################################
 
+# Ensure that getting all values of a row in a 1-column model does not result
+# in a stack handling error with perl >= 5.23.
+{
+       my $model = Gtk2::ListStore -> new(qw/Glib::Int/);
+       my $iter = $model -> append();
+       $model -> set($iter, 0 => 23);
+       is ($model -> get($iter), 23);
+}
+
+###############################################################################
+
 __END__
 
 Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the
diff --git a/xs/GtkTreeModel.xs b/xs/GtkTreeModel.xs
index df91b35..b62801f 100644
--- a/xs/GtkTreeModel.xs
+++ b/xs/GtkTreeModel.xs
@@ -1162,13 +1162,17 @@ gtk_tree_model_get (tree_model, iter, ...)
 
                int n_columns = gtk_tree_model_get_n_columns (tree_model);
                /* extend the stack so it can handle 'n_columns' items in
-                * total.  the stack already contains 'items' elements so make
-                * room for 'n_columns - items' more, move our local stack
-                * pointer forward to the new end, and update the global stack
-                * pointer.  this way, xsubs called by gtk_tree_model_get_value
-                * don't overwrite what we put on the stack. */
+                * total.  the stack already contains 'items' elements so if
+                * 'items' < 'n_columns', make room for 'n_columns - items'
+                * more.  then move our local stack pointer forward to the new
+                * end, and update the global stack pointer.  leave 'ax'
+                * unchanged though, so that ST still refers to the start of
+                * the stack allocated to us.  this way, xsubs called by
+                * gtk_tree_model_get_value don't overwrite what we put on the
+                * stack. */
                SPAGAIN;
-               EXTEND (SP, n_columns - items);
+               if (n_columns > items)
+                       EXTEND (SP, n_columns - items);
                SP += n_columns - items;
                PUTBACK;
                for (i = 0; i < n_columns; i++) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]