Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embedded Python 3 porting issues when passing FILE* to PyRun_SimpleFile() in Windows mixed-compiler environment

28 views
Skip to first unread message

Deron Meranda

unread,
Oct 5, 2012, 12:13:17 AM10/5/12
to
Hi. I'm trying to convert a large C application that embeds Python so it works with Python 3, and am running into an new API limitation I can't solve. I have a report from Windows users that there is a crashing problem occurring with calls to PyRun_SimpleFile (and similar functions). This appears to happen when people are using a Python DLL compiled with one compiler (e.g., MicroSoft's) and the application with another compiler (e.g., MinGW/gcc).

The basic problem is that C type (FILE*) is not defined by the Windows OS, but instead is specific to the compiler and its associated runtime-environment. So therefore it is not safe to pass a FILE* across DLL boundaries. However many of the Python C API functions only accept a FILE*.

Under Python 2 a work-around was used by calling the PyFile_FromString() then PyFile_AsFile(), to effectively get the underlying fopen() to occur inside the Python DLL so that an incompatible FILE* is not passed across the DLL boundary.

However many of those PyFile functions, including PyFile_FromFile(), were removed from the Python 3 API. So how can one safely call PyRun_SimpleFile() in Python 3 in Windows where different compilers could be used?

Thanks
--
Deron Meranda
http://deron.meranda.us/
0 new messages