[Stackless] Stackless crash
Jeff Senn
senn at maya.com
Fri Jun 30 15:40:25 CEST 2006
Richard Tew wrote:
> On 6/19/06, Jeff Senn <senn at maya.com> wrote:
>> This (tiny bit of) code causes stackless crash on OS-X.
...
> Or a channel being garbage collected. Looks like a straightforward
> fix, the channel needs to hold a reference to itself while there are
> tasklets
> blocked on it.
>
> Care to provide a patch for this one? :)
Hm... I see... seems a little "wrong" for the channel to hold a reference
to itself (but I really unsure how to the do the opposite: have the tasklet
hold the reference to the channel) and other things sometimes *seem* wrong
about stackless too :-) :-)
The patch is pretty easy (included below), but I'm not *certain* it doesn't
change some basic refcnt assumption somewhere...
-Jas
Index: Stackless/module/channelobject.c
===================================================================
--- Stackless/module/channelobject.c (revision 47111)
+++ Stackless/module/channelobject.c (working copy)
@@ -64,6 +64,7 @@
slp_channel_insert(PyChannelObject *channel, PyTaskletObject *task, int dir)
{
SLP_HEADCHAIN_INSERT(PyTaskletObject, channel, task, next, prev);
+ if(!channel->balance) Py_INCREF(channel); /*add a reference to myself
while there is a balance*/
channel->balance += dir;
task->flags.blocked = dir;
}
@@ -76,6 +77,7 @@
assert(PyTasklet_Check(ret));
channel->balance -= dir;
+ if(!channel->balance) Py_DECREF(channel); /*remove the extra self
reference when balance falls to 0*/
SLP_HEADCHAIN_REMOVE(ret, next, prev);
ret->flags.blocked = 0;
return ret;
@@ -91,6 +93,7 @@
assert(PyTasklet_Check(task));
channel->balance -= dir;
+ if(!channel->balance) Py_DECREF(channel); /*remove the extra self
reference when balance falls to 0*/
SLP_HEADCHAIN_REMOVE(task, next, prev);
task->flags.blocked = 0;
return task;
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list