mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Make improvements
- Fix build flakes - Polyfill SIGWINCH on Windows - Fix an execve issue on Windows - Make strerror show more information - Improve cmd.exe setup/teardown on Windows - Support bracketed paste mode in Blinkenlights - Show keyboard shortcuts in Blinkenlights status bar - Fixed copy_file_range() and copyfile() w/ zip filesystem - Size optimize GetDosArgv() to keep life.com 12kb in size - Improve Blinkenlights ability to load weird ELF executables - Fix program_executable_name and add GetInterpreterExecutableName - Make Python in tiny mode fail better if docstrings are requested - Update Python test exclusions in tiny* modes such as tinylinux - Add bulletproof unbreakable kprintf() troubleshooting function - Remove "oldskool" keyword from ape.S for virus scanners - Fix issue that caused backtraces to not print sometimes - Improve Blinkenlights serial uart character i/o - Make clock_gettime() not clobber errno on xnu - Improve sha256 cpuid check for old computers - Integrate some bestline linenoise fixes - Show runit process names better in htop - Remove SIGPIPE from ShowCrashReports() - Make realpath() not clobber errno - Avoid attaching GDB on non-Linux - Improve img.com example
This commit is contained in:
parent
2a938b3eaa
commit
b45d50b690
194 changed files with 4881 additions and 2966 deletions
124
third_party/linenoise/linenoise.c
vendored
124
third_party/linenoise/linenoise.c
vendored
|
@ -131,7 +131,6 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -250,6 +249,7 @@ static char maskmode;
|
|||
static char ispaused;
|
||||
static char iscapital;
|
||||
static int historylen;
|
||||
extern bool __replmode;
|
||||
static struct linenoiseRing ring;
|
||||
static struct sigaction orig_int;
|
||||
static struct sigaction orig_quit;
|
||||
|
@ -349,6 +349,51 @@ static size_t GetFdSize(int fd) {
|
|||
return st.st_size;
|
||||
}
|
||||
|
||||
static char IsCharDev(int fd) {
|
||||
struct stat st;
|
||||
st.st_mode = 0;
|
||||
fstat(fd, &st);
|
||||
return (st.st_mode & S_IFMT) == S_IFCHR;
|
||||
}
|
||||
|
||||
static int linenoiseIsUnsupportedTerm(void) {
|
||||
int i;
|
||||
char *term;
|
||||
static char once, res;
|
||||
if (!once) {
|
||||
if ((term = getenv("TERM"))) {
|
||||
for (i = 0; i < sizeof(kUnsupported) / sizeof(*kUnsupported); i++) {
|
||||
if (!strcasecmp(term, kUnsupported[i])) {
|
||||
res = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
once = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int linenoiseIsTerminal(void) {
|
||||
static int once, res;
|
||||
if (!once) {
|
||||
res = isatty(fileno(stdin)) && isatty(fileno(stdout)) &&
|
||||
!linenoiseIsUnsupportedTerm();
|
||||
once = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int linenoiseIsTeletype(void) {
|
||||
static int once, res;
|
||||
if (!once) {
|
||||
res = linenoiseIsTerminal() ||
|
||||
(IsCharDev(fileno(stdin)) && IsCharDev(fileno(stdout)));
|
||||
once = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static char *GetLine(FILE *f) {
|
||||
ssize_t rc;
|
||||
char *p = 0;
|
||||
|
@ -420,6 +465,7 @@ static char *FormatUnsigned(char *p, unsigned x) {
|
|||
}
|
||||
|
||||
static char HasPendingInput(int fd) {
|
||||
if (IsWindows()) return 0;
|
||||
return poll((struct pollfd[]){{fd, POLLIN}}, 1, 0) == 1;
|
||||
}
|
||||
|
||||
|
@ -557,24 +603,6 @@ static void abFree(struct abuf *a) {
|
|||
free(a->b);
|
||||
}
|
||||
|
||||
static int linenoiseIsUnsupportedTerm(void) {
|
||||
int i;
|
||||
char *term;
|
||||
static char once, res;
|
||||
if (!once) {
|
||||
if ((term = getenv("TERM"))) {
|
||||
for (i = 0; i < sizeof(kUnsupported) / sizeof(*kUnsupported); i++) {
|
||||
if (!strcasecmp(term, kUnsupported[i])) {
|
||||
res = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
once = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void linenoiseUnpause(int fd) {
|
||||
if (ispaused) {
|
||||
tcflow(fd, TCOON);
|
||||
|
@ -1162,9 +1190,11 @@ StartOver:
|
|||
rune = GetUtf8(buf + i, len - i);
|
||||
if (x && x + rune.n > xn) {
|
||||
if (cy >= 0) ++cy;
|
||||
abAppends(&ab, "\033[K" /* clear line forward */
|
||||
"\r" /* start of line */
|
||||
"\n"); /* cursor down unclamped */
|
||||
if (x < xn) {
|
||||
abAppends(&ab, "\033[K"); /* clear line forward */
|
||||
}
|
||||
abAppends(&ab, "\r" /* start of line */
|
||||
"\n"); /* cursor down unclamped */
|
||||
++rows;
|
||||
x = 0;
|
||||
}
|
||||
|
@ -2010,6 +2040,26 @@ char *linenoiseRaw(const char *prompt, int infd, int outfd) {
|
|||
}
|
||||
}
|
||||
|
||||
static int linenoiseFallback(const char *prompt, char **res) {
|
||||
if (prompt && *prompt &&
|
||||
(strchr(prompt, '\n') || strchr(prompt, '\t') ||
|
||||
strchr(prompt + 1, '\r'))) {
|
||||
errno = EINVAL;
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
if (!linenoiseIsTerminal()) {
|
||||
if (prompt && *prompt && linenoiseIsTeletype()) {
|
||||
fputs(prompt, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
*res = GetLine(stdin);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads line intelligently.
|
||||
*
|
||||
|
@ -2025,24 +2075,14 @@ char *linenoiseRaw(const char *prompt, int infd, int outfd) {
|
|||
* @return chomped allocated string of read line or null on eof/error
|
||||
*/
|
||||
char *linenoise(const char *prompt) {
|
||||
if (prompt && *prompt &&
|
||||
(strchr(prompt, '\n') || strchr(prompt, '\t') ||
|
||||
strchr(prompt + 1, '\r'))) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
if ((!isatty(fileno(stdin)) || !isatty(fileno(stdout)))) {
|
||||
return GetLine(stdin);
|
||||
} else if (linenoiseIsUnsupportedTerm()) {
|
||||
if (prompt && *prompt) {
|
||||
fputs(prompt, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
return GetLine(stdin);
|
||||
} else {
|
||||
fflush(stdout);
|
||||
return linenoiseRaw(prompt, fileno(stdin), fileno(stdout));
|
||||
}
|
||||
char *res;
|
||||
if (linenoiseFallback(prompt, &res)) return res;
|
||||
fflush(stdout);
|
||||
fflush(stdout);
|
||||
__replmode = true;
|
||||
res = linenoiseRaw(prompt, fileno(stdin), fileno(stdout));
|
||||
__replmode = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2066,9 +2106,11 @@ char *linenoise(const char *prompt) {
|
|||
* @return chomped allocated string of read line or null on eof/error
|
||||
*/
|
||||
char *linenoiseWithHistory(const char *prompt, const char *prog) {
|
||||
char *line;
|
||||
char *line, *res;
|
||||
struct abuf path;
|
||||
const char *a, *b;
|
||||
if (linenoiseFallback(prompt, &res)) return res;
|
||||
fflush(stdout);
|
||||
abInit(&path);
|
||||
if (prog) {
|
||||
if (strchr(prog, '/') || strchr(prog, '.')) {
|
||||
|
|
13
third_party/mbedtls/sha256.c
vendored
13
third_party/mbedtls/sha256.c
vendored
|
@ -175,15 +175,17 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
|||
|
||||
if( !IsTiny() || X86_NEED( SHA ) )
|
||||
{
|
||||
if( X86_HAVE( SHA ) )
|
||||
if( X86_HAVE( SHA ) &&
|
||||
X86_HAVE( SSE2 ) &&
|
||||
X86_HAVE( SSSE3 ) )
|
||||
{
|
||||
if( IsAsan() )
|
||||
__asan_verify( data, 64 );
|
||||
sha256_transform_ni( ctx->state, data, 1 );
|
||||
return( 0 );
|
||||
}
|
||||
if( X86_HAVE( BMI ) &&
|
||||
X86_HAVE( BMI2 ) &&
|
||||
if( X86_HAVE( BMI2 ) &&
|
||||
X86_HAVE( AVX ) &&
|
||||
X86_HAVE( AVX2 ) )
|
||||
{
|
||||
if( IsAsan() )
|
||||
|
@ -310,7 +312,10 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
|||
|
||||
if( ilen >= 64 )
|
||||
{
|
||||
if( ( !IsTiny() || X86_NEED( SHA ) ) && X86_HAVE( SHA ) )
|
||||
if( !IsTiny() &&
|
||||
X86_HAVE( SHA ) &&
|
||||
X86_HAVE( SSE2 ) &&
|
||||
X86_HAVE( SSSE3 ) )
|
||||
{
|
||||
if( IsAsan() )
|
||||
__asan_verify( input, ilen );
|
||||
|
|
12
third_party/python/Include/ezprint.h
vendored
12
third_party/python/Include/ezprint.h
vendored
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_EZPRINT_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_EZPRINT_H_
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/bytesobject.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
|
@ -11,24 +11,24 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
static void EzPrint(PyObject *x, const char *s) {
|
||||
PyObject *u, *r, *t;
|
||||
__printf("%s = ", s);
|
||||
kprintf("%s = ", s);
|
||||
if (!s) {
|
||||
__printf("NULL");
|
||||
kprintf("NULL");
|
||||
} else {
|
||||
t = PyObject_Type(x);
|
||||
r = PyObject_Repr(t);
|
||||
u = PyUnicode_AsUTF8String(r);
|
||||
__printf("%.*s ", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
kprintf("%.*s ", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
Py_DECREF(u);
|
||||
Py_DECREF(r);
|
||||
Py_DECREF(t);
|
||||
r = PyObject_Repr(x);
|
||||
u = PyUnicode_AsUTF8String(r);
|
||||
__printf("%.*s", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
kprintf("%.*s", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
Py_DECREF(u);
|
||||
Py_DECREF(r);
|
||||
}
|
||||
__printf("\n");
|
||||
kprintf("\n");
|
||||
}
|
||||
|
||||
#define EZPRINT(x) EzPrint(x, #x)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
if __name__ != 'test.support':
|
||||
raise ImportError('support must be imported from the test package')
|
||||
|
||||
import cosmo
|
||||
import collections.abc
|
||||
import contextlib
|
||||
import datetime
|
||||
|
@ -2043,9 +2044,10 @@ def run_unittest(*classes):
|
|||
def _check_docstrings():
|
||||
"""Just used to check if docstrings are enabled"""
|
||||
|
||||
MISSING_C_DOCSTRINGS = (check_impl_detail() and
|
||||
sys.platform != 'win32' and
|
||||
not sysconfig.get_config_var('WITH_DOC_STRINGS'))
|
||||
MISSING_C_DOCSTRINGS = (cosmo.MODE.startswith('tiny') or
|
||||
(check_impl_detail() and
|
||||
sys.platform != 'win32' and
|
||||
not sysconfig.get_config_var('WITH_DOC_STRINGS')))
|
||||
|
||||
HAVE_DOCSTRINGS = (_check_docstrings.__doc__ is not None and
|
||||
not MISSING_C_DOCSTRINGS)
|
||||
|
|
2
third_party/python/Lib/test/test_bz2.py
vendored
2
third_party/python/Lib/test/test_bz2.py
vendored
|
@ -734,7 +734,7 @@ class BZ2DecompressorTest(BaseTest):
|
|||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(BZ2Decompressor(), proto)
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"TODO(jart): what's going on here?")
|
||||
def testDecompressorChunksMaxsize(self):
|
||||
bzd = BZ2Decompressor()
|
||||
|
|
3
third_party/python/Lib/test/test_class.py
vendored
3
third_party/python/Lib/test/test_class.py
vendored
|
@ -490,7 +490,8 @@ class ClassTests(unittest.TestCase):
|
|||
|
||||
self.assertRaises(TypeError, hash, C2())
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny', "no stack awareness in tiny mode")
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"no stack awareness in tiny mode")
|
||||
def testSFBug532646(self):
|
||||
# Test for SF bug 532646
|
||||
|
||||
|
|
|
@ -1152,7 +1152,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
os.listdir(__file__)
|
||||
self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception)
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"todo(jart): why is it broken")
|
||||
def test_unraisable(self):
|
||||
# Issue #22836: PyErr_WriteUnraisable() should give sensible reports
|
||||
|
@ -1186,7 +1186,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
self.assertIn("del is broken", report)
|
||||
self.assertTrue(report.endswith("\n"))
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"todo(jart): why is it broken")
|
||||
def test_unhandled(self):
|
||||
# Check for sensible reporting of unhandled exceptions
|
||||
|
|
2
third_party/python/Lib/test/test_fileio.py
vendored
2
third_party/python/Lib/test/test_fileio.py
vendored
|
@ -177,7 +177,7 @@ class AutoFileTests:
|
|||
finally:
|
||||
os.close(fd)
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny', "no stack awareness in tiny mode")
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"), "no stack awareness in tiny mode")
|
||||
def testRecursiveRepr(self):
|
||||
# Issue #25455
|
||||
with swap_attr(self.f, 'name', self.f):
|
||||
|
|
|
@ -619,7 +619,7 @@ class TestUpdateWrapper(unittest.TestCase):
|
|||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"No .py files available in Cosmo MODE=tiny")
|
||||
def test_default_update_doc(self):
|
||||
wrapper, f = self._default_update()
|
||||
|
@ -681,7 +681,7 @@ class TestUpdateWrapper(unittest.TestCase):
|
|||
@support.requires_docstrings
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE .startswith("tiny"),
|
||||
"No .py files available in Cosmo MODE=tiny")
|
||||
def test_builtin_update(self):
|
||||
# Test for bug #1576241
|
||||
|
@ -715,7 +715,7 @@ class TestWraps(TestUpdateWrapper):
|
|||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny',
|
||||
@unittest.skipIf(cosmo.MODE .startswith("tiny"),
|
||||
"No .py files available in Cosmo MODE=tiny")
|
||||
def test_default_update_doc(self):
|
||||
wrapper, _ = self._default_update()
|
||||
|
|
3
third_party/python/Lib/test/test_plistlib.py
vendored
3
third_party/python/Lib/test/test_plistlib.py
vendored
|
@ -814,7 +814,8 @@ class TestBinaryPlistlib(unittest.TestCase):
|
|||
b = plistlib.loads(plistlib.dumps(a, fmt=plistlib.FMT_BINARY))
|
||||
self.assertIs(b['x'], b)
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny', "no stack awareness in tiny mode")
|
||||
@unittest.skipIf(cosmo.MODE.startswith("tiny"),
|
||||
"no stack awareness in tiny mode")
|
||||
def test_deep_nesting(self):
|
||||
for N in [300, 100000]:
|
||||
chunks = [b'\xa1' + (i + 1).to_bytes(4, 'big') for i in range(N)]
|
||||
|
|
|
@ -131,7 +131,7 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest):
|
|||
self.assertRaises(TypeError, self.db.numeric, 'xx')
|
||||
self.assertRaises(ValueError, self.db.numeric, 'x')
|
||||
|
||||
@unittest.skipIf(cosmo.MODE == 'tiny', 'astral planes arent tiny')
|
||||
@unittest.skipIf(cosmo.MODE.startswith('tiny'), 'astral planes arent tiny')
|
||||
def test_numeric_astral(self):
|
||||
self.assertEqual(self.db.numeric('\U00020000', None), None)
|
||||
self.assertEqual(self.db.numeric('\U0001012A'), 9000)
|
||||
|
|
2
third_party/python/Modules/tlsmodule.c
vendored
2
third_party/python/Modules/tlsmodule.c
vendored
|
@ -46,7 +46,7 @@
|
|||
PYTHON_PROVIDE("tls");
|
||||
|
||||
#if 0
|
||||
#define LOG(...) __printf(__VA_ARGS__)
|
||||
#define LOG(...) kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define LOG(...) (void)0
|
||||
#endif
|
||||
|
|
5
third_party/python/launch.c
vendored
5
third_party/python/launch.c
vendored
|
@ -6,6 +6,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -94,10 +95,10 @@ ShowCrashReportHook(int err, int fd, int sig,
|
|||
{
|
||||
PyObject *str;
|
||||
PyFrameObject *frame;
|
||||
__printf("\nCalamity Occurred w/ Python\n");
|
||||
kprintf("\nCalamity Occurred w/ Python\n");
|
||||
for (frame = PyEval_GetFrame(); frame; frame = frame->f_back) {
|
||||
str = PyUnicode_AsUTF8String(frame->f_code->co_filename);
|
||||
__printf("%s:%d\n", PyBytes_AS_STRING(str), frame->f_code->co_firstlineno/* frame->f_lineno */);
|
||||
kprintf("%s:%d\n", PyBytes_AS_STRING(str), frame->f_code->co_firstlineno/* frame->f_lineno */);
|
||||
Py_DECREF(str);
|
||||
}
|
||||
}
|
||||
|
|
749
third_party/python/python.mk
vendored
749
third_party/python/python.mk
vendored
File diff suppressed because it is too large
Load diff
2
third_party/quickjs/quickjs.mk
vendored
2
third_party/quickjs/quickjs.mk
vendored
|
@ -151,7 +151,7 @@ o/$(MODE)/third_party/quickjs/qjsc.com.dbg: \
|
|||
$(THIRD_PARTY_QUICKJS) \
|
||||
o/$(MODE)/third_party/quickjs/qjsc.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
# git clone git@github.com:tc39/test262 /opt/test262
|
||||
|
|
12
third_party/sqlite3/README.cosmo
vendored
Normal file
12
third_party/sqlite3/README.cosmo
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
DESCRIPTION
|
||||
|
||||
SQLite is an embeddable SQL relational database with a ~1mb
|
||||
footprint and a wide variety of features.
|
||||
|
||||
ORIGIN
|
||||
|
||||
https://www.sqlite.org/2021/sqlite-preprocessed-3350500.zip
|
||||
|
||||
LICENSE
|
||||
|
||||
Public Domain or MIT
|
Loading…
Add table
Add a link
Reference in a new issue