Skip to content
Open
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
20 changes: 20 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#https://groups.google.com/forum/?hl=en#!searchin/python-android/ctypes/python-android/vDaaJXNYz_A/eazMVI-DQSYJ
#/home/oly/.buildozer/android/platform/

export ANDROIDSDK="/home/omarks/.buildozer/android/platform/android-sdk-21"
export ANDROIDNDK="/home/omarks/.buildozer/android/platform/android-ndk-r9d"
export ANDROIDNDKVER=r9
export ANDROIDAPI=14

export ANDROIDSDK="/home/oly/development/android-sdk-linux"
export ANDROIDNDK="/home/oly/development/android-ndk-r7"
export ANDROIDNDKVER=r7
export ANDROIDAPI=14

diff -ur Python-2.7.2.orig/ Python-2.7.2/ > test.diff



#./distribute.sh -f -m "pil"
./distribute.sh -f -m "python"
#> /tmp/p4a-log.txt
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
107 changes: 107 additions & 0 deletions python-for-android-fix_ctypes.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
diff -uNr kivy-python-for-android-51f8025/recipes/python/patches/disable-modules.patch kivy-python-for-android-51f8025-patched6/recipes/python/patches/disable-modules.patch
--- kivy-python-for-android-51f8025/recipes/python/patches/disable-modules.patch 2012-08-24 15:23:07.000000000 +0200
+++ kivy-python-for-android-51f8025-patched6/recipes/python/patches/disable-modules.patch 2012-08-29 14:54:40.000000000 +0200
@@ -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 -uNr kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch kivy-python-for-android-51f8025-patched6/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch
--- kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch 1970-01-01 01:00:00.000000000 +0100
+++ kivy-python-for-android-51f8025-patched6/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch 2012-08-30 13:41:33.000000000 +0200
@@ -0,0 +1,63 @@
+diff -uNr 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 17:46:24.000000000 +0200
++++ Python-2.7.2/Lib/ctypes/__init__.py 2012-08-30 13:40:38.837698797 +0200
+@@ -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 -uNr kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-xcompile.patch kivy-python-for-android-51f8025-patched6/recipes/python/patches/Python-2.7.2-xcompile.patch
--- kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-xcompile.patch 2012-08-24 15:23:07.000000000 +0200
+++ kivy-python-for-android-51f8025-patched6/recipes/python/patches/Python-2.7.2-xcompile.patch 2012-08-30 15:51:37.000000000 +0200
@@ -181,10 +181,10 @@
- cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
- % (ffi_builddir, ffi_srcdir, " ".join(config_args))
+ if self.cross_compile:
-+ cmd = "cd %s && env CFLAGS='' %s/configure --host=%s --build=%s %s" \
++ cmd = "cd %s && env CFLAGS='-DNO_MALLINFO=1 -DFFI_MMAP_EXEC_WRIT=1 -DFFI_MMAP_EXEC_SELINUX=0' %s/configure --host=%s --build=%s %s" \
+ % (ffi_builddir, ffi_srcdir,
-+ os.environ.get('HOSTARCH'),
-+ os.environ.get('BUILDARCH'),
++ 'arm-eabi',
++ 'i486-linux-gnu',
+ " ".join(config_args))
+ else:
+ cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
diff -uNr kivy-python-for-android-51f8025/recipes/python/recipe.sh kivy-python-for-android-51f8025-patched6/recipes/python/recipe.sh
--- kivy-python-for-android-51f8025/recipes/python/recipe.sh 2012-08-24 15:23:07.000000000 +0200
+++ kivy-python-for-android-51f8025-patched6/recipes/python/recipe.sh 2012-08-30 14:24:47.000000000 +0200
@@ -19,6 +19,7 @@
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
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))

2 changes: 1 addition & 1 deletion recipes/python/patches/Python-2.7.2-xcompile.patch
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ diff -urN Python-2.7.2/setup.py ltib/rpm/BUILD/Python-2.7.2/setup.py
- cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
- % (ffi_builddir, ffi_srcdir, " ".join(config_args))
+ if self.cross_compile:
+ cmd = "cd %s && env CFLAGS='' %s/configure --host=%s --build=%s %s" \
+ cmd = "cd %s && env CFLAGS='-DNO_MALLINFO=1 -DFFI_MMAP_EXEC_WRIT=1 -DFFI_MMAP_EXEC_SELINUX=0' %s/configure --host=%s --build=%s %s" \
+ % (ffi_builddir, ffi_srcdir,
+ os.environ.get('HOSTARCH'),
+ os.environ.get('BUILDARCH'),
Expand Down
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
18 changes: 16 additions & 2 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 Down Expand Up @@ -92,8 +93,13 @@ 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

Expand All @@ -118,6 +124,14 @@ function build_python() {
try cp $BUILD_hostpython/hostpython $HOSTPYTHON
try cp libpython2.7.so $LIBS_PATH/

echo '############copy ctypes'
cd $BUILD_python
echo $BUILD_python
echo pwd
echo build/lib.linux-x86_64-2.7/_ctypes*.so
try cp -a build/lib.linux-x86_64-2.7/_ctypes*.so $LIBS_PATH
#exit 0

# reduce python
rm -rf "$BUILD_PATH/python-install/lib/python2.7/test"
rm -rf "$BUILD_PATH/python-install/lib/python2.7/json/tests"
Expand Down
3 changes: 3 additions & 0 deletions src/src/org/renpy/android/PythonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public void run(){
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_io.so");
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/unicodedata.so");

System.loadLibrary("ctypes");
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so");

try {
System.loadLibrary("sqlite3");
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_sqlite3.so");
Expand Down