PyRun_SimpleFile crashing under Windows 2000

quadric at primenet.com quadric at primenet.com
Sun Jun 1 21:50:47 EDT 2003


Hi,

I have embedded Python in an application and am wanting to run a startup script
when the application starts.  I am running under Windows 2000 Pro, 
compiling with MSVC 6.0
and using same compiler switches and libraries as the python22.dll was 
created with.

Python initializes fine and I can run simple strings and get results back.

When I execute the following code,  I crash with a fatal "memory can't be 
written" error.

Here is the code:


int PythonStartup()
{
	int ret = 0;

	char * startup = Py_GETENV("PYTHONSTARTUP");

	if (startup != NULL && startup[0] != '\0')
	{
		FILE *fp = fopen(startup, "r");
	
		if (fp != NULL)
		{
			(void) PyRun_SimpleFile(fp, startup);
			PyErr_Clear();
			fclose(fp);
		}
		else
		{
			fprintf(stdout , "Can't open %s. Critical macro support data not 
available!\n" , startup );
		}
	}
	else
	{
		fprintf(stdout , "PYTHONSTARTUP is not specified. Critical macro support 
data not available!\n" );
	}

     return ret;
}




The PYTHONSTARTUP variable contains a fully qualified path and file similar 
to  => 
f:\some_directory\some_sub_directory\another_sub_directory\file_name.py.

Also, the script file is a text file, not byte compiled and contains some 
simple import statements etc....


I have run the app thru the debugger and determined that the failure is at 
the      PyRun_SimpleFile(fp, startup);    call but have
not attempted to debug into the python source to see where it fails.

I was hoping someone on the list has had this problem and could save me 
some grief.

Anyone had this same problem?  If so, any help would be appreciated.

Thanks.
















More information about the Python-list mailing list