Hi,

Am 06/27/2008 05:55 PM schrieb Robert Bradshaw:
> On Jun 27, 2008, at 6:43 AM, Johannes Wienke wrote:
>> I've got the following problem:
>> There is client code of my application that is already written and
>> cotains so lines of code like these ones:
>>
>> void foo(int c) {
>>
>>     if (c < 5) {
>>         gui_exit(1)
>>     }
>>
>>     // do some other things that fail if c is < 5
>>
>> }
>>
>> I am the one who has to implement gui_exit, which was originally a
>> wrapper for the normal C exit function doing some clean up.
>>
>> My first attempt to implement gui_exit in cython was using sys.exit.
>> The problem with this approach is that sys.exit depends on exceptions,
>> which are only checked after the client routine is completely
>> processed. So foo does not exit at gui_exit and possibly generates a
>> segmentation fault in the other things it does.
>>
>> Is there a solution for this problem, that uses the python exit
>> mechanism? I need that to clean up resources.
>
> Try
> 
> 
> void foo(int c) {
> 
>     if (c < 5) {
>         gui_exit(1)
>     }
> 
>     else {
> 
>     // do some other things that fail if c is < 5
> 
>     }
> 
> }

I can't change the client code. The original sematics of gui_exit was
that it terminates the programm at that point, so I have to preserve
this functionality in my implementation of gui_exit.

> Also, look at the exception passing mechanisms at
> http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/basics.html#mozTocId482761

Well, the problem I see here, is that the caller of gui_exit is not a
python function, but a real C function in a shared library I call.

Johannes

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to