[C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name?

Lawrence Spector Lawrence.Spector at CanfieldSci.com
Mon Jul 9 23:34:36 CEST 2007


Putting a breakpoint in my class, I get the 'this' inside of the instance when it's created is 0x0012ff20, but when the callMethod() is called, the 'this' is 0x00987fc8, so it appears to be a different instance.

Any idea why?  Does the constructor of boost::python::object make a copy?

Thanks,

Lawrence

-----Original Message-----
From: c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org [mailto:c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org] On Behalf Of Nat Goodspeed
Sent: Monday, July 09, 2007 5:24 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name?

> -----Original Message-----
> From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org]
On
> Behalf Of Lawrence Spector
> Sent: Monday, July 09, 2007 5:16 PM
> To: Development of Python/C++ integration
> Subject: Re: [C++-sig] When You Create an Python Object Using
> Boost.Python, How Do You Find Out Its Name?
>
> is there a way to add it to the dict without making a copy,
> but instead having foo be a reference to the instance of MyClass()?

[Nat] boost::python::object is a C++ wrapper around a classic-C Python
reference pointer. Once you've instantiated a Python-compatible object
and captured its reference pointer using boost::python::object, I would
expect you to be able to copy the boost::python::object as needed (e.g.
into a dict) with every copy of the boost::python::object value
referencing the same MyClass instance.

If that's not what you're seeing, maybe a complete, minimal code example
would help.
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig



More information about the Cplusplus-sig mailing list