Boost logo

Boost :

Subject: Re: [boost] [python] Setting a pointer into an object
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-30 16:14:47


on Tue Sep 30 2008, "Robert Dailey" <rcdailey-AT-gmail.com> wrote:

> Hi,
>
> I am trying to do the following:
>
> SomeClassOfMine* myInstance; // Assume valid pointer
> boost::python::object myObject( myInstance );
>
> However, doing so causes an exception to be thrown when I run my
> application. The exception thrown is below (Note I'm using MSVC9):
>
> First-chance exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft
> C++ exception: boost::python::error_already_set at memory location
> 0x0012f0cc..
> Unhandled exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft C++
> exception: boost::python::error_already_set at memory location
> 0x0012f0cc..
>
>
> How can I assign the pointer above to a boost::python::object? I'm
> trying to give my python scripts access to an instance of a class that
> I haven't really exposed to Python yet, so I'm not sure of the
> consequences of that. I was going to extend the SomeClassOfMine class
> to python later on after I verify that I can get this working. Once I
> have myObject in a valid state, I will insert it into the __main__'s
> __dict__ namespace for a specific module so that it has access to it
> as a global python variable. Help is appreciated.

Just wrap the class without exposing any of its interesting parts and
you should be fine:

    class_<SomeClassOfMine>("SomeClassOfMine");

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk