Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Crash in PyStackless_kill_tasks_with_stacks #80

Closed
ghost opened this issue May 21, 2016 · 5 comments
Closed

Crash in PyStackless_kill_tasks_with_stacks #80

ghost opened this issue May 21, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented May 21, 2016

Originally reported by: Masamitsu Murase (Bitbucket: masamitsu_murase, GitHub: masamitsu-murase)


2.7.9-slp causes a crash with the following script in PyStackless_kill_tasks_with_stacks:

#!python

import stackless

def func(ch):
    def comp(a, b):
        print("comp: (%d, %d)" % (a, b))
        ch.receive()
        return a - b

    list = [ 1, 4, 2, 3 ]
    sorted(list, cmp=comp)

channel = stackless.channel()
task = stackless.tasklet(func)(channel)
stackless.run()
channel.send(None)

This crash occurs after Issue #60 was fixed by the pull request #14.

The following is the temporary patch for this issue.
The beginning of slp_cstack_new function in stacklesseval.c should be:

#!c

    ts = NULL;
    if (task && task->cstate)
        ts = task->cstate->tstate;
    if (ts == NULL)
        ts = PyThreadState_GET();

instead of:

#!c

    if (task && task->cstate) {
        ts = task->cstate->tstate;
        assert(ts);
    } else
        ts = PyThreadState_GET();

I replicated this issue with the binary built with Visual C++ 2008 Express Edition on Windows10.


@ghost
Copy link
Author

ghost commented Aug 16, 2016

Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis):


I'm able to reproduce the crash.

@ghost
Copy link
Author

ghost commented Aug 16, 2016

Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis):


I was able to simplify the test case

#!python
from __future__ import print_function
import stackless

def func():
    global channel
    assert stackless.current.nesting_level == 0
    assert apply(lambda : stackless.current.nesting_level) == 1, "apply does not recurse"
    # apply(channel.receive)  # crash at nesting level 1
    apply(channel.send, (None,))  # crash at nesting level 1
    print("OK")

channel = stackless.channel()
task = stackless.tasklet().bind(func, ())  # simplest tasklet
task.run()

Adding a sys.exitfunc avoids the crash.

@ghost
Copy link
Author

ghost commented Aug 21, 2016

Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis):


I just committed a test case and the fix proposed by Masamitsu Murase to 2.7-slp. See 655f2a2292a2.

@ghost
Copy link
Author

ghost commented Aug 21, 2016

Original comment by Masamitsu Murase (Bitbucket: masamitsu_murase, GitHub: masamitsu-murase):


Thank you so much!
Now I can enjoy Stackless Python on EFI Shell ;-)

Regards,
Murase

@ghost
Copy link
Author

ghost commented Nov 10, 2016

Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis):


Fixed:

  • 3.3-slp: 2c9cfd572e63
  • 3.4-slp: c8fc6568196e
  • default-slp: 0143b05144b3

@ghost ghost added this to the 3.3.7-slp milestone Sep 24, 2017
@ghost ghost closed this as completed Sep 24, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

0 participants