How to receive a FILE* from Python under MinGW?

John Pye john.pye at gmail.com
Wed Mar 21 02:07:35 EDT 2007


On Mar 21, 4:48 pm, "John Pye" <john.... at gmail.com> wrote:
>
> I am trying the following... any thoughts?
>
> %typemap(in) FILE * {
>     if (!PyFile_Check($input)) {
>         PyErr_SetString(PyExc_TypeError, "Need a file!");
>         return NULL;
>     }
> %#ifdef __MINGW32__
>         PyFileObject *fo = (PyFileObject *)$input;
>         $1 = fdopen(_fileno(fo->f_fp),PyString_AsString(fo->f_mode));
>         fprintf(stderr,"FDOPEN(%d,\"%s\")\n",fo->f_fp,PyString_AsString(fo->f_mode));
>
> %#else
>     $1 = PyFile_AsFile($input);
> %#endif
>
> }


Ok, so this didn't work. 'fdopen' returned NULL. I guess that nails
the coffin for the fileno() approach?

Cheers
JP






More information about the Python-list mailing list