[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    [C++-sig] "unidentifiable C++ exception"
From:       nick.gildea () gmail ! com (Nicholas Gildea)
Date:       2004-09-18 1:27:01
Message-ID: d9e0b9920409171625290714da () mail ! gmail ! com
[Download RAW message or body]

First, sorry if this is a little off-topic, but I wasn't sure where else to ask.

I've started (trying) to use Boost.Python to embed Python in a C++
application. After managing to successfully get the "Hello World"
style example working, I've run into a problem. When I started to use
PyRun_File instead of PyRun_String, I first got an access violation
and then after some Googling saw a suggestion to use the Boost.Python
exception handling wrappers to try and solve the problem, which
generates the "unidentifiable C++ exception" error.

My code looks like the following:

#include <boost/python.hpp>
#include <stdio.h>
#include <iostream>

#pragma comment( lib, "python23.lib" )
#pragma comment( lib, "boost_python.lib" )

using namespace boost::python;

void test()
{
	handle<> mainModule( borrowed( PyImport_AddModule( "__main__" ) ) );
	handle<> mainNamespace( borrowed( PyModule_GetDict( mainModule.get() ) ) );

	const char* const path = "test.py";

	FILE* f = fopen( path, "r" );
	if( f == NULL )
	{
		std::cout << "[c++] Couldn't open file!\n";
		return;
	}

	handle<>( PyRun_File( f, path, Py_file_input, mainNamespace.get(),
mainNamespace.get() ) );

	fclose( f );
}

int main( int argc, char** argv )
{
	Py_Initialize();

	if( handle_exception( test ) )
	{
		if( PyErr_Occurred() )
		{
			PyErr_Print();
		}

		return 1;
	}

	return 0;	
}

with test.py consisting of just a print statement. I'm compiling this
using VC7.1, and using the library supplied with Python 2.3.3 and have
built boost_python.lib from boost version 1.31 (also in VC7.1).

If anyone could point me in the possible direction of my problem, or
give me tips on how to track it down, it would be very much
appreciated.

Thanks, 
Nick.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic