Merged with recent changes from trunk.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
da5ade3143
commit
8c74fa0f46
703 changed files with 21126 additions and 9266 deletions
|
|
@ -5,10 +5,28 @@
|
|||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
if (PyString_Check(obj)) {
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
if (PyUnicode_Check(obj))
|
||||
%#else
|
||||
if (PyString_Check(obj))
|
||||
%#endif
|
||||
{
|
||||
char *cstr; Py_ssize_t len;
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
if (!alloc && cptr) {
|
||||
/* We can't allow converting without allocation, since the internal
|
||||
representation of string in Python 3 is UCS-2/UCS-4 but we require
|
||||
a UTF-8 representation.
|
||||
TODO(bhy) More detailed explanation */
|
||||
return SWIG_RuntimeError;
|
||||
}
|
||||
obj = PyUnicode_AsUTF8String(obj);
|
||||
PyBytes_AsStringAndSize(obj, &cstr, &len);
|
||||
if(alloc) *alloc = SWIG_NEWOBJ;
|
||||
%#else
|
||||
PyString_AsStringAndSize(obj, &cstr, &len);
|
||||
if (cptr) {
|
||||
%#endif
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
/*
|
||||
In python the user should not be able to modify the inner
|
||||
|
|
@ -33,10 +51,16 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
|||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
} else {
|
||||
*cptr = PyString_AsString(obj);
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
assert(0); /* Should never reach here in Python 3 */
|
||||
%#endif
|
||||
*cptr = SWIG_Python_str_AsChar(obj);
|
||||
}
|
||||
}
|
||||
if (psize) *psize = len + 1;
|
||||
%#if PY_VERSION_HEX>=0x03000000
|
||||
Py_XDECREF(obj);
|
||||
%#endif
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
|
|
@ -64,7 +88,11 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
|||
return pchar_descriptor ?
|
||||
SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
|
||||
} else {
|
||||
%#if PY_VERSION_HEX >= 0x03000000
|
||||
return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
|
||||
%#else
|
||||
return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
|
||||
%#endif
|
||||
}
|
||||
} else {
|
||||
return SWIG_Py_Void();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue