[Stackless] Crash after throwing C++ exception?

Richard Tew richard.m.tew at gmail.com
Sun Oct 29 14:45:26 CET 2006

On 10/29/06, Lloyd Weehuizen <lloyd at fusion.net.nz> wrote:
> I seem to have run into an issue with throwing C++ exceptions when a
> python error is encountered ( As boost::python does ). Am I wrong in
> thinking it should be safe to use exceptions with stackless?
> At this point everything appears to be ok, however if that exact same
> code is executed again, stackless crashes with a NULL pointer exception
> deep inside python.

Hi Lloyd,

Thanks for the reproducibility case.  If someone with the required
interest and skill with boost::python wants to step forward and have
a go at working out what is going wrong, I am happy to help out
to the degree which does not require me to install boost::python and
compile this myself.

However, if I had to guess at the reason for this bug.  I would say
something soft switched and the watchdog code you are using does
not handle it appropriately.

When soft switching is done, more or less what is happened is an
UnwindToken is returned and the calling C functions exit and return
it themselves until it reaches a frame dispatching function in the
Stackless code.  This unpacks the actual value in the token and
passes it into the execution of the frame that is being soft switched

My blind-hand-wavey-didn't-actually-reproduce-the-problem guess,
is therefore that the reason you are getting a NULL pointer
exception is that the frame which the dispatcher reached did
not get its accompanying UnwindToken.

And I would also blindly point my finger at the use of the channel
C API functions in Juho's code.  Having these return what
the channel C API functions return to Juho's code might fix the
problem if my guess is the cause.

e.g. See my BeNice function in the C version of the watchdog:

PyObject *BeNice(PyObject *self) {
	PyObject *ret;
	/* By using PyChannel_Receive_nr to block the current tasklet on
	   the channel, we ensure that soft switching is used (we can
	   check this by looking at what is returned and making sure it
	   is the unwind token. */
	ret = PyChannel_Receive_nr(niceChannel);
	assert(ret == (PyObject *)Py_UnwindToken);
	return ret;

Hope this is of some help at least,

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list