Skip to content

Commit 5795c32

Browse files
author
Oliver Marks
committed
patch file
1 parent a60d9e6 commit 5795c32

File tree

5 files changed

+177
-7
lines changed

5 files changed

+177
-7
lines changed

build.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#https://groups.google.com/forum/?hl=en#!searchin/python-android/ctypes/python-android/vDaaJXNYz_A/eazMVI-DQSYJ
22
#/home/oly/.buildozer/android/platform/
33

4-
export ANDROIDSDK="/home/omarks/.buildozer/android/platform/android-sdk-20"
4+
export ANDROIDSDK="/home/omarks/.buildozer/android/platform/android-sdk-21"
55
export ANDROIDNDK="/home/omarks/.buildozer/android/platform/android-ndk-r9d"
66
export ANDROIDNDKVER=r9
77
export ANDROIDAPI=14
@@ -11,6 +11,10 @@ export ANDROIDNDK="/home/oly/development/android-ndk-r7"
1111
export ANDROIDNDKVER=r7
1212
export ANDROIDAPI=14
1313

14+
diff -ur Python-2.7.2.orig/ Python-2.7.2/ > test.diff
15+
16+
17+
1418
#./distribute.sh -f -m "pil"
1519
./distribute.sh -f -m "python"
1620
#> /tmp/p4a-log.txt

python-for-android-fix_ctypes.diff

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
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
2+
--- kivy-python-for-android-51f8025/recipes/python/patches/disable-modules.patch 2012-08-24 15:23:07.000000000 +0200
3+
+++ kivy-python-for-android-51f8025-patched6/recipes/python/patches/disable-modules.patch 2012-08-29 14:54:40.000000000 +0200
4+
@@ -5,7 +5,7 @@
5+
6+
# This global variable is used to hold the list of modules to be disabled.
7+
-disabled_module_list = []
8+
-+disabled_module_list = ['spwd', '_ctypes','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing']
9+
++disabled_module_list = ['spwd','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing']
10+
11+
def add_dir_to_list(dirlist, dir):
12+
"""Add the directory 'dir' to the list 'dirlist' (at the front) if
13+
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
14+
--- kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch 1970-01-01 01:00:00.000000000 +0100
15+
+++ 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
16+
@@ -0,0 +1,63 @@
17+
+diff -uNr Python-2.7.2.orig/Lib/ctypes/__init__.py Python-2.7.2/Lib/ctypes/__init__.py
18+
+--- Python-2.7.2.orig/Lib/ctypes/__init__.py 2011-06-11 17:46:24.000000000 +0200
19+
++++ Python-2.7.2/Lib/ctypes/__init__.py 2012-08-30 13:40:38.837698797 +0200
20+
+@@ -272,31 +272,34 @@
21+
+ else:
22+
+ set_conversion_mode("ascii", "strict")
23+
+
24+
+- class c_wchar_p(_SimpleCData):
25+
+- _type_ = "Z"
26+
+-
27+
+- class c_wchar(_SimpleCData):
28+
+- _type_ = "u"
29+
+-
30+
+- POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
31+
+-
32+
+- def create_unicode_buffer(init, size=None):
33+
+- """create_unicode_buffer(aString) -> character array
34+
+- create_unicode_buffer(anInteger) -> character array
35+
+- create_unicode_buffer(aString, anInteger) -> character array
36+
+- """
37+
+- if isinstance(init, (str, unicode)):
38+
+- if size is None:
39+
+- size = len(init)+1
40+
+- buftype = c_wchar * size
41+
+- buf = buftype()
42+
+- buf.value = init
43+
+- return buf
44+
+- elif isinstance(init, (int, long)):
45+
+- buftype = c_wchar * init
46+
+- buf = buftype()
47+
+- return buf
48+
+- raise TypeError(init)
49+
++# The wchar stuff causes a crash on Android (the bionic C library doesn't
50+
++# implement wchar_t anyway)
51+
++#
52+
++# class c_wchar_p(_SimpleCData):
53+
++# _type_ = "Z"
54+
++#
55+
++# class c_wchar(_SimpleCData):
56+
++# _type_ = "u"
57+
++#
58+
++# POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
59+
++#
60+
++# def create_unicode_buffer(init, size=None):
61+
++# """create_unicode_buffer(aString) -> character array
62+
++# create_unicode_buffer(anInteger) -> character array
63+
++# create_unicode_buffer(aString, anInteger) -> character array
64+
++# """
65+
++# if isinstance(init, (str, unicode)):
66+
++# if size is None:
67+
++# size = len(init)+1
68+
++# buftype = c_wchar * size
69+
++# buf = buftype()
70+
++# buf.value = init
71+
++# return buf
72+
++# elif isinstance(init, (int, long)):
73+
++# buftype = c_wchar * init
74+
++# buf = buftype()
75+
++# return buf
76+
++# raise TypeError(init)
77+
+
78+
+ POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
79+
+
80+
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
81+
--- kivy-python-for-android-51f8025/recipes/python/patches/Python-2.7.2-xcompile.patch 2012-08-24 15:23:07.000000000 +0200
82+
+++ kivy-python-for-android-51f8025-patched6/recipes/python/patches/Python-2.7.2-xcompile.patch 2012-08-30 15:51:37.000000000 +0200
83+
@@ -181,10 +181,10 @@
84+
- cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
85+
- % (ffi_builddir, ffi_srcdir, " ".join(config_args))
86+
+ if self.cross_compile:
87+
-+ cmd = "cd %s && env CFLAGS='' %s/configure --host=%s --build=%s %s" \
88+
++ 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" \
89+
+ % (ffi_builddir, ffi_srcdir,
90+
-+ os.environ.get('HOSTARCH'),
91+
-+ os.environ.get('BUILDARCH'),
92+
++ 'arm-eabi',
93+
++ 'i486-linux-gnu',
94+
+ " ".join(config_args))
95+
+ else:
96+
+ cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
97+
diff -uNr kivy-python-for-android-51f8025/recipes/python/recipe.sh kivy-python-for-android-51f8025-patched6/recipes/python/recipe.sh
98+
--- kivy-python-for-android-51f8025/recipes/python/recipe.sh 2012-08-24 15:23:07.000000000 +0200
99+
+++ kivy-python-for-android-51f8025-patched6/recipes/python/recipe.sh 2012-08-30 14:24:47.000000000 +0200
100+
@@ -19,6 +19,7 @@
101+
fi
102+
103+
try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-xcompile.patch
104+
+ try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-ctypes-disable-wchar.patch
105+
try patch -p1 < $RECIPE_python/patches/disable-modules.patch
106+
try patch -p1 < $RECIPE_python/patches/fix-locale.patch
107+
try patch -p1 < $RECIPE_python/patches/fix-gethostbyaddr.patch

recipes/python/patches/Python-2.7.2-ctypes-disable-wchar.patch

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
diff -uNr Python-2.7.2.orig/Lib/ctypes/__init__.py Python-2.7.2/Lib/ctypes/__init__.py
2-
--- Python-2.7.2.orig/Lib/ctypes/__init__.py 2011-06-11 17:46:24.000000000 +0200
3-
+++ Python-2.7.2/Lib/ctypes/__init__.py 2012-08-30 13:40:38.837698797 +0200
1+
diff -ur '--exclude=*~' Python-2.7.2.orig/Lib/ctypes/__init__.py Python-2.7.2/Lib/ctypes/__init__.py
2+
--- Python-2.7.2.orig/Lib/ctypes/__init__.py 2011-06-11 16:46:24.000000000 +0100
3+
+++ Python-2.7.2/Lib/ctypes/__init__.py 2015-03-19 12:32:45.747723687 +0000
44
@@ -272,31 +272,34 @@
55
else:
66
set_conversion_mode("ascii", "strict")
@@ -61,3 +61,56 @@ diff -uNr Python-2.7.2.orig/Lib/ctypes/__init__.py Python-2.7.2/Lib/ctypes/__ini
6161

6262
POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
6363

64+
diff -ur '--exclude=*~' Python-2.7.2.orig/Modules/_ctypes/callproc.c Python-2.7.2/Modules/_ctypes/callproc.c
65+
--- Python-2.7.2.orig/Modules/_ctypes/callproc.c 2015-03-19 11:56:40.668159317 +0000
66+
+++ Python-2.7.2/Modules/_ctypes/callproc.c 2015-03-19 11:45:45.898288000 +0000
67+
@@ -1423,7 +1423,7 @@
68+
mode |= RTLD_NOW;
69+
handle = ctypes_dlopen(name, mode);
70+
if (!handle) {
71+
- char *errmsg = ctypes_dlerror();
72+
+ const char *errmsg = ctypes_dlerror();
73+
if (!errmsg)
74+
errmsg = "dlopen() error";
75+
PyErr_SetString(PyExc_OSError,
76+
diff -ur '--exclude=*~' Python-2.7.2.orig/Modules/_ctypes/libffi/src/dlmalloc.c Python-2.7.2/Modules/_ctypes/libffi/src/dlmalloc.c
77+
--- Python-2.7.2.orig/Modules/_ctypes/libffi/src/dlmalloc.c 2015-03-19 13:26:58.928438829 +0000
78+
+++ Python-2.7.2/Modules/_ctypes/libffi/src/dlmalloc.c 2015-03-19 15:32:19.042396376 +0000
79+
@@ -614,18 +614,6 @@
80+
#include "/usr/include/malloc.h"
81+
#else /* HAVE_USR_INCLUDE_MALLOC_H */
82+
83+
-struct mallinfo {
84+
- MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
85+
- MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
86+
- MALLINFO_FIELD_TYPE smblks; /* always 0 */
87+
- MALLINFO_FIELD_TYPE hblks; /* always 0 */
88+
- MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
89+
- MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
90+
- MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
91+
- MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
92+
- MALLINFO_FIELD_TYPE fordblks; /* total free space */
93+
- MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
94+
-};
95+
96+
#endif /* HAVE_USR_INCLUDE_MALLOC_H */
97+
#endif /* NO_MALLINFO */
98+
@@ -966,7 +954,7 @@
99+
p = malloc(n);
100+
assert(malloc_usable_size(p) >= 256);
101+
*/
102+
-size_t dlmalloc_usable_size(void*);
103+
+size_t dlmalloc_usable_size(const void*);
104+
105+
/*
106+
malloc_stats();
107+
@@ -4384,7 +4372,7 @@
108+
internal_malloc_stats(gm);
109+
}
110+
111+
-size_t dlmalloc_usable_size(void* mem) {
112+
+size_t dlmalloc_usable_size(const void* mem) {
113+
if (mem != 0) {
114+
mchunkptr p = mem2chunk(mem);
115+
if (cinuse(p))
116+

recipes/python/recipe.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ function build_python() {
9595

9696
# CFLAGS for python ctypes library
9797
export CFLAGS="$CFLAGS -DNO_MALLINFO"
98+
export BUILDARCH=x86_64-linux-gnu
99+
export HOSTARCH=arm-eabi
98100

99-
100-
try ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
101-
echo ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
101+
try ./configure --host=$HOSTARCH --build=$BUILDARCH OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
102+
echo ./configure --host=$HOSTARCH --build=$BUILDARCH OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
102103
echo $MAKE HOSTPYTHON=$BUILD_python/hostpython HOSTPGEN=$BUILD_python/hostpgen CROSS_COMPILE_TARGET=yes INSTSONAME=libpython2.7.so
103104
cp HOSTPYTHON=$BUILD_python/hostpython python
104105

@@ -126,8 +127,10 @@ function build_python() {
126127
echo '############copy ctypes'
127128
cd $BUILD_python
128129
echo $BUILD_python
130+
echo pwd
129131
echo build/lib.linux-x86_64-2.7/_ctypes*.so
130132
try cp -a build/lib.linux-x86_64-2.7/_ctypes*.so $LIBS_PATH
133+
#exit 0
131134

132135
# reduce python
133136
rm -rf "$BUILD_PATH/python-install/lib/python2.7/test"

src/src/org/renpy/android/PythonService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public void run(){
8989
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_io.so");
9090
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/unicodedata.so");
9191

92+
System.loadLibrary("ctypes");
93+
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so");
94+
9295
try {
9396
System.loadLibrary("sqlite3");
9497
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_sqlite3.so");

0 commit comments

Comments
 (0)