Skip to content

Commit 6c352dd

Browse files
committed
PR snagging
1 parent 6241ac1 commit 6c352dd

File tree

3 files changed

+33
-251
lines changed

3 files changed

+33
-251
lines changed
Lines changed: 24 additions & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -1,251 +1,28 @@
11
diff -ur Python-2.7.2.orig/Lib/ctypes/util.py Python-2.7.2/Lib/ctypes/util.py
22
--- Python-2.7.2.orig/Lib/ctypes/util.py 2011-06-11 16:46:24.000000000 +0100
3-
+++ Python-2.7.2/Lib/ctypes/util.py 2015-05-10 10:37:49.258720992 +0100
4-
@@ -3,237 +3,16 @@
5-
######################################################################
6-
import sys, os
3+
+++ Python-2.7.2/Lib/ctypes/util.py 2015-05-10 15:50:18.906203529 +0100
4+
@@ -71,7 +71,21 @@
5+
def find_library(name):
6+
return name
77

8-
-# find_library(name) returns the pathname of a library, or None.
9-
-if os.name == "nt":
10-
-
11-
- def _get_build_version():
12-
- """Return the version of MSVC that was used to build Python.
13-
-
14-
- For Python 2.3 and up, the version number is included in
15-
- sys.version. For earlier versions, assume the compiler is MSVC 6.
16-
- """
17-
- # This function was copied from Lib/distutils/msvccompiler.py
18-
- prefix = "MSC v."
19-
- i = sys.version.find(prefix)
20-
- if i == -1:
21-
- return 6
22-
- i = i + len(prefix)
23-
- s, rest = sys.version[i:].split(" ", 1)
24-
- majorVersion = int(s[:-2]) - 6
25-
- minorVersion = int(s[2:3]) / 10.0
26-
- # I don't think paths are affected by minor version in version 6
27-
- if majorVersion == 6:
28-
- minorVersion = 0
29-
- if majorVersion >= 6:
30-
- return majorVersion + minorVersion
31-
- # else we don't know what version of the compiler this is
32-
- return None
33-
-
34-
- def find_msvcrt():
35-
- """Return the name of the VC runtime dll"""
36-
- version = _get_build_version()
37-
- if version is None:
38-
- # better be safe than sorry
39-
- return None
40-
- if version <= 6:
41-
- clibname = 'msvcrt'
42-
- else:
43-
- clibname = 'msvcr%d' % (version * 10)
44-
-
45-
- # If python was built with in debug mode
46-
- import imp
47-
- if imp.get_suffixes()[0][0] == '_d.pyd':
48-
- clibname += 'd'
49-
- return clibname+'.dll'
50-
-
51-
- def find_library(name):
52-
- if name in ('c', 'm'):
53-
- return find_msvcrt()
54-
- # See MSDN for the REAL search order.
55-
- for directory in os.environ['PATH'].split(os.pathsep):
56-
- fname = os.path.join(directory, name)
57-
- if os.path.isfile(fname):
58-
- return fname
59-
- if fname.lower().endswith(".dll"):
60-
- continue
61-
- fname = fname + ".dll"
62-
- if os.path.isfile(fname):
63-
- return fname
64-
- return None
65-
-
66-
-if os.name == "ce":
67-
- # search path according to MSDN:
68-
- # - absolute path specified by filename
69-
- # - The .exe launch directory
70-
- # - the Windows directory
71-
- # - ROM dll files (where are they?)
72-
- # - OEM specified search path: HKLM\Loader\SystemPath
73-
- def find_library(name):
74-
- return name
75-
-
768
-if os.name == "posix" and sys.platform == "darwin":
77-
- from ctypes.macholib.dyld import dyld_find as _dyld_find
78-
- def find_library(name):
79-
- possible = ['lib%s.dylib' % name,
80-
- '%s.dylib' % name,
81-
- '%s.framework/%s' % (name, name)]
82-
- for name in possible:
83-
- try:
84-
- return _dyld_find(name)
85-
- except ValueError:
86-
- continue
87-
- return None
88-
-
89-
-elif os.name == "posix":
90-
- # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
91-
- import re, tempfile, errno
92-
-
93-
- def _findLib_gcc(name):
94-
- expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
95-
- fdout, ccout = tempfile.mkstemp()
96-
- os.close(fdout)
97-
- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \
98-
- '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
99-
- try:
100-
- f = os.popen(cmd)
101-
- try:
102-
- trace = f.read()
103-
- finally:
104-
- rv = f.close()
105-
- finally:
106-
- try:
107-
- os.unlink(ccout)
108-
- except OSError, e:
109-
- if e.errno != errno.ENOENT:
110-
- raise
111-
- if rv == 10:
112-
- raise OSError, 'gcc or cc command not found'
113-
- res = re.search(expr, trace)
114-
- if not res:
115-
- return None
116-
- return res.group(0)
117-
-
118-
-
119-
- if sys.platform == "sunos5":
120-
- # use /usr/ccs/bin/dump on solaris
121-
- def _get_soname(f):
122-
- if not f:
123-
- return None
124-
- cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
125-
- f = os.popen(cmd)
126-
- try:
127-
- data = f.read()
128-
- finally:
129-
- f.close()
130-
- res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
131-
- if not res:
132-
- return None
133-
- return res.group(1)
134-
- else:
135-
- def _get_soname(f):
136-
- # assuming GNU binutils / ELF
137-
- if not f:
138-
- return None
139-
- cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
140-
- "objdump -p -j .dynamic 2>/dev/null " + f
141-
- f = os.popen(cmd)
142-
- dump = f.read()
143-
- rv = f.close()
144-
- if rv == 10:
145-
- raise OSError, 'objdump command not found'
146-
- f = os.popen(cmd)
147-
- try:
148-
- data = f.read()
149-
- finally:
150-
- f.close()
151-
- res = re.search(r'\sSONAME\s+([^\s]+)', data)
152-
- if not res:
153-
- return None
154-
- return res.group(1)
155-
-
156-
- if (sys.platform.startswith("freebsd")
157-
- or sys.platform.startswith("openbsd")
158-
- or sys.platform.startswith("dragonfly")):
159-
-
160-
- def _num_version(libname):
161-
- # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
162-
- parts = libname.split(".")
163-
- nums = []
164-
- try:
165-
- while parts:
166-
- nums.insert(0, int(parts.pop()))
167-
- except ValueError:
168-
- pass
169-
- return nums or [ sys.maxint ]
170-
-
171-
- def find_library(name):
172-
- ename = re.escape(name)
173-
- expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
174-
- f = os.popen('/sbin/ldconfig -r 2>/dev/null')
175-
- try:
176-
- data = f.read()
177-
- finally:
178-
- f.close()
179-
- res = re.findall(expr, data)
180-
- if not res:
181-
- return _get_soname(_findLib_gcc(name))
182-
- res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
183-
- return res[-1]
184-
-
185-
- else:
186-
-
187-
- def _findLib_ldconfig(name):
188-
- # XXX assuming GLIBC's ldconfig (with option -p)
189-
- expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
190-
- f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
191-
- try:
192-
- data = f.read()
193-
- finally:
194-
- f.close()
195-
- res = re.search(expr, data)
196-
- if not res:
197-
- # Hm, this works only for libs needed by the python executable.
198-
- cmd = 'ldd %s 2>/dev/null' % sys.executable
199-
- f = os.popen(cmd)
200-
- try:
201-
- data = f.read()
202-
- finally:
203-
- f.close()
204-
- res = re.search(expr, data)
205-
- if not res:
206-
- return None
207-
- return res.group(0)
208-
-
209-
- def _findSoname_ldconfig(name):
210-
- import struct
211-
- if struct.calcsize('l') == 4:
212-
- machine = os.uname()[4] + '-32'
213-
- else:
214-
- machine = os.uname()[4] + '-64'
215-
- mach_map = {
216-
- 'x86_64-64': 'libc6,x86-64',
217-
- 'ppc64-64': 'libc6,64bit',
218-
- 'sparc64-64': 'libc6,64bit',
219-
- 's390x-64': 'libc6,64bit',
220-
- 'ia64-64': 'libc6,IA-64',
221-
- }
222-
- abi_type = mach_map.get(machine, 'libc6')
223-
-
224-
- # XXX assuming GLIBC's ldconfig (with option -p)
225-
- expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
226-
- % (abi_type, re.escape(name))
227-
- f = os.popen('/sbin/ldconfig -p 2>/dev/null')
228-
- try:
229-
- data = f.read()
230-
- finally:
231-
- f.close()
232-
- res = re.search(expr, data)
233-
- if not res:
234-
- return None
235-
- return res.group(1)
236-
-
237-
- def find_library(name):
238-
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
239-
+def find_library(name):
240-
+ """ hack to find librarys for kivy and android
241-
+ split the path and get the first parts which will give us
242-
+ the app path something like /data/data/org.app.foo/"""
243-
+ app_root = os.path.abspath('./').split(os.path.sep)[0:4]
244-
+ lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib'
245-
+ for filename in os.listdir(lib_search):
246-
+ if filename.endswith('.so') and name in filename:
247-
+ return lib_search + os.path.sep + filename
248-
+ return None
249-
250-
################################################################
251-
# test code
9+
+# this test is for android specifically shoudl match here and ignore any
10+
+# of the other platform tests below
11+
+if os.name == "posix":
12+
+ def find_library(name):
13+
+ """ hack to find librarys for kivy and android
14+
+ split the path and get the first parts which will give us
15+
+ the app path something like /data/data/org.app.foo/"""
16+
+ app_root = os.path.abspath('./').split(os.path.sep)[0:4]
17+
+ lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib'
18+
+ for filename in os.listdir(lib_search):
19+
+ if filename.endswith('.so') and name in filename:
20+
+ return lib_search + os.path.sep + filename
21+
+ return None
22+
+
23+
+elif os.name == "posix" and sys.platform == "darwin":
24+
from ctypes.macholib.dyld import dyld_find as _dyld_find
25+
def find_library(name):
26+
possible = ['lib%s.dylib' % name,
27+
Only in Python-2.7.2/Lib/ctypes: util.py.save
28+
Only in Python-2.7.2/Lib/ctypes: util.py.save.1

recipes/python/recipe.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function prebuild_python() {
3232
try patch -p1 < $RECIPE_python/patches/fix-remove-corefoundation.patch
3333
try patch -p1 < $RECIPE_python/patches/fix-dynamic-lookup.patch
3434
try patch -p1 < $RECIPE_python/patches/fix-dlfcn.patch
35-
try patch -p1 < $RECIPE_python/patches/ctypes-find-library.patch
35+
try patch -p1 < $RECIPE_python/patches/ctypes-find-library.patch
3636

3737
system=$(uname -s)
3838
if [ "X$system" == "XDarwin" ]; then
@@ -106,7 +106,7 @@ function build_python() {
106106

107107
# FIXME, the first time, we got a error at:
108108
# python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
109-
# /home/tito/code/python-for-android/build/python/Python-2.7.2/python: 1: Syntax error: word unexpected (expecting ")")
109+
# /home/tito/code/python-for-android/build/python/Python-2.7.2/python: 1: Syntax error: word unexpected (expecting ")")
110110
# because at this time, python is arm, not x86. even that, why /usr/include/netinet/in.h is used ?
111111
# check if we can avoid this part.
112112

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

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

9090
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_io.so");
9191
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/unicodedata.so");
92-
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so");
92+
93+
try {
94+
System.loadLibrary("ctypes");
95+
System.load(getFilesDir() + "/lib/python2.7/lib-dynload/_ctypes.so");
96+
} catch(UnsatisfiedLinkError e) {
97+
}
9398

9499
try {
95100
System.loadLibrary("sqlite3");

0 commit comments

Comments
 (0)