[Pyrex] Mapping a stdio-FILE to a Python-file

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Nov 18 23:51:47 CET 2003


Joachim Saul <saul at gfz-potsdam.de>:

> There is, however, a problem when I translate the
> avove (Pyrex 0.9):
> 
>     /home/saul/Python/SeisPy/MseedPy/_mseed.pyx:85:38: Expected ')'

In Pyrex you'll have to declare it as

  cdef extern from "Python.h":
    FILE* PyFile_AsFile(object)

> Also, I would have expected
> 
>     cdef FILE *p
>     p = PyFile_AsFile("dummy")
> 
> to produce some sort of an error, which it doesn't

Using the above declaration, this will pass a Python string to
PyFile_AsFile, which will produce a runtime error.

If you want to get a compile-time error for this, you'll have to
declare PyFileObject as an external extension type, as you did.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list