On 7 August 2012 10:53, Stefan Behnel <stefan...@behnel.de> wrote:
> Hi,
>
> given how ubiquitous manual memory management is in C, I think it would be
> nice to let Cython generate the exception raising also for C, not only for
> C++. The difference is this:
>
>   cdef extern from "...":
>       char* make_new_buffer() except NULL as MemoryError
>       int append_to_buffer(char* buffer, char* value) \
>                                      except -1 as MemoryError
>
>   c_buffer = make_new_buffer()           # raises MemoryError on NULL
>   append_to_buffer(c_buffer, "testdata") # raises MemoryError on -1
>   append_to_buffer(c_buffer, "moredata") # raises MemoryError on -1
>
> versus this:
>
>    cdef extern from "...":
>        char* make_new_buffer()
>        int append_to_buffer(char* buffer, char* value)
>
>    c_buffer = make_new_buffer()
>    if c_buffer is NULL:
>        raise MemoryError()
>    if append_to_buffer(c_buffer, "testdata") == -1:
>        raise MemoryError()
>    if append_to_buffer(c_buffer, "moredata") == -1:
>        raise MemoryError()
>
> I don't think it's necessary to support this for anything but MemoryError,
> since you'd normally want a formatted error message for everything else.
>
> Alternative colours for the bike shed:
>
>     char* make_new_buffer() except NULL raise MemoryError
>
>     char* make_new_buffer() raise MemoryError for NULL
>
>     char* make_new_buffer() raise MemoryError from NULL
>
> What do you think?
>
> Stefan
> _______________________________________________
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/mailman/listinfo/cython-devel

I'd say write a wrapper function that does the check, or use an object
that encapsulates the buffer allocation and functions. I'm not sure
we'd want extra syntax for this. Calling functions is already
complicated, this will complicate it even further.
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to