[C++-sig] Re: please help with simple program crashing

Drew Ferraro gfilla at gmail.com
Thu Jul 1 19:17:54 CEST 2004


hi dave,

thanks for your reply! this might sound stupid, but could you tell me
what i should do then to have them both use the same standard library?
im using visual studio .net 2003 if that matters. also, what is the
alternative to Py_Finalize, and why is it incompatible but the other
Py_XXX function are not ? thanks for any help! ps, i have boost
included because i was just using it to do some other stuff (i was
actually able to call a C++ function through the Py_SimpleString()
function...)

On Thu, 01 Jul 2004 09:52:59 -0400, David Abrahams
<dave at boost-consulting.com> wrote:
> 
> Drew Ferraro <gfilla at gmail.com> writes:
> 
> > hi,
> >
> > ive recently trying to add a scripting system to a game i am making..
> > anyway, ive started to learn python and am trying to figure out how to
> > embed it in my game. i have gotten a C++ function to work from inside
> > C++ but called from python via PyRun_SimpleString(),,, i can send
> > commands directly to the intepreter with that function, but im having
> > a problem
> >  with PyRun_SimpleFile(). im trying to execute a python script with
> > this function, but its crashing when it gets to this line:
> >
> >  PyRun_SimpleFile(fp,"test.py");
> >
> > i cant figure out what im doing wrong. here is the source. any help is
> > greatly appreciated!!
> 
> One likely possibility is that your Python was built with a different
> C/C++ standard library than your program, so they have different
> ideas of what a FILE is supposed to be.  Also, Boost.Python is
> incompatible with Py_Finalize... though it's not clear why you're
> linking with Boost.Python anyway, since you're not using it.
> 
> > #include <boost/python.hpp>
> > #include <iostream>
> > #include <stdio.h>
> >
> >
> > using namespace std;
> > using namespace boost::python;
> >
> >
> > #ifdef _WIN32
> > #pragma comment(lib,"boost_python.lib");
> > #endif
> >
> > int main()
> > {
> >
> >    Py_Initialize();
> >
> >    FILE *fp = NULL;
> >    fp = fopen("test.py", "r");
> >
> >    if(fp == NULL)
> >         return 1;
> >
> >    PyRun_SimpleFile(fp,"test.py");
> >
> >    Py_Finalize();
> >
> >    system("PAUSE");
> >
> >    return 0;
> > }
> >
> > thanks for any help! also, i tried not opening the file myself, and
> > just sending PR_SF() a NULL FILE*... it didnt crash! instead, in the
> > console it said there was a syntax error and printed out some garbage
> > characters... i dont think theres a syntax error, "text.py" entire
> > file just says print "hello world"
> >
> > thanks again!
> 
> --
> Dave Abrahams
> Boost Consulting
> http://www.boost-consulting.com
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>




More information about the Cplusplus-sig mailing list