[C++-sig] weird runtime error I'm getting with PyRun_SimpleFile()
Blake Skinner
5p4ced0ut at gmail.com
Fri Aug 11 06:38:26 CEST 2006
Here's my C++ code, I'm building with VS 2005, under multi-threaded:
#include <Python/python.h>
#include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, char **argv)
{
Py_Initialize();
PyObject *main_module = PyImport_AddModule("__main__");
PyObject *main_dict = PyModule_GetDict(main_module);
FILE *f = fopen("test.py", "r");
PyRun_SimpleFile(f, "test.py");
if (PyDict_GetItemString(main_dict, "num") == NULL)
cout << "No" << endl;
else
cout << "Yes" << endl;
Py_Finalize();
return 0;
}
When I run it, I get an error:
Unhandled exception at 0x7c918fea in Embed_practice.exe: 0xC0000005: Access
violation writing location 0x00000010
from a file called _file.c, the debugger calls attention to this method
specificially:
/***
* _lock_file - Lock a FILE
*
*Purpose:
* Assert the lock for a stdio-level file
*
*Entry:
* pf = __piob[] entry (pointer to a FILE or _FILEX)
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
void __cdecl _lock_file (
FILE *pf
)
{
/*
* The way the FILE (pointed to by pf) is locked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= _iob) && (pf <= (&_iob[_IOB_ENTRIES-1])) )
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
*/
_lock( _STREAM_LOCKS + (int)(pf - _iob) );
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
EnterCriticalSection( &(((_FILEX *)pf)->lock) );
}
Any help solving this would be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060810/24f66e1a/attachment.htm>
More information about the Cplusplus-sig
mailing list