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,10 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/bits/likely.h"
#include "libc/calls/calls.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/o.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/longobject.h"
@ -298,7 +302,6 @@ _PyDict_DebugMallocStats(FILE *out)
"free PyDictObject", numfree, sizeof(PyDictObject));
}
void
PyDict_Fini(void)
{
@ -335,7 +338,6 @@ dk_get_index(PyDictKeysObject *keys, Py_ssize_t i)
{
Py_ssize_t s = DK_SIZE(keys);
Py_ssize_t ix;
if (s <= 0xff) {
int8_t *indices = (int8_t*)(keys->dk_indices);
ix = indices[i];
@ -672,8 +674,7 @@ lookdict_index(PyDictKeysObject *k, Py_hash_t hash, Py_ssize_t index)
return DKIX_EMPTY;
}
}
assert(0); /* NOT REACHED */
return DKIX_ERROR;
unreachable;
}
/*
@ -811,8 +812,7 @@ top:
}
}
}
assert(0); /* NOT REACHED */
return 0;
unreachable;
}
/* Specialized version for string-only keys */
@ -885,14 +885,13 @@ lookdict_unicode(PyDictObject *mp, PyObject *key,
return ix;
}
}
assert(0); /* NOT REACHED */
return 0;
unreachable;
}
/* Faster version of lookdict_unicode when it is known that no <dummy> keys
* will be present. */
static Py_ssize_t
lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
lookdict_unicode_nodummy(PyDictObject *restrict mp, PyObject *restrict key,
Py_hash_t hash, PyObject ***value_addr,
Py_ssize_t *hashpos)
{
@ -900,29 +899,28 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
size_t mask = DK_MASK(mp->ma_keys);
Py_ssize_t ix;
PyDictKeyEntry *ep, *ep0 = DK_ENTRIES(mp->ma_keys);
assert(mp->ma_values == NULL);
/* Make sure this function doesn't have to handle non-unicode keys,
including subclasses of str; e.g., one reason to subclass
unicodes is to override __eq__, and for speed we don't cater to
that here. */
if (!PyUnicode_CheckExact(key)) {
if (UNLIKELY(!PyUnicode_CheckExact(key)) /* 0.00001% taken */) {
mp->ma_keys->dk_lookup = lookdict;
return lookdict(mp, key, hash, value_addr, hashpos);
}
i = (size_t)hash & mask;
ix = dk_get_index(mp->ma_keys, i);
assert (ix != DKIX_DUMMY);
if (ix == DKIX_EMPTY) {
assert(ix != DKIX_DUMMY);
if (UNLIKELY(ix == DKIX_EMPTY)) { /* 4% taken */
if (hashpos != NULL)
*hashpos = i;
*value_addr = NULL;
return DKIX_EMPTY;
}
ep = &ep0[ix];
assert(ep->me_key != NULL);
assert(ep->me_key);
assert(PyUnicode_CheckExact(ep->me_key));
if (ep->me_key == key ||
if (ep->me_key == key || /* 70.671% taken */
(ep->me_hash == hash && unicode_eq(ep->me_key, key))) {
if (hashpos != NULL)
*hashpos = i;
@ -933,16 +931,17 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
perturb >>= PERTURB_SHIFT;
i = mask & ((i << 2) + i + perturb + 1);
ix = dk_get_index(mp->ma_keys, i);
assert (ix != DKIX_DUMMY);
if (ix == DKIX_EMPTY) {
assert(ix != DKIX_DUMMY);
if (UNLIKELY(ix == DKIX_EMPTY)) {
if (hashpos != NULL)
*hashpos = i;
*value_addr = NULL;
return DKIX_EMPTY;
}
ep = &ep0[ix];
assert(ep->me_key != NULL && PyUnicode_CheckExact(ep->me_key));
if (ep->me_key == key ||
assert(ep->me_key);
assert(PyUnicode_CheckExact(ep->me_key));
if (LIKELY(ep->me_key == key) || /* 99.8697% taken (interning?) */
(ep->me_hash == hash && unicode_eq(ep->me_key, key))) {
if (hashpos != NULL)
*hashpos = i;
@ -950,8 +949,7 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
return ix;
}
}
assert(0); /* NOT REACHED */
return 0;
unreachable;
}
/* Version of lookdict for split tables.
@ -1017,8 +1015,7 @@ lookdict_split(PyDictObject *mp, PyObject *key,
return ix;
}
}
assert(0); /* NOT REACHED */
return 0;
unreachable;
}
int
@ -1456,10 +1453,13 @@ PyDict_GetItem(PyObject *op, PyObject *key)
else {
ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr, NULL);
if (ix < 0) {
PyErr_Clear();
/* [jart] don't clear the error if there is no error */
if (UNLIKELY(ix == DKIX_ERROR))
PyErr_Clear();
return NULL;
}
}
return *value_addr;
}
@ -1540,25 +1540,23 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key)
Py_ssize_t ix;
Py_hash_t hash;
PyObject **value_addr;
if (!PyUnicode_CheckExact(key) ||
if (UNLIKELY(!PyUnicode_CheckExact(key)) ||
(hash = ((PyASCIIObject *) key)->hash) == -1)
{
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
}
/* namespace 1: globals */
ix = globals->ma_keys->dk_lookup(globals, key, hash, &value_addr, NULL);
if (ix == DKIX_ERROR)
if (UNLIKELY(ix == DKIX_ERROR)) /* 0% taken */
return NULL;
if (ix != DKIX_EMPTY && *value_addr != NULL)
if (LIKELY(ix != DKIX_EMPTY) && /* 90.3814% taken */
LIKELY(*value_addr != NULL)) /* 100% taken */
return *value_addr;
/* namespace 2: builtins */
ix = builtins->ma_keys->dk_lookup(builtins, key, hash, &value_addr, NULL);
if (ix < 0)
if (UNLIKELY(ix < 0)) /* 5.9974e-05% taken */
return NULL;
return *value_addr;
}