How to receive a FILE* from Python under MinGW?
John Pye
john.pye at gmail.com
Wed Mar 21 01:48:47 EDT 2007
On Mar 21, 4:04 pm, Ross Ridge <rri... at caffeine.csclub.uwaterloo.ca>
wrote:
> Gabriel Genellina <gagsl-... at yahoo.com.ar> wrote:
> >You can get the file descriptor from the Python file object using its
> >fileno() method. The file descriptor lives at the OS level, so it's safe
> >to pass around.
>
> Not under Windows. Windows doesn't have Unix-like descriptors, so the
> C runtime emulates them.
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
}
More information about the Python-list
mailing list