Skip to content

Commit e8c0a4e

Browse files
Oliver Marksolymk2
authored andcommitted
enable ctypes wip, hopefully fixes for kivy#301, kivy#333, kivy#319
1 parent 9797fe6 commit e8c0a4e

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

distribute.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,6 @@ function run_distribute() {
807807
try find . | grep -E '*\.(py|pyc|so\.o|so\.a|so\.libs)$' | xargs rm
808808

809809
# we are sure that all of theses will be never used on android (well...)
810-
try rm -rf ctypes
811810
try rm -rf lib2to3
812811
try rm -rf idlelib
813812
try rm -rf config/libpython*.a
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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
4+
@@ -272,31 +272,34 @@
5+
else:
6+
set_conversion_mode("ascii", "strict")
7+
8+
- class c_wchar_p(_SimpleCData):
9+
- _type_ = "Z"
10+
-
11+
- class c_wchar(_SimpleCData):
12+
- _type_ = "u"
13+
-
14+
- POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
15+
-
16+
- def create_unicode_buffer(init, size=None):
17+
- """create_unicode_buffer(aString) -> character array
18+
- create_unicode_buffer(anInteger) -> character array
19+
- create_unicode_buffer(aString, anInteger) -> character array
20+
- """
21+
- if isinstance(init, (str, unicode)):
22+
- if size is None:
23+
- size = len(init)+1
24+
- buftype = c_wchar * size
25+
- buf = buftype()
26+
- buf.value = init
27+
- return buf
28+
- elif isinstance(init, (int, long)):
29+
- buftype = c_wchar * init
30+
- buf = buftype()
31+
- return buf
32+
- raise TypeError(init)
33+
+# The wchar stuff causes a crash on Android (the bionic C library doesn't
34+
+# implement wchar_t anyway)
35+
+#
36+
+# class c_wchar_p(_SimpleCData):
37+
+# _type_ = "Z"
38+
+#
39+
+# class c_wchar(_SimpleCData):
40+
+# _type_ = "u"
41+
+#
42+
+# POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
43+
+#
44+
+# def create_unicode_buffer(init, size=None):
45+
+# """create_unicode_buffer(aString) -> character array
46+
+# create_unicode_buffer(anInteger) -> character array
47+
+# create_unicode_buffer(aString, anInteger) -> character array
48+
+# """
49+
+# if isinstance(init, (str, unicode)):
50+
+# if size is None:
51+
+# size = len(init)+1
52+
+# buftype = c_wchar * size
53+
+# buf = buftype()
54+
+# buf.value = init
55+
+# return buf
56+
+# elif isinstance(init, (int, long)):
57+
+# buftype = c_wchar * init
58+
+# buf = buftype()
59+
+# return buf
60+
+# raise TypeError(init)
61+
62+
POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
63+

recipes/python/patches/disable-modules.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# This global variable is used to hold the list of modules to be disabled.
77
-disabled_module_list = []
8-
+disabled_module_list = ['spwd', '_ctypes','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing']
8+
+disabled_module_list = ['spwd','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing']
99

1010
def add_dir_to_list(dirlist, dir):
1111
"""Add the directory 'dir' to the list 'dirlist' (at the front) if

recipes/python/recipe.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function prebuild_python() {
2020
fi
2121

2222
try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-xcompile.patch
23+
try patch -p1 < $RECIPE_python/patches/Python-$VERSION_python-ctypes-disable-wchar.patch
2324
try patch -p1 < $RECIPE_python/patches/disable-modules.patch
2425
try patch -p1 < $RECIPE_python/patches/fix-locale.patch
2526
try patch -p1 < $RECIPE_python/patches/fix-gethostbyaddr.patch
@@ -92,8 +93,13 @@ function build_python() {
9293
export LDFLAGS="$LDFLAGS -L$SRC_PATH/obj/local/$ARCH/"
9394
fi
9495

95-
try ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
96-
echo ./configure --host=arm-eabi OPT=$OFLAG --prefix="$BUILD_PATH/python-install" --enable-shared --disable-toolbox-glue --disable-framework
96+
# CFLAGS for python ctypes library
97+
export CFLAGS="$CFLAGS -DNO_MALLINFO"
98+
export BUILDARCH=x86_64-linux-gnu
99+
export HOSTARCH=arm-eabi
100+
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
97103
echo $MAKE HOSTPYTHON=$BUILD_python/hostpython HOSTPGEN=$BUILD_python/hostpgen CROSS_COMPILE_TARGET=yes INSTSONAME=libpython2.7.so
98104
cp HOSTPYTHON=$BUILD_python/hostpython python
99105

@@ -117,6 +123,7 @@ function build_python() {
117123
fi
118124
try cp $BUILD_hostpython/hostpython $HOSTPYTHON
119125
try cp libpython2.7.so $LIBS_PATH/
126+
try cp -a build/lib.linux-x86_64-2.7/_ctypes*.so $LIBS_PATH
120127

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ public void run(){
8585
System.loadLibrary("python2.7");
8686
System.loadLibrary("application");
8787
System.loadLibrary("sdl_main");
88+
System.loadLibrary("ctypes");
8889

8990
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_io.so");
9091
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/unicodedata.so");
92+
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so");
9193

9294
try {
9395
System.loadLibrary("sqlite3");

0 commit comments

Comments
 (0)