Skip to content

Commit

Permalink
Fix a crash in cross-thread throw
Browse files Browse the repository at this point in the history
  • Loading branch information
snaury committed Jun 2, 2012
1 parent 486ea8d commit 85f0ab3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions greenlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ g_switch(PyGreenlet* target, PyObject* args, PyObject* kwargs)

/* check ts_current */
if (!STATE_OK) {
Py_DECREF(args);
Py_XDECREF(args);
Py_XDECREF(kwargs);
return NULL;
}
run_info = green_statedict(target);
if (run_info == NULL || run_info != ts_current->run_info) {
Py_DECREF(args);
Py_XDECREF(args);
Py_XDECREF(kwargs);
PyErr_SetString(PyExc_GreenletError, run_info
? "cannot switch to a different thread"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_greenlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,16 @@ def __getattribute__(self, name):
return greenlet.__getattribute__(self, name)
g = mygreenlet(lambda: None)
self.assertRaises(SomeError, g.throw, SomeError())

def test_throw_doesnt_crash(self):
result = []
def worker():
greenlet.getcurrent().parent.switch()
def creator():
g = greenlet(worker)
g.switch()
result.append(g)
t = threading.Thread(target=creator)
t.start()
t.join()
self.assertRaises(greenlet.error, result[0].throw, SomeError())

0 comments on commit 85f0ab3

Please sign in to comment.