diff -r 38f5b3beeb2a Include/androidfn.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Include/androidfn.h Thu Apr 09 10:23:03 2015 -0500 @@ -0,0 +1,15 @@ +/* Fix for broken Android mbstowcs, from rjmatthews62@gmail.com */ +#ifndef Py_ANDROIDFN_H +#define Py_ANDROIDFN_H + +#include + +/* this MUST come after the stdlib.h include */ +#ifdef __ANDROID__ +size_t android_wcstombs(char * dest, const wchar_t *source, int maxlen); +size_t android_mbstowcs(wchar_t *dest, const char * source, int maxlen); +#define wcstombs android_wcstombs +#define mbstowcs android_mbstowcs +#endif + +#endif /* !Py_ANDROIDFN_H */ diff -r 38f5b3beeb2a Python/pythonrun.c --- a/Python/pythonrun.c Thu Mar 19 15:16:03 2015 -0500 +++ b/Python/pythonrun.c Thu Apr 09 10:23:03 2015 -0500 @@ -35,6 +35,47 @@ #include "windows.h" #endif +/* the following defines are from rjmatthews62@gmail.com, specifically from his + * notes on cross compiling Python for Android. In Android, mbstowcs is very broken + * the next lines define it here. + */ + +#ifdef __ANDROID__ +size_t android_mbstowcs(wchar_t *dest, char * in, int maxlen) { + wchar_t *out = dest; + int size = 0; + if (in) + { + while(*in && size= 0xdc800 && c <= 0xdcff) + { + /* UTF-8b surrogate */ + c-=0xdc800; + } + if (dest) dest[i]=c; + } + return i; +} +#endif + _Py_IDENTIFIER(builtins); _Py_IDENTIFIER(excepthook); _Py_IDENTIFIER(flush);