diff --git a/distribute.sh b/distribute.sh index 1a79d14e30..adcda0a817 100755 --- a/distribute.sh +++ b/distribute.sh @@ -807,7 +807,6 @@ function run_distribute() { try find . | grep -E '*\.(py|pyc|so\.o|so\.a|so\.libs)$' | xargs rm # we are sure that all of theses will be never used on android (well...) - try rm -rf ctypes try rm -rf lib2to3 try rm -rf idlelib try rm -rf config/libpython*.a diff --git a/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch b/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch new file mode 100644 index 0000000000..19d8915eaa --- /dev/null +++ b/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch @@ -0,0 +1,116 @@ +diff -ur '--exclude=*~' Python-2.7.2.orig/Lib/ctypes/__init__.py Python-2.7.2/Lib/ctypes/__init__.py +--- Python-2.7.2.orig/Lib/ctypes/__init__.py 2011-06-11 16:46:24.000000000 +0100 ++++ Python-2.7.2/Lib/ctypes/__init__.py 2015-03-19 12:32:45.747723687 +0000 +@@ -272,31 +272,34 @@ + else: + set_conversion_mode("ascii", "strict") + +- class c_wchar_p(_SimpleCData): +- _type_ = "Z" +- +- class c_wchar(_SimpleCData): +- _type_ = "u" +- +- POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param +- +- def create_unicode_buffer(init, size=None): +- """create_unicode_buffer(aString) -> character array +- create_unicode_buffer(anInteger) -> character array +- create_unicode_buffer(aString, anInteger) -> character array +- """ +- if isinstance(init, (str, unicode)): +- if size is None: +- size = len(init)+1 +- buftype = c_wchar * size +- buf = buftype() +- buf.value = init +- return buf +- elif isinstance(init, (int, long)): +- buftype = c_wchar * init +- buf = buftype() +- return buf +- raise TypeError(init) ++# The wchar stuff causes a crash on Android (the bionic C library doesn't ++# implement wchar_t anyway) ++# ++# class c_wchar_p(_SimpleCData): ++# _type_ = "Z" ++# ++# class c_wchar(_SimpleCData): ++# _type_ = "u" ++# ++# POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param ++# ++# def create_unicode_buffer(init, size=None): ++# """create_unicode_buffer(aString) -> character array ++# create_unicode_buffer(anInteger) -> character array ++# create_unicode_buffer(aString, anInteger) -> character array ++# """ ++# if isinstance(init, (str, unicode)): ++# if size is None: ++# size = len(init)+1 ++# buftype = c_wchar * size ++# buf = buftype() ++# buf.value = init ++# return buf ++# elif isinstance(init, (int, long)): ++# buftype = c_wchar * init ++# buf = buftype() ++# return buf ++# raise TypeError(init) + + POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param + +diff -ur '--exclude=*~' Python-2.7.2.orig/Modules/_ctypes/callproc.c Python-2.7.2/Modules/_ctypes/callproc.c +--- Python-2.7.2.orig/Modules/_ctypes/callproc.c 2015-03-19 11:56:40.668159317 +0000 ++++ Python-2.7.2/Modules/_ctypes/callproc.c 2015-03-19 11:45:45.898288000 +0000 +@@ -1423,7 +1423,7 @@ + mode |= RTLD_NOW; + handle = ctypes_dlopen(name, mode); + if (!handle) { +- char *errmsg = ctypes_dlerror(); ++ const char *errmsg = ctypes_dlerror(); + if (!errmsg) + errmsg = "dlopen() error"; + PyErr_SetString(PyExc_OSError, +diff -ur '--exclude=*~' Python-2.7.2.orig/Modules/_ctypes/libffi/src/dlmalloc.c Python-2.7.2/Modules/_ctypes/libffi/src/dlmalloc.c +--- Python-2.7.2.orig/Modules/_ctypes/libffi/src/dlmalloc.c 2015-03-19 13:26:58.928438829 +0000 ++++ Python-2.7.2/Modules/_ctypes/libffi/src/dlmalloc.c 2015-03-19 15:32:19.042396376 +0000 +@@ -614,18 +614,6 @@ + #include "/usr/include/malloc.h" + #else /* HAVE_USR_INCLUDE_MALLOC_H */ + +-struct mallinfo { +- MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ +- MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ +- MALLINFO_FIELD_TYPE smblks; /* always 0 */ +- MALLINFO_FIELD_TYPE hblks; /* always 0 */ +- MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ +- MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ +- MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ +- MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ +- MALLINFO_FIELD_TYPE fordblks; /* total free space */ +- MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ +-}; + + #endif /* HAVE_USR_INCLUDE_MALLOC_H */ + #endif /* NO_MALLINFO */ +@@ -966,7 +954,7 @@ + p = malloc(n); + assert(malloc_usable_size(p) >= 256); + */ +-size_t dlmalloc_usable_size(void*); ++size_t dlmalloc_usable_size(const void*); + + /* + malloc_stats(); +@@ -4384,7 +4372,7 @@ + internal_malloc_stats(gm); + } + +-size_t dlmalloc_usable_size(void* mem) { ++size_t dlmalloc_usable_size(const void* mem) { + if (mem != 0) { + mchunkptr p = mem2chunk(mem); + if (cinuse(p)) + diff --git a/recipes/python/patches/ctypes-find-library.patch b/recipes/python/patches/ctypes-find-library.patch new file mode 100644 index 0000000000..68fa93f526 --- /dev/null +++ b/recipes/python/patches/ctypes-find-library.patch @@ -0,0 +1,28 @@ +diff -ur Python-2.7.2.orig/Lib/ctypes/util.py Python-2.7.2/Lib/ctypes/util.py +--- Python-2.7.2.orig/Lib/ctypes/util.py 2011-06-11 16:46:24.000000000 +0100 ++++ Python-2.7.2/Lib/ctypes/util.py 2015-05-10 15:50:18.906203529 +0100 +@@ -71,7 +71,21 @@ + def find_library(name): + return name + +-if os.name == "posix" and sys.platform == "darwin": ++# this test is for android specifically shoudl match here and ignore any ++# of the other platform tests below ++if os.name == "posix": ++ def find_library(name): ++ """ hack to find librarys for kivy and android ++ split the path and get the first parts which will give us ++ the app path something like /data/data/org.app.foo/""" ++ app_root = os.path.abspath('./').split(os.path.sep)[0:4] ++ lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib' ++ for filename in os.listdir(lib_search): ++ if filename.endswith('.so') and name in filename: ++ return lib_search + os.path.sep + filename ++ return None ++ ++elif os.name == "posix" and sys.platform == "darwin": + from ctypes.macholib.dyld import dyld_find as _dyld_find + def find_library(name): + possible = ['lib%s.dylib' % name, +Only in Python-2.7.2/Lib/ctypes: util.py.save +Only in Python-2.7.2/Lib/ctypes: util.py.save.1 diff --git a/recipes/python/patches/disable-modules.patch b/recipes/python/patches/disable-modules.patch index fe96dcdcd8..3841488c40 100644 --- a/recipes/python/patches/disable-modules.patch +++ b/recipes/python/patches/disable-modules.patch @@ -5,7 +5,7 @@ # This global variable is used to hold the list of modules to be disabled. -disabled_module_list = [] -+disabled_module_list = ['spwd', '_ctypes','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing'] ++disabled_module_list = ['spwd','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing'] def add_dir_to_list(dirlist, dir): """Add the directory 'dir' to the list 'dirlist' (at the front) if diff --git a/recipes/python/recipe.sh b/recipes/python/recipe.sh index 4246bae97a..69e1b6c26a 100644 --- a/recipes/python/recipe.sh +++ b/recipes/python/recipe.sh @@ -20,6 +20,7 @@ function prebuild_python() { fi try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-xcompile.patch + try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-ctypes-disable-wchar.patch try patch -p1 < $RECIPE_python/patches/disable-modules.patch try patch -p1 < $RECIPE_python/patches/fix-locale.patch try patch -p1 < $RECIPE_python/patches/fix-gethostbyaddr.patch @@ -31,6 +32,7 @@ function prebuild_python() { try patch -p1 < $RECIPE_python/patches/fix-remove-corefoundation.patch try patch -p1 < $RECIPE_python/patches/fix-dynamic-lookup.patch try patch -p1 < $RECIPE_python/patches/fix-dlfcn.patch + try patch -p1 < $RECIPE_python/patches/ctypes-find-library.patch system=$(uname -s) if [ "X$system" == "XDarwin" ]; then @@ -92,14 +94,19 @@ function build_python() { export LDFLAGS="$LDFLAGS -L$SRC_PATH/obj/local/$ARCH/" fi - try ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework - echo ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework + # CFLAGS for python ctypes library + #export CFLAGS="$CFLAGS -DNO_MALLINFO" + export BUILDARCH=x86_64-linux-gnu + export HOSTARCH=arm-eabi + + try ./configure --host=$HOSTARCH --build=$BUILDARCH OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework + echo ./configure --host=$HOSTARCH --build=$BUILDARCH OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework echo $MAKE HOSTPYTHON=$BUILD_python/hostpython HOSTPGEN=$BUILD_python/hostpgen CROSS_COMPILE_TARGET=yes INSTSONAME=libpython2.7.so cp HOSTPYTHON=$BUILD_python/hostpython python # FIXME, the first time, we got a error at: # python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h - # /home/tito/code/python-for-android/build/python/Python-2.7.2/python: 1: Syntax error: word unexpected (expecting ")") + # /home/tito/code/python-for-android/build/python/Python-2.7.2/python: 1: Syntax error: word unexpected (expecting ")") # because at this time, python is arm, not x86. even that, why /usr/include/netinet/in.h is used ? # check if we can avoid this part. @@ -117,6 +124,7 @@ function build_python() { fi try cp $BUILD_hostpython/hostpython $HOSTPYTHON try cp libpython2.7.so $LIBS_PATH/ + try cp -a build/lib.linux-x86_64-2.7/_ctypes*.so $LIBS_PATH # reduce python rm -rf "$BUILD_PATH/python-install/lib/python2.7/test" diff --git a/src/src/org/renpy/android/PythonService.java b/src/src/org/renpy/android/PythonService.java index 321ee6094d..2128f9bb34 100644 --- a/src/src/org/renpy/android/PythonService.java +++ b/src/src/org/renpy/android/PythonService.java @@ -85,9 +85,16 @@ public void run(){ System.loadLibrary("python2.7"); System.loadLibrary("application"); System.loadLibrary("sdl_main"); + System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_io.so"); System.load(getFilesDir() + "/lib/python2.7/lib-dynload/unicodedata.so"); + + try { + System.loadLibrary("ctypes"); + System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so"); + } catch(UnsatisfiedLinkError e) { + } try { System.loadLibrary("sqlite3");