Improve Libc by making Python work even better

Actually Portable Python is now outperforming the Python binaries
that come bundled with Linux distros, at things like HTTP serving.
You can now have a fully featured Python install in just one .com
file that runs on six operating systems and is about 10mb in size.
With tuning, the tiniest is ~1mb. We've got most of the libraries
working, including pysqlite, and the repl now feels very pleasant.
The things you can't do quite yet are: threads and shared objects
but that can happen in the future, if the community falls in love
with this project and wants to see it developed further. Changes:

- Add siginterrupt()
- Add sqlite3 to Python
- Add issymlink() helper
- Make GetZipCdir() faster
- Add tgamma() and finite()
- Add legacy function lutimes()
- Add readlink() and realpath()
- Use heap allocations when appropriate
- Reorganize Python into two-stage build
- Save Lua / Python shell history to dotfile
- Integrate Python Lib embedding into linkage
- Make isregularfile() and isdirectory() go faster
- Make Python shell auto-completion work perfectly
- Make crash reports work better if changed directory
- Fix Python+NT open() / access() flag overflow error
- Disable Python tests relating to \N{LONG NAME} syntax
- Have Python REPL copyright() show all notice embeddings

The biggest technical challenge at the moment is working around
when Python tries to be too clever about filenames.
This commit is contained in:
Justine Tunney 2021-08-18 14:21:30 -07:00
parent 98ccbf44b1
commit 8af197560e
179 changed files with 6728 additions and 10430 deletions

View file

@ -8,6 +8,7 @@
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/o.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/codecs.h"
@ -167,22 +168,8 @@ static long
safe_get_max_fd(void)
{
long local_max_fd;
#if defined(__NetBSD__)
local_max_fd = fcntl(0, F_MAXFD);
if (local_max_fd >= 0)
return local_max_fd;
#endif
#if defined(HAVE_SYS_RESOURCE_H) && defined(__OpenBSD__)
struct rlimit rl;
/* Not on the POSIX async signal safe functions list but likely
* safe. TODO - Someone should audit OpenBSD to make sure. */
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
return (long) rl.rlim_max;
#endif
#ifdef _SC_OPEN_MAX
local_max_fd = sysconf(_SC_OPEN_MAX);
if (local_max_fd == -1)
#endif
local_max_fd = 256; /* Matches legacy Lib/subprocess.py behavior. */
return local_max_fd;
}
@ -223,7 +210,7 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep)
}
#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
#if 0 && defined(__linux__)
/* It doesn't matter if d_name has room for NAME_MAX chars; we're using this
* only to read a directory of short file descriptor number names. The kernel
* will return an error if we didn't give it enough space. Highly Unlikely.
@ -293,7 +280,7 @@ _close_open_fds_safe(int start_fd, PyObject* py_fds_to_keep)
#define _close_open_fds _close_open_fds_safe
#else /* NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
#else /* NOT defined(__linux__) */
/* Close all open file descriptors from start_fd and higher.
@ -362,7 +349,7 @@ _close_open_fds_maybe_unsafe(long start_fd, PyObject* py_fds_to_keep)
#define _close_open_fds _close_open_fds_maybe_unsafe
#endif /* else NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
#endif /* else NOT defined(__linux__) */
/*