[Swig-user] How to prevent std::string from converting to python unicode string?

22 views
Skip to first unread message

Bob Rossi

unread,
Mar 20, 2012, 8:36:48 PM3/20/12
to swig...@lists.sourceforge.net
Hi,

In general, I love that std::string converts to a unicode
string in python. However, sometimes this is WRONG.

I've got an std::string that has arbitrary data in it.
It is converted in swig through this call chain:
- resultobj = SWIG_From_std_string(static_cast<std::string>(*result));
- return SWIG_FromCharPtrAndSize(s.data(), s.size());
- #if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromStringAndSize(carray, static_cast< int >(size));
#else
return PyString_FromStringAndSize(carray, static_cast< int >(size));
#endif

The problem is, in my case, with arbitrary data, this is a hard error
in python. Since the utf8 encoding/decoding fails.

Is there a nice way to disable this and simply convert to a python
string for a particular std::string member?

Thanks,
Bob

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Swig-user mailing list
Swig...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Reply all
Reply to author
Forward
0 new messages