[C++-sig] Re: embedding examples

Joel de Guzman joel at boost-consulting.com
Mon Mar 1 14:34:47 CET 2004


David Abrahams wrote:

> Ingo Luetkebohle <ingo at fargonauten.de> writes:
> 
> 
>>Hi,
>>
>>I have trouble compiling the 'Using the interpreter' examples from the
>>tutorial.
>>
>>Code like this:
>>  handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
>>  dict main_namespace(handle<>(borrowed(
>>PyModule_GetDict(main_module.get()) )));
>>results in 
>>  error: variable declaration is not allowed here
>>
>>using gcc 3.2 and gcc 3.3 on Linux.
>>
>>When I use
>>  handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
>>  handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) ));
>>  dict main_namespace(main_nsh);
>>
>>it compiles and the resulting dict is usable.
>>
>>So, this is not a showstopper but it doesn't work as documented and
>>results in longer code.  Is there anything I can do to get the intended
>>behaviour?
> 
> 
> [joel, can you fix this?]
> 
> I think this will work.  Please let us know if it doesn't:
> 
>     // Retrieve the main module
>     object main_module = python::extract<python::object>(
>         PyImport_AddModule("__main__")
>     );
>     
>     // Retrieve the main module's namespace
>     dict main_namespace(
>          extract<dict>(main_module.attr("__dict__"))
>     );

I think Dirk Gerrits is the authority here. He's the author of that
part of the tutorial. Dirk?

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net




More information about the Cplusplus-sig mailing list