[C++-sig] Problem using wrapped void* in Python
Kor de Jong
k.dejong at geog.uu.nl
Fri Nov 28 11:07:00 CET 2003
Hi all,
I am trying to wrap a C struct with Boost.Python which among other
members has an opaque pointer to some data, for example:
// A class in C.
typedef struct AClass {
ENUM1 v1;
void *data;
} AClass;
// Boost.Python code to wrap AClass.
BOOST_PYTHON_MODULE(amodule)
{
enum_<ENUM1>("ENUM1")
.value("first", first)
.value("second", second)
;
class_<AClass>("AClass")
.def_readwrite("v1", &A::v1)
.def_readwrite("data", &A::data)
;
}
// Python code which uses AClass.
import amodule
var = amodule.AClass()
print var.v1
print var.data
This results in the following error message when run:
print var.data
TypeError: No to_python (by-value) converter found for C++ type: Pv
I don't want to use the value pointed to by the void pointer in Python
(which can't be done anyway I suppose), I just want to copy it around
and pass it to wrapped C functions again.
So, what I am looking for is a way to tell Boost.Python how to convert
from void* to Python and back. I have tried various things, like the
opaque_pointer_converter and the to_python_converter, but I end up with
code which I don't understand anymore and/or which doesn't compile. I
would be very grateful if one of you could provide me with a bit of code
to get me going again.
Thanks in advance!
Kor de Jong
More information about the Cplusplus-sig
mailing list