Re: custom model rows-reordered marshal



Torsten Schoenfeld <kaffeetisch gmx de> writes:

In practical terms: after every XPUSHs or similar, use PUTBACK if it's
possible that some Perl code is invoked before you return from the
XSUB.

I believe in addition: and do an SPAGAIN after that perl code, because
it could move the whole stack, completely invalidating your local SP
pointer.

An all-perl failing case for that below.  Remove the grow_the_stack()
call to see it become ok.

So, I think the attached patch should do it.

Except it doesn't work!  :-)

Looking at the generated .c, the first thing PPCODE does is "SP -=
items", so in the supplied-columns case the PUTBACK sets the global
position to overwrite the "..." args yet unprocessed.

I don't see how iter_n_children is affected by this -- can you elaborate?

Umm, it's been a while.  I think it's another stack-grow SPAGAIN, like
g_object_get in other message.

Does all of the above make sense?

I guess it's not meant to be quite so difficult.  If you keep a local
copy of the pointer then you have to be careful to sync with the global
when anything might read, write or move that global.

The bit that gets me confused is which macros use or don't use the local
SP.  All the PUSH/POP use it, but XSRETURN and XST_ don't.  And PPCODE:
needs it valid at the end of your xsub, but CODE: doesn't.  Or something
like that.  :-(

Index: GtkTreeModelIface.t
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkTreeModelIface.t,v
retrieving revision 1.8
diff -u -u -r1.8 GtkTreeModelIface.t
--- GtkTreeModelIface.t 18 Aug 2008 20:28:44 -0000      1.8
+++ GtkTreeModelIface.t 25 Aug 2008 00:21:12 -0000
@@ -346,7 +346,7 @@
 
 package main;
 
-use Gtk2::TestHelper tests => 176, noinit => 1;
+use Gtk2::TestHelper tests => 177, noinit => 1;
 use strict;
 use warnings;
 
@@ -475,4 +475,36 @@
              'iter->set() from another iter');
 }
 
+package AnotherCustomList;
+use strict;
+use warnings;
+use Gtk2;
+
+use Glib::Object::Subclass
+  Glib::Object::,
+  interfaces => [ Gtk2::TreeModel:: ];
+
+sub GET_FLAGS       { return [ 'list-only' ]; }
+sub GET_N_COLUMNS   { return 1; }
+sub GET_COLUMN_TYPE { return 'Glib::Int'; }
+sub GET_ITER        { return [ 123, 0, undef, undef ]; }
+
+my @bigarray;
+for (my $i = 0; $i < 500; $i++) { $bigarray[$i] = 9; }
+sub grow_the_stack { myfunc (@bigarray); }
+sub myfunc { }
+
+sub GET_VALUE {
+  my ($self, $iter, $column) = @_;
+  grow_the_stack();
+  return 123;
+}
+
+package main;
+
+$model = AnotherCustomList->new;
+$iter = $model->get_iter_first;
+is ($model->get($iter), 123);
+
+
 # vim: set syntax=perl :

-- 
Two birds were sitting in a tree when an air force jet flew overhead low
and fast.  "Strewth, did you see that big bird, it was really moving."
The other said, "Yeah, you'd be moving too if your arse was on fire."


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