mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
Get more Python tests passing (#141)
This commit is contained in:
parent
916f19eea1
commit
59e1c245d1
141 changed files with 3536 additions and 1203 deletions
2
third_party/python/Lib/test/test_locale.py
vendored
2
third_party/python/Lib/test/test_locale.py
vendored
|
@ -11,7 +11,7 @@ class BaseLocalizedTest(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if sys.platform == 'darwin':
|
||||
if sys.platform in ('darwin', 'cosmo'):
|
||||
import os
|
||||
tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US")
|
||||
if int(os.uname().release.split('.')[0]) < 10:
|
||||
|
|
1
third_party/python/Modules/_math.h
vendored
1
third_party/python/Modules/_math.h
vendored
|
@ -1,5 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__MATH_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__MATH_H_
|
||||
#include "third_party/python/pyconfig.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
|
1
third_party/python/Modules/cmathmodule.c
vendored
1
third_party/python/Modules/cmathmodule.c
vendored
|
@ -6,6 +6,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
#include "third_party/python/Include/complexobject.h"
|
||||
#include "third_party/python/Include/dtoa.h"
|
||||
|
|
2
third_party/python/Modules/config.c
vendored
2
third_party/python/Modules/config.c
vendored
|
@ -89,6 +89,7 @@ extern PyObject* PyInit__codecs_tw(void);
|
|||
extern PyObject* PyInit__json(void);
|
||||
extern PyObject* PyInit__lsprof(void);
|
||||
extern PyObject* PyInit__opcode(void);
|
||||
extern PyObject* PyInit_termios(void);
|
||||
|
||||
/* -- ADDMODULE MARKER 1 -- */
|
||||
|
||||
|
@ -164,6 +165,7 @@ struct _inittab _PyImport_Inittab[] = {
|
|||
{"_json", PyInit__json},
|
||||
{"_lsprof", PyInit__lsprof},
|
||||
{"_opcode", PyInit__opcode},
|
||||
{"termios", PyInit_termios},
|
||||
|
||||
/* -- ADDMODULE MARKER 2 -- */
|
||||
|
||||
|
|
8
third_party/python/Modules/faulthandler.c
vendored
8
third_party/python/Modules/faulthandler.c
vendored
|
@ -1100,15 +1100,9 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* TODO(jart): sigaltstack */
|
||||
#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
|
||||
#define FAULTHANDLER_STACK_OVERFLOW
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
/* Issue #23654: Turn off ICC's tail call optimization for the
|
||||
* stack_overflow generator. ICC turns the recursive tail call into
|
||||
* a loop. */
|
||||
# pragma intel optimization_level 0
|
||||
#endif
|
||||
static
|
||||
uintptr_t
|
||||
stack_overflow(uintptr_t min_sp, uintptr_t max_sp, size_t *depth)
|
||||
|
|
5
third_party/python/Modules/fcntlmodule.c
vendored
5
third_party/python/Modules/fcntlmodule.c
vendored
|
@ -11,6 +11,7 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/lock.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/bytesobject.h"
|
||||
#include "third_party/python/Include/ceval.h"
|
||||
|
@ -558,10 +559,10 @@ all_ins(PyObject* m)
|
|||
|
||||
/* OS X specifics */
|
||||
#ifdef F_FULLFSYNC
|
||||
if (PyModule_AddIntMacro(m, F_FULLFSYNC)) return -1;
|
||||
if (F_FULLFSYNC && PyModule_AddIntMacro(m, F_FULLFSYNC)) return -1;
|
||||
#endif
|
||||
#ifdef F_NOCACHE
|
||||
if (PyModule_AddIntMacro(m, F_NOCACHE)) return -1;
|
||||
if (F_NOCACHE && PyModule_AddIntMacro(m, F_NOCACHE)) return -1;
|
||||
#endif
|
||||
|
||||
/* For F_{GET|SET}FL */
|
||||
|
|
74
third_party/python/Modules/posixmodule.c
vendored
74
third_party/python/Modules/posixmodule.c
vendored
|
@ -9,6 +9,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
|
@ -16,6 +17,7 @@
|
|||
#include "libc/runtime/dlfcn.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/dt.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
|
@ -6997,59 +6999,20 @@ os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
|
|||
int target_is_directory, int dir_fd)
|
||||
/*[clinic end generated code: output=08ca9f3f3cf960f6 input=e820ec4472547bc3]*/
|
||||
{
|
||||
#ifdef MS_WINDOWS
|
||||
DWORD result;
|
||||
#else
|
||||
int result;
|
||||
#endif
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
if (!check_CreateSymbolicLink()) {
|
||||
PyErr_SetString(PyExc_NotImplementedError,
|
||||
"CreateSymbolicLink functions not found");
|
||||
return NULL;
|
||||
}
|
||||
if (!win32_can_symlink) {
|
||||
PyErr_SetString(PyExc_OSError, "symbolic link privilege not held");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
_Py_BEGIN_SUPPRESS_IPH
|
||||
/* if src is a directory, ensure target_is_directory==1 */
|
||||
target_is_directory |= _check_dirW(src->wide, dst->wide);
|
||||
result = Py_CreateSymbolicLinkW(dst->wide, src->wide,
|
||||
target_is_directory);
|
||||
_Py_END_SUPPRESS_IPH
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (!result)
|
||||
return path_error2(src, dst);
|
||||
|
||||
#else
|
||||
|
||||
if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"symlink: src and dst must be the same type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
#if HAVE_SYMLINKAT
|
||||
if (dir_fd != DEFAULT_DIR_FD)
|
||||
result = symlinkat(src->narrow, dir_fd, dst->narrow);
|
||||
else
|
||||
#endif
|
||||
result = symlink(src->narrow, dst->narrow);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (result)
|
||||
return path_error2(src, dst);
|
||||
#endif
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
#endif /* HAVE_SYMLINK */
|
||||
|
@ -10718,6 +10681,7 @@ os_cpu_count_impl(PyObject *module)
|
|||
{
|
||||
int ncpu;
|
||||
ncpu = GetCpuCount();
|
||||
printf("cpu count %d\n", ncpu);
|
||||
if (ncpu >= 1)
|
||||
return PyLong_FromLong(ncpu);
|
||||
else
|
||||
|
@ -12062,34 +12026,6 @@ static PyMethodDef posix_methods[] = {
|
|||
};
|
||||
|
||||
|
||||
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
|
||||
static int
|
||||
enable_symlink()
|
||||
{
|
||||
HANDLE tok;
|
||||
TOKEN_PRIVILEGES tok_priv;
|
||||
LUID luid;
|
||||
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &tok))
|
||||
return 0;
|
||||
|
||||
if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid))
|
||||
return 0;
|
||||
|
||||
tok_priv.PrivilegeCount = 1;
|
||||
tok_priv.Privileges[0].Luid = luid;
|
||||
tok_priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
|
||||
if (!AdjustTokenPrivileges(tok, FALSE, &tok_priv,
|
||||
sizeof(TOKEN_PRIVILEGES),
|
||||
(PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL))
|
||||
return 0;
|
||||
|
||||
/* ERROR_NOT_ALL_ASSIGNED returned when the privilege can't be assigned. */
|
||||
return GetLastError() == ERROR_NOT_ALL_ASSIGNED ? 0 : 1;
|
||||
}
|
||||
#endif /* defined(HAVE_SYMLINK) && defined(MS_WINDOWS) */
|
||||
|
||||
static int
|
||||
all_ins(PyObject *m)
|
||||
{
|
||||
|
@ -12482,10 +12418,6 @@ INITFUNC(void)
|
|||
PyObject *list;
|
||||
const char * const *trace;
|
||||
|
||||
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
|
||||
win32_can_symlink = enable_symlink();
|
||||
#endif
|
||||
|
||||
m = PyModule_Create(&posixmodule);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
|
6
third_party/python/Modules/termios.c
vendored
6
third_party/python/Modules/termios.c
vendored
|
@ -24,12 +24,6 @@
|
|||
|
||||
/* termiosmodule.c -- POSIX terminal I/O module implementation. */
|
||||
|
||||
/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
|
||||
is defined, so we define it here. */
|
||||
#if defined(__sgi)
|
||||
#define CTRL(c) ((c)&037)
|
||||
#endif
|
||||
|
||||
PyDoc_STRVAR(termios__doc__,
|
||||
"This module provides an interface to the Posix calls for tty I/O control.\n\
|
||||
For a complete description of these calls, see the Posix or Unix manual\n\
|
||||
|
|
8
third_party/python/Objects/longobject.c
vendored
8
third_party/python/Objects/longobject.c
vendored
|
@ -1604,7 +1604,7 @@ long_to_decimal_string_internal(PyObject *aa,
|
|||
digit *pout, *pin, rem, tenpow;
|
||||
int negative;
|
||||
int d;
|
||||
enum PyUnicode_Kind kind = -1;
|
||||
enum PyUnicode_Kind kind = 0;
|
||||
|
||||
a = (PyLongObject *)aa;
|
||||
if (a == NULL || !PyLong_Check(a)) {
|
||||
|
@ -1696,8 +1696,6 @@ long_to_decimal_string_internal(PyObject *aa,
|
|||
kind = PyUnicode_KIND(str);
|
||||
}
|
||||
|
||||
CHECK_NE(-1, kind); /* if this fails there's a serious bug upstream */
|
||||
|
||||
#define WRITE_DIGITS(p) \
|
||||
do { \
|
||||
/* pout[0] through pout[size-2] contribute exactly \
|
||||
|
@ -1796,7 +1794,7 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
|||
PyObject *v = NULL;
|
||||
Py_ssize_t sz;
|
||||
Py_ssize_t size_a;
|
||||
enum PyUnicode_Kind kind = -1;
|
||||
enum PyUnicode_Kind kind = 0;
|
||||
int negative;
|
||||
int bits;
|
||||
|
||||
|
@ -1863,8 +1861,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
|||
kind = PyUnicode_KIND(v);
|
||||
}
|
||||
|
||||
CHECK_NE(-1, kind); /* if this fails there's a serious bug upstream */
|
||||
|
||||
#define WRITE_DIGITS(p) \
|
||||
do { \
|
||||
if (size_a == 0) { \
|
||||
|
|
4
third_party/python/Programs/python.c
vendored
4
third_party/python/Programs/python.c
vendored
|
@ -46,7 +46,7 @@ GetMember(const char *s, Py_ssize_t n, PyObject *o)
|
|||
if (v != Py_None && PyUnicode_Check(k)) {
|
||||
t = PyUnicode_AsUTF8AndSize(k, &m);
|
||||
printf("\r%`'.*s vs. %`'.*s\n", n, s, m, t);
|
||||
if (n == m && !memcmp(s, t, n)) {
|
||||
if (n == m && !memcasecmp(s, t, n)) {
|
||||
Py_INCREF(v);
|
||||
return v;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ TerminalComplete(const char *s, linenoiseCompletions *c, PyObject *o)
|
|||
for (n = strlen(s), i = 0; PyDict_Next(o, &i, &k, &v);) {
|
||||
if (v != Py_None && PyUnicode_Check(k)) {
|
||||
t = PyUnicode_AsUTF8AndSize(k, &m);
|
||||
if (m > n && !memcmp(t, s, n)) {
|
||||
if (m > n && !memcasecmp(t, s, n)) {
|
||||
c->cvec = realloc(c->cvec, ++c->len * sizeof(*c->cvec));
|
||||
c->cvec[c->len - 1] = strdup(t);
|
||||
}
|
||||
|
|
2
third_party/python/Python/sysmodule.c
vendored
2
third_party/python/Python/sysmodule.c
vendored
|
@ -7,6 +7,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/unicode/locale.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
|
@ -2216,6 +2217,7 @@ sys_update_path(int argc, wchar_t **argv)
|
|||
}
|
||||
}
|
||||
#endif /* HAVE_READLINK */
|
||||
|
||||
#if SEP == '\\' /* Special case for MS filename syntax */
|
||||
if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
|
||||
wchar_t *q;
|
||||
|
|
6
third_party/python/pyconfig.h
vendored
6
third_party/python/pyconfig.h
vendored
|
@ -408,7 +408,7 @@
|
|||
#define HAVE_GETPEERNAME 1
|
||||
|
||||
/* Define to 1 if you have the `getpgid' function. */
|
||||
/* #undef HAVE_GETPGID */
|
||||
#define HAVE_GETPGID 1
|
||||
|
||||
/* Define to 1 if you have the `getpgrp' function. */
|
||||
#define HAVE_GETPGRP 1
|
||||
|
@ -592,7 +592,7 @@
|
|||
/* #undef HAVE_LUTIMES */
|
||||
|
||||
/* Define this if you have the makedev macro. */
|
||||
/* #undef HAVE_MAKEDEV */
|
||||
#define HAVE_MAKEDEV 1
|
||||
|
||||
/* Define to 1 if you have the `mbrtowc' function. */
|
||||
#define HAVE_MBRTOWC 1
|
||||
|
@ -1486,4 +1486,6 @@
|
|||
|
||||
#define Py_NSIG 32
|
||||
|
||||
#define HAVE_SYSTEM 1
|
||||
|
||||
#endif /*Py_PYCONFIG_H*/
|
||||
|
|
7
third_party/python/python-modules.mk
vendored
7
third_party/python/python-modules.mk
vendored
|
@ -212,3 +212,10 @@ $(EXTMODULE_PYEXPAT_OBJS): \
|
|||
o/$(MODE)/third_party/python/Modules/_decimal/libmpdec/transpose.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
# Issue #23654: Turn off ICC's tail call optimization for the
|
||||
# stack_overflow generator. ICC turns the recursive tail
|
||||
# call into a loop. [Let's do GCC too, just to be safe.]
|
||||
o/$(MODE)/third_party/python/Modules/faulthandler.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-fno-optimize-sibling-calls
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue