467,225 Members | 1,364 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,225 developers. It's quick & easy.

Embedded and extending python 2.5: trouble with __main__ inPyRun_SimpleFileExFlags?

Hi Python fans,

I am developing a DLL that is loaded by a host application on windows.
I'm using python 2.5.

My DLL uses an embedded python interpreter which can access the host
application through an API which I have exposed using SWIG 1.3.31.

Therefore I have both extended and embedded Python at once: the SWIG
generated code is statically linked into my DLL, and one of the
functions in my DLL executes PyRun_SimpleFile.

Using python25_d.dll, I stepped through some python code to understand
what is happening, and it appears that PyRun_SimpleFile is returning
-1 because python cannot create the module __main__.

Here's the code from pythonrun.c:

PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
PyCompilerFlags *flags)
PyObject *m, *d, *v;
const char *ext;

m = PyImport_AddModule("__main__");
if (m == NULL)
return -1;

BTW, PyImport_AddModule fails because deeper down a dictionary check fails:

if (!PyDict_Check(op))
return NULL;
Can someone suggest what I need to do to get this to work?

Here are the relevant lines from my code:

if (GetOpenFileName(&ofn)==TRUE)
init_mymodule(); // SWIG generated method

PyObject* PyFileObject = PyFile_FromString(ofn.lpstrFile, "r");

if (PyRun_SimpleFile(PyFile_AsFile(PyFileObject), ofn.lpstrFile)==-1)
MessageBox(NULL, "error running script", "Python", MB_ICONERROR);



Feb 19 '07 #1
  • viewed: 902

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Link | last post: by
2 posts views Thread by Rick Olson | last post: by
11 posts views Thread by Nicolas Lehuen | last post: by
reply views Thread by Richard Townsend | last post: by
1 post views Thread by Richard Townsend | last post: by
4 posts views Thread by Chris8Boyd@gmail.com | last post: by
reply views Thread by Riccardo Di Meo | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.