forked from uyjulian/switch-libpython2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpython.patch
More file actions
335 lines (302 loc) · 11 KB
/
Copy pathcpython.patch
File metadata and controls
335 lines (302 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
diff -Naur a/Include/pyport.h b/Include/pyport.h
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -838,7 +838,7 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
# error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
#endif
-#if defined(__ANDROID__) || defined(__VXWORKS__)
+#if defined(__ANDROID__) || defined(__VXWORKS__) || defined(__SWITCH__)
/* Ignore the locale encoding: force UTF-8 */
# define _Py_FORCE_UTF8_LOCALE
#endif
diff -Naur a/Lib/posixpath.py b/Lib/posixpath.py
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -60,6 +60,9 @@ def normcase(s):
def isabs(s):
"""Test whether a path is absolute"""
s = os.fspath(s)
+ if sys.platform == 'horizon':
+ i = s.find('/', 0)
+ return (i != -1 and i != 0) and s[i - 1] == ':'
sep = _get_sep(s)
return s.startswith(sep)
@@ -86,6 +89,10 @@ def join(a, *p):
path += b
else:
path += sep + b
+ if sys.platform == 'horizon':
+ i = b.find('/', 0)
+ if (i != -1 and i != 0) and b[i - 1] == ':':
+ path = b
except (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', a, *p)
raise
@@ -366,7 +373,10 @@ def normpath(path):
comps = new_comps
path = sep.join(comps)
if initial_slashes:
- path = sep*initial_slashes + path
+ if sys.platform == 'horizon':
+ path = 'sdmc:/' + path
+ else:
+ path = sep*initial_slashes + path
return path or dot
@@ -405,8 +415,13 @@ def _joinrealpath(path, rest, seen):
pardir = '..'
if isabs(rest):
- rest = rest[1:]
- path = sep
+ i = rest.find('/', 0)
+ if (sys.platform == 'horizon') and (i != -1 and i != 0) and rest[i - 1] == ':':
+ path = rest[:i + 1]
+ rest = rest[i + 1:]
+ else:
+ rest = rest[1:]
+ path = sep
while rest:
name, _, rest = rest.partition(sep)
diff -Naur a/Modules/Setup b/Modules/Setup
--- a/Modules/Setup
+++ b/Modules/Setup
@@ -103,8 +103,8 @@ PYTHONPATH=$(COREPYTHONPATH)
posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls
errno errnomodule.c # posix (UNIX) errno values
-pwd pwdmodule.c # this is needed to find out the user's home dir
- # if $HOME is not set
+#pwd pwdmodule.c # this is needed to find out the user's home dir
+# # if $HOME is not set
_sre _sre.c # Fredrik Lundh's new regular expressions
_codecs _codecsmodule.c # access to the builtin codecs and codec registry
_weakref _weakref.c # weak references
@@ -169,26 +169,26 @@ _symtable symtablemodule.c
# Modules that should always be present (non UNIX dependent):
-#array arraymodule.c # array objects
-#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
-#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
-#_contextvars _contextvarsmodule.c # Context Variables
-#_struct _struct.c # binary structure packing/unpacking
+array arraymodule.c # array objects
+cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
+math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
+_contextvars _contextvarsmodule.c # Context Variables
+_struct _struct.c # binary structure packing/unpacking
#_weakref _weakref.c # basic weak reference support
#_testcapi _testcapimodule.c # Python C API test module
#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal -DPy_BUILD_CORE_MODULE # Python internal C API test module
-#_random _randommodule.c -DPy_BUILD_CORE_MODULE # Random number generator
-#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator
-#_pickle _pickle.c # pickle accelerator
-#_datetime _datetimemodule.c # datetime accelerator
-#_zoneinfo _zoneinfo.c # zoneinfo accelerator
-#_bisect _bisectmodule.c # Bisection algorithms
-#_heapq _heapqmodule.c # Heap queue algorithm
-#_asyncio _asynciomodule.c # Fast asyncio Future
-#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups
-#_statistics _statisticsmodule.c # statistics accelerator
+_random _randommodule.c -DPy_BUILD_CORE_MODULE # Random number generator
+_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator
+_pickle _pickle.c # pickle accelerator
+_datetime _datetimemodule.c # datetime accelerator
+_zoneinfo _zoneinfo.c # zoneinfo accelerator
+_bisect _bisectmodule.c # Bisection algorithms
+_heapq _heapqmodule.c # Heap queue algorithm
+#_asyncio _asynciomodule.c # Fast asyncio Future
+_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups
+_statistics _statisticsmodule.c # statistics accelerator
-#unicodedata unicodedata.c # static Unicode character database
+unicodedata unicodedata.c # static Unicode character database
# Modules with some UNIX dependencies -- on by default:
@@ -204,10 +204,10 @@ _symtable symtablemodule.c
#mmap mmapmodule.c
# CSV file helper
-#_csv _csv.c
+_csv _csv.c
# Socket module helper for socket(2)
-#_socket socketmodule.c
+#_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
@@ -245,18 +245,18 @@ _symtable symtablemodule.c
# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321.
-#_md5 md5module.c
+_md5 md5module.c
# The _sha module implements the SHA checksum algorithms.
# (NIST's Secure Hash Algorithms.)
-#_sha1 sha1module.c
-#_sha256 sha256module.c -DPy_BUILD_CORE_BUILTIN
-#_sha512 sha512module.c -DPy_BUILD_CORE_BUILTIN
-#_sha3 _sha3/sha3module.c
+_sha1 sha1module.c
+_sha256 sha256module.c -DPy_BUILD_CORE_BUILTIN
+_sha512 sha512module.c -DPy_BUILD_CORE_BUILTIN
+_sha3 _sha3/sha3module.c
# _blake module
-#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
+_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
# The _tkinter module.
#
@@ -338,7 +338,7 @@ _symtable symtablemodule.c
# Andrew Kuchling's zlib module.
# This require zlib 1.1.3 (or later).
# See http://www.gzip.org/zlib/
-#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
+zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
# Interface to the Expat XML parser
# More information on Expat can be found at www.libexpat.org.
diff -Naur a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -1810,6 +1810,8 @@ exit:
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
+#if defined(HAVE_UMASK)
+
PyDoc_STRVAR(os_umask__doc__,
"umask($module, mask, /)\n"
"--\n"
@@ -1843,6 +1845,8 @@ exit:
return return_value;
}
+#endif /* defined(HAVE_UMASK) */
+
PyDoc_STRVAR(os_unlink__doc__,
"unlink($module, /, path, *, dir_fd=None)\n"
"--\n"
@@ -8929,6 +8933,10 @@ exit:
#define OS_SYSTEM_METHODDEF
#endif /* !defined(OS_SYSTEM_METHODDEF) */
+#ifndef OS_UMASK_METHODDEF
+ #define OS_UMASK_METHODDEF
+#endif /* !defined(OS_UMASK_METHODDEF) */
+
#ifndef OS_UNAME_METHODDEF
#define OS_UNAME_METHODDEF
#endif /* !defined(OS_UNAME_METHODDEF) */
diff -Naur a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -311,6 +311,7 @@ corresponding Unix manual entries for more information on calls.");
# define fsync _commit
# else
/* Unix functions that the configure script doesn't check for */
+# if !defined(__SWITCH__)
# ifndef __VXWORKS__
# define HAVE_EXECV 1
# define HAVE_FORK 1
@@ -329,6 +330,26 @@ corresponding Unix manual entries for more information on calls.");
# define HAVE_SYSTEM 1
# define HAVE_WAIT 1
# define HAVE_TTYNAME 1
+# else
+# ifdef HAVE_GETGROUPS
+# undef HAVE_GETGROUPS
+# endif
+# ifdef HAVE_SETGROUPS
+# undef HAVE_SETGROUPS
+# endif
+# ifdef HAVE_SYMLINK
+# undef HAVE_SYMLINK
+# endif
+# ifdef HAVE_CHROOT
+# undef HAVE_CHROOT
+# endif
+# ifdef HAVE_FDATASYNC
+# undef HAVE_FDATASYNC
+# endif
+# ifdef HAVE_FCHDIR
+# undef HAVE_FCHDIR
+# endif
+# endif /* ! __SWITCH__ */
# endif /* _MSC_VER */
#endif /* ! __WATCOMC__ || __QNX__ */
@@ -4753,6 +4774,7 @@ os_system_impl(PyObject *module, PyObject *command)
#endif /* HAVE_SYSTEM */
+#ifdef HAVE_UMASK
/*[clinic input]
os.umask
@@ -4771,6 +4793,7 @@ os_umask_impl(PyObject *module, int mask)
return posix_error();
return PyLong_FromLong((long)i);
}
+#endif /* HAVE_UMASK */
#ifdef MS_WINDOWS
diff -Naur a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -45,6 +45,10 @@
#define _Py_timezone _timezone
#define _Py_daylight _daylight
#define _Py_tzname _tzname
+#elif defined(__SWITCH__)
+#define _Py_timezone 0
+#define _Py_daylight 0
+#define _Py_tzname ((char*[]){"GMT", "UTC"}) /* XXX: dirty hack */
#else
#define _Py_timezone timezone
#define _Py_daylight daylight
diff -Naur a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -16,6 +16,9 @@
# if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY))
# include <sys/random.h>
# endif
+# ifdef __SWITCH__
+# include <switch/kernel/random.h>
+# endif
# if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL)
# include <sys/syscall.h>
# endif
@@ -517,6 +520,11 @@ pyurandom(void *buffer, Py_ssize_t size, int blocking, int raise)
return win32_urandom((unsigned char *)buffer, size, raise);
#else
+#ifdef __SWITCH__
+ randomGet(buffer, size);
+ return 0;
+#endif
+
#if defined(PY_GETRANDOM) || defined(PY_GETENTROPY)
if (HAVE_GETENTRYPY_GETRANDOM_RUNTIME) {
#ifdef PY_GETRANDOM
diff -Naur a/Python/thread_pthread.h b/Python/thread_pthread.h
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -320,7 +320,11 @@ PyThread_get_thread_ident(void)
if (!initialized)
PyThread_init_thread();
threadid = pthread_self();
+#ifdef __SWITCH__
+ return (unsigned long) threadid - 1;
+#else
return (unsigned long) threadid;
+#endif
}
#ifdef PY_HAVE_THREAD_NATIVE_ID
diff -Naur a/configure b/configure
--- a/configure
+++ b/configure
@@ -3302,8 +3302,11 @@ then
ac_sys_system=Cygwin
;;
*-*-vxworks*)
- ac_sys_system=VxWorks
- ;;
+ ac_sys_system=VxWorks
+ ;;
+ aarch64-none-elf*)
+ ac_sys_system=Horizon
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
@@ -3354,6 +3357,9 @@ if test "$cross_compiling" = yes; then
*-*-vxworks*)
_host_cpu=$host_cpu
;;
+ aarch64-none-elf*)
+ _host_cpu=$host_cpu
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"