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
276 lines (259 loc) · 8.15 KB
/
Copy pathcpython.patch
File metadata and controls
276 lines (259 loc) · 8.15 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
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index bbc2369ce7..b66f013d02 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -51,6 +51,9 @@ def normcase(s):
def isabs(s):
"""Test whether a path is absolute"""
+ if sys.platform == 'horizon':
+ i = s.find('/', 0)
+ return (i != -1 and i != 0) and s[i - 1] == ':'
return s.startswith('/')
@@ -71,6 +74,10 @@ def join(a, *p):
path += b
else:
path += '/' + b
+ if sys.platform == 'horizon':
+ i = b.find('/', 0)
+ if (i != -1 and i != 0) and b[i - 1] == ':':
+ path = b
return path
@@ -358,7 +365,10 @@ def normpath(path):
comps = new_comps
path = slash.join(comps)
if initial_slashes:
- path = slash*initial_slashes + path
+ if sys.platform == 'horizon':
+ path = 'sdmc:/' + path
+ else:
+ path = slash*initial_slashes + path
return path or dot
@@ -386,8 +396,13 @@ symbolic links encountered in the path."""
# encountered in the second path.
def _joinrealpath(path, rest, seen):
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 --git a/Modules/Setup.dist b/Modules/Setup.dist
index bbc9222129..43f3ff45e7 100644
--- a/Modules/Setup.dist
+++ b/Modules/Setup.dist
@@ -114,7 +114,7 @@ PYTHONPATH=$(COREPYTHONPATH)
posix 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
+#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
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 4fc5cee479..57573a2588 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -934,7 +934,7 @@ calibrate(void)
#endif
}
#if defined(MS_WINDOWS) || defined(PYOS_OS2) || \
- defined(__VMS) || defined (__QNX__)
+ defined(__VMS) || defined (__QNX__) || defined(__SWITCH__)
rusage_diff = -1;
#else
{
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 7a1a6945c1..0c0688976d 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -141,6 +141,7 @@ corresponding Unix manual entries for more information on calls.");
/* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
#else /* all other compilers */
/* Unix functions that the configure script doesn't check for */
+#if !defined(__SWITCH__)
#define HAVE_EXECV 1
#define HAVE_FORK 1
#if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
@@ -161,6 +162,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 /* PYOS_OS2 && PYCC_GCC && __VMS */
#endif /* _MSC_VER */
#endif /* __BORLANDC__ */
@@ -2854,6 +2875,7 @@ posix_system(PyObject *self, PyObject *args)
#endif
+#if defined(HAVE_UMASK)
PyDoc_STRVAR(posix_umask__doc__,
"umask(new_mask) -> old_mask\n\n\
Set the current numeric umask and return the previous umask.");
@@ -2869,6 +2891,7 @@ posix_umask(PyObject *self, PyObject *args)
return posix_error();
return PyInt_FromLong((long)i);
}
+#endif /* defined(HAVE_UMASK) */
PyDoc_STRVAR(posix_unlink__doc__,
@@ -8919,7 +8942,9 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_SYSTEM
{"system", posix_system, METH_VARARGS, posix_system__doc__},
#endif
+#ifdef HAVE_UMASK
{"umask", posix_umask, METH_VARARGS, posix_umask__doc__},
+#endif
#ifdef HAVE_UNAME
{"uname", posix_uname, METH_NOARGS, posix_uname__doc__},
#endif /* HAVE_UNAME */
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 61b8d612a4..ea18e5a2d6 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -808,7 +808,11 @@ inittimezone(PyObject *m) {
#ifdef PYOS_OS2
PyModule_AddIntConstant(m, "timezone", _timezone);
#else /* !PYOS_OS2 */
+#ifdef __SWITCH__
+ PyModule_AddIntConstant(m, "timezone", 0);
+#else
PyModule_AddIntConstant(m, "timezone", timezone);
+#endif /* __SWITCH__ */
#endif /* PYOS_OS2 */
#ifdef HAVE_ALTZONE
PyModule_AddIntConstant(m, "altzone", altzone);
@@ -816,12 +820,25 @@ inittimezone(PyObject *m) {
#ifdef PYOS_OS2
PyModule_AddIntConstant(m, "altzone", _timezone-3600);
#else /* !PYOS_OS2 */
+#ifdef __SWITCH__
+ PyModule_AddIntConstant(m, "altzone", 0-3600);
+#else
PyModule_AddIntConstant(m, "altzone", timezone-3600);
+#endif
#endif /* PYOS_OS2 */
#endif
+#ifdef __SWITCH__
+ PyModule_AddIntConstant(m, "daylight", 0);
+#else
PyModule_AddIntConstant(m, "daylight", daylight);
+#endif
+#ifdef __SWITCH__
+ PyModule_AddObject(m, "tzname",
+ Py_BuildValue("(zz)", "GMT", "UTC"));
+#else
PyModule_AddObject(m, "tzname",
Py_BuildValue("(zz)", tzname[0], tzname[1]));
+#endif
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
#ifdef HAVE_STRUCT_TM_TM_ZONE
{
diff --git a/Python/import.c b/Python/import.c
index b79354b37a..f963275a59 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1402,6 +1402,13 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
Py_DECREF(meta_path);
}
+ // printf("PATCH: find_module(%s)\n", fullname);
+ if (fullname != NULL && is_builtin(fullname)) {
+ // printf("PATCH: submodule %s is built-in!\n", fullname);
+ strcpy(buf, fullname);
+ return &fd_builtin;
+ }
+
if (path != NULL && PyString_Check(path)) {
/* The only type of submodule allowed inside a "frozen"
package are other frozen modules or packages. */
diff --git a/Python/random.c b/Python/random.c
index 000cb36938..c710ba95ea 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -6,6 +6,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
#endif
#ifdef Py_DEBUG
@@ -347,6 +350,9 @@ _PyOS_URandom(void *buffer, Py_ssize_t size)
#ifdef MS_WINDOWS
return win32_urandom((unsigned char *)buffer, size, 1);
+#elif defined(__SWITCH__)
+ randomGet(buffer, size);
+ return 0;
#elif defined(PY_GETENTROPY)
return py_getentropy(buffer, size, 0);
#else
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 4d792a123a..da973d7322 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -264,7 +264,11 @@ PyThread_get_thread_ident(void)
/* Jump through some hoops for Alpha OSF/1 */
threadid = pthread_self();
#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
+#ifdef __SWITCH__
+ return (long) threadid - 1;
+#else
return (long) threadid;
+#endif
#else
return (long) *(long *) &threadid;
#endif
@@ -277,6 +281,7 @@ PyThread_exit_thread(void)
if (!initialized) {
exit(0);
}
+ pthread_exit(0);
}
#ifdef USE_SEMAPHORES
diff --git a/configure b/configure
index 63d675312d..4ca558e3a6 100755
--- a/configure
+++ b/configure
@@ -3287,6 +3287,9 @@ then
*-*-cygwin*)
ac_sys_system=Cygwin
;;
+ aarch64-none-elf*)
+ ac_sys_system=Horizon
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
@@ -3333,6 +3336,9 @@ if test "$cross_compiling" = yes; then
*-*-cygwin*)
_host_cpu=
;;
+ aarch64-none-elf*)
+ _host_cpu=$host_cpu
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"