[C++-sig] Re: boost:python:embedding

Dirk Gerrits dirk at gerrits.homeip.net
Sat May 3 18:46:24 CEST 2003

Dirk Gerrits wrote:
> Dirk Gerrits wrote:
>  >
>> ... but I personally use a home-made
>> boost::python::interpreter class. (See attachments.) I would really 
>> love to see it in Boost.Python but perhaps it is not "up to Boost 
>> standards" at this point? 
> Hmm, a bit of an understatement. The execfile code is giving me access 
> violations. I'll look into it.

Okay, this seems to fix it:

void interpreter::execfile(char const* filename, dict& globals, dict& 
     FILE* file = 0;

     handle<> py_file(allow_null( PyFile_FromString(filename, "r") ));
     if (py_file)
         file = PyFile_AsFile(py_file.get());
     if (!file)
         throw std::runtime_error("Failed to open file: " + 
     handle<> result(
         PyRun_File(file, filename, Py_file_input, globals.ptr(), 
locals.ptr()) );

Apparently, my C library is incompatible with the one my Python 
installation was built with.

Anyway, it would be nice if this sort of low-level stuff was a part of 
Boost.Python, so that I wouldn't have to make a fool of myself by 
getting it wrong and posting about it. ;)

Dirk Gerrits

More information about the Cplusplus-sig mailing list