[C++-sig] missing to_python converter for wchar_t

progetto dex progettodex at gmail.com
Fri Feb 1 08:59:05 CET 2008


Thanks for the response,
but the trick did not work on the sample code.
Anyway, I cannot change the original interface I'm wrapping since it's a
third party library.

Regards,
Dex

2008/1/31, Roman Yakovenko <roman.yakovenko at gmail.com>:
>
> 2008/1/31 progetto dex <progettodex at gmail.com>:
> > Hi all,
> > it seems that I'm facing a well-known problem (I've found some messages
> > dated 2006 or earlier), but maybe in the near past something has
> changed...
> >
> > I'm wrapping a third party API that uses "const wchar_t* const"
> arguments,
> > and Python says that a converter is missing.
> >  Before creating a layer to convert from/to std::wstring, I post a
> stripped
> > down example. First, the C++ stuff:
> >
> > // C++
> > #include <boost/python.hpp>
> >
> > using namespace boost::python;
> >
> > class Receiver
> >  {
> > public:
> >     virtual void Receive(const wchar_t* const message) { }
> > };
> >
> > class Sender
> > {
> >     Receiver& receiver;
> >
> > public:
> >     Sender(Receiver& r) : receiver(r) { }
> >     void Send() { receiver.Receive(L"test message"); }
> >  };
> >
> > struct PyReceiver : Receiver
> > {
> >     PyObject* self;
> >     PyReceiver(PyObject* s) : self(s) { }
> >
> >     void Receive(const wchar_t* const message)
> >         { return call_method<void>(self, "Receive", message); }
> >
> >     void Receive_default(const wchar_t* const message)
> >         { return this->Receiver::Receive(message); }
> > };
> >
> > BOOST_PYTHON_MODULE(MyModule)
> > {
> >     class_<Receiver, PyReceiver, boost::noncopyable>("Receiver")
> >          .def("Receive", &Receiver::Receive,
> &PyReceiver::Receive_default)
> >     ;
> >
> >     class_<Sender, boost::noncopyable>("Sender", init<Receiver&>())
> >         .def("Send", &Sender::Send)
> >      ;
> > }
> >
> > Now, a trivial Python test case:
> >
> > #python
> > import MyModule
> >
> > class Receiver(MyModule.Receiver):
> >     def Receive (self, msg):
> >         print "MSG: " + msg
> >
> > r = Receiver()
> >  s = MyModule.Sender(r)
> > s.Send()
> >
> > If I supply a to_python wchar_t converter, only the first letter of the
> > message is printed.
> > I'm I missing something?
>
> Untested: I think that replacing "const wchar_t* const" with "const
> wchar_t* " should work.
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080201/bac4061c/attachment.htm>


More information about the Cplusplus-sig mailing list