]> sigrok.org Git - sigrok-util.git/blame - cross-compile/android/Python-3.3.3.patch
Cross-compile Python for Android.
[sigrok-util.git] / cross-compile / android / Python-3.3.3.patch
CommitLineData
2e353a08
ML
1diff --git a/Python/fileutils.c b/Python/fileutils.c
2index b7c42e8..40db4f9 100644
3--- a/Python/fileutils.c
4+++ b/Python/fileutils.c
5@@ -43,7 +43,7 @@ _Py_device_encoding(int fd)
6 Py_RETURN_NONE;
7 }
8
9-#if !defined(__APPLE__) && !defined(MS_WINDOWS)
10+#if !defined(__APPLE__) && !defined(MS_WINDOWS) && !defined(__ANDROID__)
11 extern int _Py_normalize_encoding(const char *, char *, size_t);
12
13 /* Workaround FreeBSD and OpenIndiana locale encoding issue with the C locale.
14@@ -260,7 +260,7 @@ _Py_char2wchar(const char* arg, size_t *size)
15 mbstate_t mbs;
16 #endif
17
18-#ifndef MS_WINDOWS
19+#if !(defined(MS_WINDOWS) || defined(__ANDROID__))
20 if (force_ascii == -1)
21 force_ascii = check_force_ascii();
22
23@@ -419,7 +419,7 @@ _Py_wchar2char(const wchar_t *text, size_t *error_pos)
24 size_t i, size, converted;
25 wchar_t c, buf[2];
26
27-#ifndef MS_WINDOWS
28+#if !(defined(MS_WINDOWS) || defined(__ANDROID__))
29 if (force_ascii == -1)
30 force_ascii = check_force_ascii();
31
32diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
33index a6516dc..f06c2a0 100644
34--- a/Python/formatter_unicode.c
35+++ b/Python/formatter_unicode.c
36@@ -664,6 +664,9 @@ static int
37 get_locale_info(int type, LocaleInfo *locale_info)
38 {
39 switch (type) {
40+#ifdef __ANDROID__
41+ case LT_CURRENT_LOCALE:
42+#else
43 case LT_CURRENT_LOCALE: {
44 struct lconv *locale_data = localeconv();
45 locale_info->decimal_point = PyUnicode_DecodeLocale(
46@@ -681,6 +684,7 @@ get_locale_info(int type, LocaleInfo *locale_info)
47 locale_info->grouping = locale_data->grouping;
48 break;
49 }
50+#endif
51 case LT_DEFAULT_LOCALE:
52 locale_info->decimal_point = PyUnicode_FromOrdinal('.');
53 locale_info->thousands_sep = PyUnicode_FromOrdinal(',');
54diff --git a/Python/pystrtod.c b/Python/pystrtod.c
55index 4ab8f08..22b01a1 100644
56--- a/Python/pystrtod.c
57+++ b/Python/pystrtod.c
58@@ -177,8 +177,12 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
59
60 fail_pos = NULL;
61
62+#ifdef __ANDROID__
63+ decimal_point = ".";
64+#else
65 locale_data = localeconv();
66 decimal_point = locale_data->decimal_point;
67+#endif
68 decimal_point_len = strlen(decimal_point);
69
70 assert(decimal_point_len != 0);
71@@ -378,8 +382,12 @@ PyOS_string_to_double(const char *s,
72 Py_LOCAL_INLINE(void)
73 change_decimal_from_locale_to_dot(char* buffer)
74 {
75+#ifdef __ANDROID__
76+ const char *decimal_point = ".";
77+#else
78 struct lconv *locale_data = localeconv();
79 const char *decimal_point = locale_data->decimal_point;
80+#endif
81
82 if (decimal_point[0] != '.' || decimal_point[1] != 0) {
83 size_t decimal_point_len = strlen(decimal_point);
84diff --git a/Python/pythonrun.c b/Python/pythonrun.c
85index 832df53..c43e5e9 100644
86--- a/Python/pythonrun.c
87+++ b/Python/pythonrun.c
88@@ -810,6 +810,44 @@ Py_SetPythonHome(wchar_t *home)
89 default_home = home;
90 }
91
92+#ifdef __ANDROID__
93+size_t mbstowcs(wchar_t *dest, const char * in, size_t maxlen)
94+{
95+ wchar_t *out = dest;
96+ size_t size = 0;
97+ if (in)
98+ {
99+ while(*in && size<maxlen) {
100+ if(*in < 128)
101+ *out++ = *in++;
102+ else
103+ *out++ = 0xdc00 + *in++;
104+ size += 1;
105+ }
106+ }
107+ *out = 0;
108+ return size;
109+}
110+
111+size_t wcstombs(char * dest, const wchar_t *source, size_t maxlen)
112+{
113+ wchar_t c;
114+ size_t i;
115+ for (i=0; i<maxlen && source[i]; i++)
116+ {
117+ c=source[i];
118+ if (c >= 0xdc80 && c <= 0xdcff)
119+ {
120+ /* UTF-8b surrogate */
121+ c-=0xdc00;
122+ }
123+ if (dest)
124+ dest[i]=c;
125+ }
126+ return i;
127+}
128+#endif
129+
130 wchar_t *
131 Py_GetPythonHome(void)
132 {
133--- a/configure.ac 2013-11-17 07:23:09.000000000 +0000
134+++ b/configure.ac 2013-12-05 14:27:43.166191803 +0000
135@@ -2829,7 +2829,7 @@
136 getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \
137 getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
138 if_nameindex \
139- initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mmap \
140+ initgroups kill killpg lchmod lchown localeconv lockf linkat lstat lutimes mmap \
141 memrchr mbrtowc mkdirat mkfifo \
142 mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \
143 posix_fallocate posix_fadvise pread \
144--- a/Modules/_localemodule.c 2013-12-05 14:29:33.643662167 +0000
145+++ b/Modules/_localemodule.c 2013-12-05 14:31:41.069332495 +0000
146@@ -88,6 +88,7 @@
147 return result_object;
148 }
149
150+#if defined(HAVE_LOCALECONV)
151 PyDoc_STRVAR(localeconv__doc__,
152 "() -> dict. Returns numeric and monetary locale-specific parameters.");
153
154@@ -144,6 +145,7 @@
155 Py_XDECREF(x);
156 return NULL;
157 }
158+#endif
159
160 #if defined(HAVE_WCSCOLL)
161 PyDoc_STRVAR(strcoll__doc__,
162@@ -566,8 +566,10 @@
163 static struct PyMethodDef PyLocale_Methods[] = {
164 {"setlocale", (PyCFunction) PyLocale_setlocale,
165 METH_VARARGS, setlocale__doc__},
166+#ifdef HAVE_LOCALECONV
167 {"localeconv", (PyCFunction) PyLocale_localeconv,
168 METH_NOARGS, localeconv__doc__},
169+#endif
170 #ifdef HAVE_WCSCOLL
171 {"strcoll", (PyCFunction) PyLocale_strcoll,
172 METH_VARARGS, strcoll__doc__},
173--- a/Modules/pwdmodule.c 2013-12-05 14:41:59.065464798 +0000
174+++ b/Modules/pwdmodule.c 2013-12-05 14:42:17.045681049 +0000
175@@ -76,7 +76,7 @@
176 #endif
177 PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid));
178 PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid));
179-#ifdef __VMS
180+#if defined(__VMS) || defined(__ANDROID__)
181 SETS(setIndex++, "");
182 #else
183 SETS(setIndex++, p->pw_gecos);