[Pyrex] ability to return NULL from a def function

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jan 30 02:39:29 CET 2005


sjmachin at lexicon.net wrote:
> Consider this:
> 
> cdef extern from "python.h":
>     int Py_XXX(int arg1) except -1
> 
> def myfunc():
>     # acquire bags of resources, create reference cycles, call malloc(), whatever
>     answer = PyXXX(something)
>    # failure means no chance to clean up

Not true! Think Pythonically:

    def myfunc():
       ...
       try:
          answer = PyXXX(something)
       finally:
          # clean up after failire

--
Greg




More information about the Pyrex mailing list