Make numerous improvements

- Python static hello world now 1.8mb
- Python static fully loaded now 10mb
- Python HTTPS client now uses MbedTLS
- Python REPL now completes import stmts
- Increase stack size for Python for now
- Begin synthesizing posixpath and ntpath
- Restore Python \N{UNICODE NAME} support
- Restore Python NFKD symbol normalization
- Add optimized code path for Intel SHA-NI
- Get more Python unit tests passing faster
- Get Python help() pagination working on NT
- Python hashlib now supports MbedTLS PBKDF2
- Make memcpy/memmove/memcmp/bcmp/etc. faster
- Add Mersenne Twister and Vigna to LIBC_RAND
- Provide privileged __printf() for error code
- Fix zipos opendir() so that it reports ENOTDIR
- Add basic chmod() implementation for Windows NT
- Add Cosmo's best functions to Python cosmo module
- Pin function trace indent depth to that of caller
- Show memory diagram on invalid access in MODE=dbg
- Differentiate stack overflow on crash in MODE=dbg
- Add stb_truetype and tools for analyzing font files
- Upgrade to UNICODE 13 and reduce its binary footprint
- COMPILE.COM now logs resource usage of build commands
- Start implementing basic poll() support on bare metal
- Set getauxval(AT_EXECFN) to GetModuleFileName() on NT
- Add descriptions to strerror() in non-TINY build modes
- Add COUNTBRANCH() macro to help with micro-optimizations
- Make error / backtrace / asan / memory code more unbreakable
- Add fast perfect C implementation of μ-Law and a-Law audio codecs
- Make strtol() functions consistent with other libc implementations
- Improve Linenoise implementation (see also github.com/jart/bestline)
- COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
Justine Tunney 2021-09-27 22:58:51 -07:00
parent fa7b4f5bd1
commit 39bf41f4eb
806 changed files with 77494 additions and 63859 deletions

View file

@ -4,6 +4,7 @@
Python 3
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/bytesobject.h"
@ -36,10 +37,15 @@ PYTHON_PROVIDE("_sre.__name__");
PYTHON_PROVIDE("_sre.__package__");
PYTHON_PROVIDE("_sre.__spec__");
PYTHON_PROVIDE("_sre.compile");
PYTHON_PROVIDE("_sre.copyright");
PYTHON_PROVIDE("_sre.getcodesize");
PYTHON_PROVIDE("_sre.getlower");
asm(".ident\t\"\\n\\n\
SRE 2.2.2 (Python license)\\n\
Copyright 1997-2002 Secret Labs AB\"");
asm(".include \"libc/disclaimer.inc\"");
/* clang-format off */
/*
* Secret Labs' Regular Expression Engine
*
@ -77,11 +83,6 @@ PYTHON_PROVIDE("_sre.getlower");
* other compatibility work.
*/
static const char copyright[] =
" SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB ";
#define PY_SSIZE_T_CLEAN
#define SRE_CODE_BITS (8 * sizeof(SRE_CODE))
/* name of this module, minus the leading underscore */
@ -148,17 +149,25 @@ static unsigned int sre_upper(unsigned int ch)
/* locale-specific character predicates */
/* !(c & ~N) == (c < N+1) for any unsigned c, this avoids
* warnings when c's type supports only numbers < N+1 */
#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? isalnum((ch)) : 0)
#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? Py_ISALNUM((ch)) : 0)
#define SRE_LOC_IS_WORD(ch) (SRE_LOC_IS_ALNUM((ch)) || (ch) == '_')
static unsigned int sre_lower_locale(unsigned int ch)
static inline unsigned int sre_lower_locale(unsigned int ch)
{
#ifdef __COSMOPOLITAN__
return sre_lower(ch);
#else
return ((ch) < 256 ? (unsigned int)tolower((ch)) : ch);
#endif
}
static unsigned int sre_upper_locale(unsigned int ch)
static inline unsigned int sre_upper_locale(unsigned int ch)
{
#ifdef __COSMOPOLITAN__
return sre_upper(ch);
#else
return ((ch) < 256 ? (unsigned int)toupper((ch)) : ch);
#endif
}
/* unicode-specific character predicates */
@ -199,12 +208,10 @@ sre_category(SRE_CODE category, unsigned int ch)
return SRE_IS_LINEBREAK(ch);
case SRE_CATEGORY_NOT_LINEBREAK:
return !SRE_IS_LINEBREAK(ch);
case SRE_CATEGORY_LOC_WORD:
return SRE_LOC_IS_WORD(ch);
case SRE_CATEGORY_LOC_NOT_WORD:
return !SRE_LOC_IS_WORD(ch);
case SRE_CATEGORY_UNI_DIGIT:
return SRE_UNI_IS_DIGIT(ch);
case SRE_CATEGORY_UNI_NOT_DIGIT:
@ -225,8 +232,6 @@ sre_category(SRE_CODE category, unsigned int ch)
return 0;
}
/* helpers */
static void
data_stack_dealloc(SRE_STATE* state)
{
@ -2734,8 +2739,8 @@ pattern_richcompare(PyObject *lefto, PyObject *righto, int op)
produce different codes depending on the locale used to compile the
pattern when the re.LOCALE flag is used. Don't compare groups,
indexgroup nor groupindex: they are derivated from the pattern. */
cmp = (memcmp(left->code, right->code,
sizeof(left->code[0]) * left->codesize) == 0);
cmp = !bcmp(left->code, right->code,
sizeof(left->code[0]) * left->codesize);
}
if (cmp) {
cmp = PyObject_RichCompareBool(left->pattern, right->pattern,
@ -2948,7 +2953,8 @@ static struct PyModuleDef sremodule = {
NULL
};
PyMODINIT_FUNC PyInit__sre(void)
PyMODINIT_FUNC
PyInit__sre(void)
{
PyObject* m;
PyObject* d;
@ -2988,13 +2994,10 @@ PyMODINIT_FUNC PyInit__sre(void)
Py_DECREF(x);
}
x = PyUnicode_FromString(copyright);
if (x) {
PyDict_SetItemString(d, "copyright", x);
Py_DECREF(x);
}
return m;
}
/* vim:ts=4:sw=4:et
*/
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sre = {
"_sre",
PyInit__sre,
};