[C++-sig] Re: iterate through boot::python::list
harold fellermann
harold at imb-jena.de
Wed Mar 12 16:32:49 CET 2003
On Dienstag, März 11, 2003, at 04:39 Uhr, David Abrahams wrote:
> Dirk Gerrits <dirk at gerrits.homeip.net> writes:
>> As Dave mentioned, you need to use x.attr("__len__")(). Notice the
>> *additional* pair of braces.
>
> True, but that result is just an 'object'. He needs
> extract<std::size_t>(x.attr("__len__")()) to get a size_t out of it.
Thank you, this works fine. But I still cannot get along with my
stuff...
My plan is to insert references to C++ objects within a
boost::python::list.
The code looks like the following:
class X {
// ...
};
class Y {
public:
void insert(X &);
boost::python::list xlist;
};
void Y::insert(X &x) {
// do some other things
xlist.insert(0,x)
}
int main() {
X x; Y y;
y.insert(x);
}
Unfortunately this little snippet crashes:
Program received signal SIGABRT, Aborted.
[Switching to Thread 1024 (LWP 26257)]
0x401a6df1 in kill () from /lib/libc.so.6
(gdb) bt
#0 0x401a6df1 in kill () from /lib/libc.so.6
#1 0x4008f06d in pthread_kill () from /lib/libpthread.so.0
#2 0x4008f5eb in raise () from /lib/libpthread.so.0
#3 0x401a84d9 in abort () from /lib/libc.so.6
#4 0x4012a5d7 in __cxxabiv1::__terminate(void (*)()) ()
from /usr/lib/libstdc++.so.5
#5 0x4012a624 in std::terminate() () from /usr/lib/libstdc++.so.5
#6 0x4012a7a6 in __cxa_throw () from /usr/lib/libstdc++.so.5
#7 0x4004df59 in boost::python::throw_error_already_set() ()
from /usr/local/lib/libboost_python.so.1.29.0
#8 0x080e9fea in
boost::python::converter::arg_to_python<Node>::arg_to_python(Node
const&) ()
#9 0x080e8c41 in _object*
boost::python::api::object_initializer<false, false>::get<Node>(Node
const*, int*) ()
#10 0x080e777c in boost::python::api::object::object<Node>(Node const&)
()
#11 0x080e748d in void boost::python::list::insert<Node>(int, Node
const&) ()
#12 0x080e63cf in Network::add_node(Node&) ()
#13 0x080e2858 in DynamicNetwork::add_node(DynamicNode&) ()
#14 0x080e1e81 in main ()
#15 0x401954a2 in __libc_start_main () from /lib/libc.so.6
What am I doing wrong this time?
My general ambition is to reimplement some classes originally written
in python.
So my intention is not to not intrude the underlying C++-classes, but
rather to not
intrude the overlying python-classes. This is why I need a
boost::python::list
as a public member of some C++ classes. The references inside the list
must be
accessible from either python and C++. Do you think this approach is
passable with
boost::python or is this a misuse of the library?
thank you,
- harold -
--
Live in a world of your own.
But always welcome visitors.
--
More information about the Cplusplus-sig
mailing list