[C++-sig] Re: C++ object from PyObject pointer
David Abrahams
dave at boost-consulting.com
Mon Feb 24 23:03:23 CET 2003
The following message is a courtesy copy of an article
that has been posted to gmane.comp.lib.boost.user as well.
"mghiggins <mghiggins at yahoo.com>" <mghiggins at yahoo.com> writes:
> Excuse my newbiness if this question is too dumb... :)
>
> I've built a python extension from a C++ class using boost - it all
> seems to work fine.
>
> However, now another C++ function is receiving a pointer to a PyObject
> that represents an instance of this "boosted" python class. How do I
> pick off a pointer to the underlying C++ object from the PyObject
> pointer?
Boost.Python questions to the c++-sig, please!
http://www.python.org/sigs/c++-sig/
Your answer:
void f(PyObject* p)
{
handle<> ph(borrowed(p));
MyObj* op = extract<MyObj*>(object(ph));
}
HTH,
Dave
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list