Lisandro Dalcin wrote:

> > It's a bit less efficient than what I proposed, as, when an error occurs:
> >  - it restores the thread context before Pyx_CppExn2PyErr(),
> >  - saves the thread context after Pyx_CppExn2PyErr(),
> >  - restores it in the /*finally:*/ block.
> > whereas what I proposed only restores once the context (before 
> > Pyx_CppExn2PyErr(), skipped in the
> > /*finally:*/ block).
> 
> Indeed (but only when an error occurs)... However, I'm a bit confused:
> Is my added restore in the finally block actually necessary?

Yes, to re-acquire the GIL.

> Is you
> original implementation correct if you do not restore in the finally
> block?

You need to restore in case you reach this block through the normal flow (no 
exceptions).

Note that you can restore at the end of the /*try:*/ block, instead of in the 
/*finally:*/ block:

  { PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {
      try {foo();} catch(...) {Py_BLOCK_THREADS __Pyx_CppExn2PyErr(); 
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto 
__pyx_L6;}}
      Py_BLOCK_THREADS
    }
    /*finally:*/ {
      int __pyx_why;
      __pyx_why = 0; goto __pyx_L7;
      __pyx_L6: __pyx_why = 4; goto __pyx_L7;
      __pyx_L7:;
      switch (__pyx_why) {
        case 4: goto __pyx_L1_error;
      }
    }
  }

(it's exactly equivalent to my original proposal, but maybe cleaner that way...)

> >
> > But do we have to really care of performance when an error occurs?
> >
> 
> I do not advocate using exceptions for control flow (though I do it in
> a few cases), so I do not care about performance in this case.

Fine.

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

Reply via email to