Re: custom model rows-reordered marshal



Kevin Ryde wrote:
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.

Ah, I didn't think of the possibility that the whole stack might be moved.  And
strangely enough, it doesn't seem to happen for me.  Your test case passes for
me with only PUTBACK and no SPAGAIN, even when I increase the artificial stack
size from 500 to 500000.  But I see why it might fail: when the requested stack
size exceeds the size currently allocated, perl calls something like realloc()
which might move the whole block.

So I applied your patch.  Thanks!

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.

I think the iter_n_children case was fixed by moving the code that might end up
overwriting the stack above the code that modifies the local stack pointer.

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.

Yeah.  The new rule of thumb then seems to be: if there is a chance that someone
might overwrite the stack before you return from the xsub, call SPAGAIN before
and PUTBACK after any code that modifies the local stack pointer.

-- 



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