Productionize new APE loader and more

The APE_NO_MODIFY_SELF loader payload has been moved out of the examples
folder and improved so that it works on BSD systems, and permits general
elf program headers. This brings its quality up enough that it should be
acceptable to use by default for many programs, e.g. Python, Lua, SQLite
and Python. It's the responsibility of the user to define an appropriate
TMPDIR if /tmp is considered an adversarial environment. Mac OS shall be
supported by APE_NO_MODIFY_SELF soon.

Fixes and improvements have been made to program_executable_name as it's
now the one true way to get the absolute path of the executing image.

This change fixes a memory leak in linenoise history loading, introduced
by performance optimizations in 51904e2687
This change fixes a longstanding regression with Mach system calls, that
23ae9dfceb back in February which impacted
our sched_yield() implementation, which is why no one noticed until now.

The Blinkenlights PC emulator has been improved. We now fix rendering on
XNU and BSD by not making the assumption that the kernel terminal driver
understands UTF8 since that seems to break its internal modeling of \r\n
which is now being addressed by using \e[𝑦H instead. The paneling is now
more compact in real mode so you won't need to make your font as tiny if
you're only emulating an 8086 program. The CLMUL ISA is now emulated too

This change also makes improvement to time. CLOCK_MONOTONIC now does the
right thing on Windows NT. The nanosecond time module functions added in
Python 3.7 have been backported.

This change doubles the performance of Argon2 password stretching simply
by not using its copy_block and xor_block helper functions, as they were
trivial to inline thus resulting in us needing to iterate over each 1024
byte block four fewer times.

This change makes code size improvements. _PyUnicode_ToNumeric() was 64k
in size and now it's 10k. The CJK codec lookup tables now use lazy delta
zigzag deflate (δzd) encoding which reduces their size from 600k to 200k
plus the code bloat caused by macro abuse in _decimal.c is now addressed
so our fully-loaded statically-linked hermetically-sealed Python virtual
interpreter container is now 9.4 megs in the default build mode and 5.5m
in MODE=tiny which leaves plenty of room for chibicc.

The pydoc web server now accommodates the use case of people who work by
SSH'ing into a different machine w/ python.com -m pydoc -p8080 -h0.0.0.0

Finally Python Capsulae delenda est and won't be supported in the future
This commit is contained in:
Justine Tunney 2021-10-02 08:17:04 -07:00
parent 9cb54218ab
commit 47a53e143b
270 changed files with 214544 additions and 23331 deletions

View file

@ -6,7 +6,6 @@ COSMOPOLITAN_C_START_
/* clang-format off */
/* A label of an arc */
typedef struct {
int lb_type;
char *lb_str;
@ -15,34 +14,28 @@ typedef struct {
#define EMPTY 0 /* Label number 0 is by definition the empty label */
/* A list of labels */
typedef struct {
int ll_nlabels;
label *ll_label;
} labellist;
/* An arc from one state to another */
typedef struct {
short a_lbl; /* Label of this arc */
short a_arrow; /* State where this arc goes to */
} arc;
/* A state in a DFA */
typedef struct {
int s_narcs;
int s_narcs; /* [jart/abi] moving s_accept here saves 4k */
int s_accept; /* [optional] Nonzero for accepting state */
arc *s_arc; /* Array of arcs */
/* Optional accelerators */
int s_lower; /* Lowest label index */
int s_upper; /* Highest label index */
int *s_accel; /* Accelerator */
int s_accept; /* Nonzero for accepting state */
int s_lower; /* [optional] Lowest label index */
int s_upper; /* [optional] Highest label index */
int *s_accel; /* [optional] Accelerator */
} state;
/* A DFA */
typedef struct {
int d_type; /* Non-terminal this represents */
char *d_name; /* For printing */
@ -53,7 +46,6 @@ typedef struct {
} dfa;
/* A grammar */
typedef struct {
int g_ndfas;
dfa *g_dfa; /* Array of DFAs */
@ -62,27 +54,21 @@ typedef struct {
int g_accel; /* Set if accelerators present */
} grammar;
/* FUNCTIONS */
grammar *newgrammar(int start);
void freegrammar(grammar *g);
dfa *adddfa(grammar *g, int type, const char *name);
int addstate(dfa *d);
void addarc(dfa *d, int from, int to, int lbl);
dfa *PyGrammar_FindDFA(grammar *g, int type);
int addlabel(labellist *ll, int type, const char *str);
int findlabel(labellist *ll, int type, const char *str);
const char *PyGrammar_LabelRepr(label *lb);
void translatelabels(grammar *g);
void addfirstsets(grammar *g);
void PyGrammar_AddAccelerators(grammar *g);
grammar *newgrammar(int);
void freegrammar(grammar *);
dfa *adddfa(grammar *, int, const char *);
int addstate(dfa *);
void addarc(dfa *, int, int, int);
dfa *PyGrammar_FindDFA(grammar *, int);
int addlabel(labellist *, int, const char *);
int findlabel(labellist *, int, const char *);
const char *PyGrammar_LabelRepr(label *);
void translatelabels(grammar *);
void addfirstsets(grammar *);
void PyGrammar_AddAccelerators(grammar *);
void PyGrammar_RemoveAccelerators(grammar *);
void printgrammar(grammar *g, FILE *fp);
void printnonterminals(grammar *g, FILE *fp);
void printgrammar(grammar *, FILE *);
void printnonterminals(grammar *, FILE *);
#ifndef Py_LIMITED_API
extern grammar _PyParser_Grammar;

View file

@ -69,7 +69,7 @@ PyObject * PyLong_GetInfo(void);
/* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
_PyBytes_DecodeEscapeRecode(), etc. */
#ifndef Py_LIMITED_API
extern unsigned char _PyLong_DigitValue[256];
extern const unsigned char _PyLong_DigitValue[256];
#endif
/* _PyLong_Frexp returns a double x and an exponent e such that the

View file

@ -43,8 +43,11 @@ int _PyTime_AsTimeval(_PyTime_t, struct timeval *, _PyTime_round_t);
int _PyTime_AsTimeval_noraise(_PyTime_t, struct timeval *, _PyTime_round_t);
int _PyTime_AsTimevalTime_t(_PyTime_t, time_t *, int *, _PyTime_round_t);
int _PyTime_AsTimespec(_PyTime_t, struct timespec *);
int _PyTime_FromTimeval(_PyTime_t *, struct timeval *);
int _PyTime_FromTimespec(_PyTime_t *, struct timespec *);
_PyTime_t _PyTime_GetSystemClock(void);
_PyTime_t _PyTime_GetMonotonicClock(void);
_PyTime_t _PyTime_MulDiv(_PyTime_t, _PyTime_t, _PyTime_t);
typedef struct {
const char *implementation;
@ -55,6 +58,7 @@ typedef struct {
int _PyTime_GetSystemClockWithInfo(_PyTime_t *, _Py_clock_info_t *);
int _PyTime_GetMonotonicClockWithInfo(_PyTime_t *, _Py_clock_info_t *);
int _PyTime_GetPerfCounterWithInfo(_PyTime_t *, _Py_clock_info_t *);
int _PyTime_Init(void);
int _PyTime_localtime(time_t, struct tm *);
int _PyTime_gmtime(time_t, struct tm *);