Re: [patch] Do not open Python scripts twice #2 [Re: [RFC] Crash sourcing Python script on Windows]

Pedro Alves
2012-01-23T18:41:09Z

Does anyone know if there's a way to create a PyFile from an open Windows
file HANDLE (that is, an hypothetical PyFile_from_HANDLE function)?

If there is, we could do something like:

static PyObject *
PyFile_from_FILE (FILE *file, const char *filename, char *mode)
{
#ifdef _WIN32
HANDLE h = _get_osfhandle (fileno (file));
return PyFile_from_HANDLE (h, ...);
#else
return PyFile_FromFile(file, filename, mode, ...);
}

Unlike libc objects, HANDLEs are common to all loaded libcs, given
that they live in the common Win32/NT layer beneath libc, so that
would work around the multiple libc's problem, and, would plug the
race on Windows too.

_get_osfhandle:
http://msdn.microsoft.com/en-us/library/ks2530z6.aspx

--
Pedro Alves