On Thu, 2013-02-28 at 15:34 +0100, Sturla Molden wrote:
> 
> This is clearly a bug in Cython. One cannot let a C++ reference
> dangle.

Hi Sturla,

Thanks for the confirmation! I had a closer look at it, and I think I
know why this happens.

My method call is actually wrapped in a try { ... } catch clause,
because I declared it as being able to throw exceptions, so the
reference can't be defined in this block, or it will not be accessible
to the outside world.

Apparently, Cython should rather do something like this instead:

    Token *__pyx_v_tok;
    Token *__pyx_t_5_p;

    try {
        Token &__pyx_t_5 = __pyx_v_self->pEngine->OStack.top();
        __pyx_t_5_p = (&__pyx_t_5);
    }
    ...

    __pyx_v_tok = __pyx_t_5_p;

I'm sorry, but I don't think that I can personally help fixing this,
because even if I manage to come up with a patch to generate
declarations inside try blocks with my non-existing knowledge of Cython
internals, this simply not gonna work.

I believe that some convention should be established regarding
references handling, i.e. stating that Cython will generate correct code
to convert them to pointers if such and such syntax is used...

Hopefully, in the mean time, there is some other solution to the problem
that I have overlooked.

Z.

-- 
Sincerely yours,
Yury V. Zaytsev


_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to