Embedded Python 3 porting issues when passing FILE* toPyRun_SimpleFile() in Windows mixed-compiler e


D

Deron Meranda

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 appearsto 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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top