Automatically coerce python 2.x unicode objects into UTF8 when passing to underlying code.
This commit is contained in:
parent
0ae5bfa6e2
commit
edd36b28d2
1 changed files with 18 additions and 0 deletions
|
|
@ -63,6 +63,24 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
|||
%#endif
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
%#if PY_VERSION_HEX<0x03000000
|
||||
if (PyUnicode_Check(obj)) {
|
||||
char *cstr; Py_ssize_t len;
|
||||
obj = PyUnicode_AsUTF8String(obj);
|
||||
if (PyString_AsStringAndSize(obj, &cstr, &len) == -1) {
|
||||
Py_XDECREF(obj);
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
if (alloc) *alloc = SWIG_NEWOBJ;
|
||||
if (psize) *psize = len + 1;
|
||||
*cptr = %new_copy_array(cstr, len + 1, char);
|
||||
|
||||
Py_XDECREF(obj);
|
||||
return SWIG_OK;
|
||||
}
|
||||
%#endif
|
||||
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
if (pchar_descriptor) {
|
||||
void* vptr = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue