Problem embedding Python.

Brandon Keown keown.brandon at gmail.com
Tue Oct 27 05:36:18 EDT 2009


On Oct 27, 2:47 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
>
> Crashes, how? Try running inside a debugger to see where it crashes, or at  
> least put a few printf.
> You didn't test for the fopen result; are you sure "test.py" exists in the  
> current directory at the time you run it?
>
> --
> Gabriel Genellina

Ok, so I assumed that the file, if supplied without a path, would use
current working directory, which was evidently a false assumption.  I
put in an if statement to check to see if the pointer was null which
it was.  So I fully qualified the path in the test file.  Now it
throws an unhandled exception when it goes to execute the line with
PyRun_SimpleFile.  The following code yields the errors after it.

#include <Python.h>

int main(int argc, char* argv[])
{
	FILE* fp = fopen("c:\\Patches\\Test\\Debug\\test.py","w");
	if(fp == NULL)
		printf("error");
	Py_Initialize();
	PyRun_SimpleFile(fp,"test.py");
	Py_Finalize();
	return 0;
}

"First-chance exception at 0x77d2dbba in Test.exe: 0xC0000005: Access
violation writing location 0x00000014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC0000005: Access
violation writing location 0x00000014.
First-chance exception at 0x77d2dbba in Test.exe: 0xC0000005: Access
violation writing location 0x00000014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC0000005: Access
violation writing location 0x00000014."

In the debug output.

This is the call stack (the first line is where execution halted).

Test.exe!main(int argc=1, char** argv=0x006d1b88)  Line 9 + 0x15 bytes
Test.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes
Test.exe!mainCRTStartup()  Line 403

(There is more after this, but it goes back to system calls and
execution is halted here so I thought this was relevant).



More information about the Python-list mailing list