[C++-sig] weird runtime error I'm getting with PyRun_SimpleFile()

Stefan Seefeld seefeld at sympatico.ca
Fri Aug 11 09:18:56 CEST 2006


Blake Skinner wrote:
> Here's my C++ code, I'm building with VS 2005, under multi-threaded:
> 
> #include <Python/python.h>
> #include <iostream>
> #include <cstdio>
> using namespace std;

Please note that this list is about the python<->C++ integration
provided by boost.python, not any language binding (even though the
list name may suggest something else).


> 
> int main(int argc, char **argv)
> {
>    Py_Initialize();
> 
>    PyObject *main_module = PyImport_AddModule("__main__");
>    PyObject *main_dict = PyModule_GetDict(main_module);
> 
>    FILE *f = fopen("test.py", "r");
>    PyRun_SimpleFile(f, "test.py");
> 
>    if (PyDict_GetItemString(main_dict, "num") == NULL)
>        cout << "No" << endl;
>    else
>        cout << "Yes" << endl;
> 
>    Py_Finalize();
>    return 0;
> 
> }
> 
> When I run it, I get an error:
> 
> Unhandled exception at 0x7c918fea in Embed_practice.exe: 0xC0000005: Access
> violation writing location 0x00000010
> 
> from a file called _file.c, the debugger calls attention to this method
> specificially:

This sounds as if the definition of the FILE structure as seen by your
compiler isn't the same that was seen during compilation of the python support
library, resulting in an ABI incompatibility.
Make sure you use the same compiler for both, or avoid the explicit use
of FILE in your code (using PyFile_FromString and PyFile_FromString instead).

HTH,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list