I'm looking at implementing your suggestion in a branch that Thomas (the OP) started. It looks like Cython doesn't like any syntax with "except X" in it when it comes to ctypedef or casting. For example, we have:
cdef herr_t H5FD_fileobj_flush(H5FD_fileobj_t *f, hid_t dxpl, hbool_t closing) except -1 with gil:
# TODO: avoid unneeded fileobj.flush() when closing for e.g. TemporaryFile
(<object>f.fileobj).flush()
return 0
Then from your suggestion:
ctypedef herr_t (*fileflush_ptr)(H5FD_t *, hid_t, hbool_t) except -1
and:
info.flush = <fileflush_ptr>H5FD_fileobj_flush
But then cythonizing gives:
info.flush = <fileflush_ptr>H5FD_fileobj_flush
^
------------------------------------------------------------
h5py/h5fd.pyx:213:13: Cannot assign type 'fileflush_ptr' to 'herr_t (*)(H5FD_t *, hid_t, hbool_t) noexcept'. Exception values are incompatible. Suggest adding 'noexcept' to type 'herr_t (H5FD_t *, hid_t, hbool_t) except -1'.
I read this as Cython not recognizing "except -1" as an except clause since it is suggesting adding "noexcept" to it.
Am I missing something?
Dave