Embedded Python 1.5.1 crashes under WIN32

Sven Havemann s.havemann at tu-bs.de
Wed Nov 17 13:42:03 EST 1999


Hi!
===

I've modified the example from Python-1.5.1/Demo/embed: 

ftp://ftp.cg.cs.tu-bs.de/pub/cg/people/havemann/embeddedPython.tgz

What I want to do is to call PyRun_SimpleFile from my main program. This
works fine under Irix 6.5, but the same thing crashes inside
PyRun_SimpleFile when compiled with VC6.0SP2 under Win32, which is a
great pity. I have attached the demo.cpp file, and the complete
(compiled) project is in the tarfile above. Does anybody know why it
crashes??? 

I wanted to build it as a plain Win32 console application, and I've
renamed it to demo.cpp because I wanted it to be compiled as a C++ file. 

I'd appreciate if you could Re: to me directly using the email below,
because I can't follow the news regularly.

TIA, greetings, Sven.

--
__________________________________________________________________
 dipl-inform. Sven Havemann        Institut fuer ComputerGraphik
 Odastrasse 6                      Rebenring 18
 38122 Braunschweig - Germany      38106 Braunschweig - Germany
 Tel. 0531/2808955                 Tel. 0531/391-2108, Fax: -2103
 mailto:s.havemann at tu-bs.de        http://www.cg.cs.tu-bs.de


=========================demo.cpp==================================
#include <stdio.h>
#include "Python.h"

// #define SHOWPYFILE

static char *argv0;

void initxyzzy(); /* Forward */

int main(int argc, char ** argv)
{
   argv0 = argv[0];
   Py_Initialize();

   initxyzzy();

   PySys_SetArgv(argc, argv);

   printf("Hello, brave new world\n\n");

   PyRun_SimpleString("import sys\n");
   PyRun_SimpleString("print sys.builtin_module_names\n");
   PyRun_SimpleString("print sys.modules.keys()\n");
   PyRun_SimpleString("print sys.argv\n");

   char* filename="test.py";
   FILE* myfile=fopen(filename,"r");
#ifdef SHOWPYFILE
   char line[200];
   printf("Reading file %s\n",filename);
   while(fgets(line,200,myfile)!=NULL) {
      printf("Read: %s",line);
   }
#else
   PyRun_SimpleFile(myfile,filename);
#endif
   fclose(myfile);

   printf("\nGoodbye, cruel world\n");

   Py_Exit(0);
   return 0;
}

char *getprogramname()
{
        return argv0;
}

/* A static module */

PyObject *xyzzy_foo(PyObject *self, PyObject *args)
{
        if (!PyArg_ParseTuple(args, ""))
                return NULL;
        return PyInt_FromLong(42L);
}

PyMethodDef xyzzy_methods[] = {
        {"foo",         xyzzy_foo,      1},
        {NULL,          NULL}           /* sentinel */
};

void initxyzzy()
{
        PyImport_AddModule("xyzzy");
        Py_InitModule("xyzzy", xyzzy_methods);
}
==================test.py======================================
print "this is from PyRun_SimpleFile"
for i in range(100): print i*i,
==================OUTPUT IRIX==================================
Hello, brave new world

('__builtin__', '__main__', 'array', 'fast_umath', 'imp', 'marshal',
'math', 'operator', 'posix', 'signal', 'strop', 'struct', 'sys',
'umath')
['xyzzy', 'os', 'exceptions', '__main__', 'posix', 'sys', '__builtin__',
'site', 'signal', 'UserDict', 'posixpath', 'stat']
['./demo']
this is from PyRun_SimpleFile
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
441 484 529 576 625 676 729 784 841 900 961 1024 1089 1156 1225 1296
1369 1444 1521 1600 1681 1764 1849 1936 2025 2116 2209 2304 2401 2500
2601 2704 2809 2916 3025 3136 3249 3364 3481 3600 3721 3844 3969 4096
4225 4356 4489 4624 4761 4900 5041 5184 5329 5476 5625 5776 5929 6084
6241 6400 6561 6724 6889 7056 7225 7396 7569 7744 7921 8100 8281 8464
8649 8836 9025 9216 9409 9604 9801

Goodbye, cruel world
==================OUTPUT WIN32==================================
-- Hello, brave new world

('__builtin__', '__main__', '_socket', 'array', 'binascii', 'cPickle',
'cStringI
O', 'cmath', 'errno', 'imageop', 'imp', 'marshal', 'math', 'md5',
'msvcrt', 'new
', 'nt', 'operator', 'pcre', 'regex', 'rgbimg', 'rotor', 'select',
'signal', 'so
undex', 'strop', 'struct', 'sys', 'thread', 'time')
['xyzzy', 'os', 'exceptions', '__main__', 'ntpath', 'strop', 'nt',
'sys', '__bui
ltin__', 'site', 'signal', 'UserDict', 'string', 'stat']
['T:\\WORK\\HAVEMANN\\SW\\PYTHON-1.5.1\\DEMO\\EMBED\\VC60.exe']
=====================** CRASH **================================
================================================================
__________________________________________________________________
 dipl-inform. Sven Havemann        Institut fuer ComputerGraphik
 Odastrasse 6                      Rebenring 18
 38122 Braunschweig - Germany      38106 Braunschweig - Germany
 Tel. 0531/2808955                 Tel. 0531/391-2108, Fax: -2103
 mailto:s.havemann at tu-bs.de        http://www.cg.cs.tu-bs.de




More information about the Python-list mailing list