Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion distribute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 116 additions & 0 deletions recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch
Original file line number Diff line number Diff line change
@@ -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))

28 changes: 28 additions & 0 deletions recipes/python/patches/ctypes-find-library.patch
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion recipes/python/patches/disable-modules.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 11 additions & 3 deletions recipes/python/recipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions src/src/org/renpy/android/PythonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down