- if (PyUnicode_Check(source)) {
- target = new wxString();
- size_t len = PyUnicode_GET_SIZE(source);
- if (len) {
- PyUnicode_AsWideChar((PyUnicodeObject*)source, target->GetWriteBuf(len), len);
- target->UngetWriteBuf();
- }
- } else {
- // It is a string, get pointers to it and transform to unicode
- char* tmpPtr; int tmpSize;
- PyString_AsStringAndSize(source, &tmpPtr, &tmpSize);
- target = new wxString(tmpPtr, *wxConvCurrent, tmpSize);
+ PyObject* uni = source;
+ if (PyString_Check(source)) {
+ uni = PyUnicode_FromEncodedObject(source, wxPyDefaultEncoding, "strict");
+ if (PyErr_Occurred()) return NULL;