Undiamond Python headers

This change gets the Python codebase into a state where it conforms to
the conventions of this codebase. It's now possible to include headers
from Python, without worrying about ordering. Python has traditionally
solved that problem by "diamonding" everything in Python.h, but that's
problematic since it means any change to any Python header invalidates
all the build artifacts. Lastly it makes tooling not work. Since it is
hard to explain to Emacs when I press C-c C-h to add an import line it
shouldn't add the header that actually defines the symbol, and instead
do follow the nonstandard Python convention.

Progress has been made on letting Python load source code from the zip
executable structure via the standard C library APIs. System calss now
recognizes zip!FILENAME alternative URIs as equivalent to zip:FILENAME
since Python uses colon as its delimiter.

Some progress has been made on embedding the notice license terms into
the Python object code. This is easier said than done since Python has
an extremely complicated ownership story.

- Some termios APIs have been added
- Implement rewinddir() dirstream API
- GetCpuCount() API added to Cosmopolitan Libc
- More bugs in Cosmopolitan Libc have been fixed
- zipobj.com now has flags for mangling the path
- Fixed bug a priori with sendfile() on certain BSDs
- Polyfill F_DUPFD and F_DUPFD_CLOEXEC across platforms
- FIOCLEX / FIONCLEX now polyfilled for fast O_CLOEXEC changes
- APE now supports a hybrid solution to no-self-modify for builds
- Many BSD-only magnums added, e.g. O_SEARCH, O_SHLOCK, SF_NODISKIO
This commit is contained in:
Justine Tunney 2021-08-12 00:42:14 -07:00
parent 20bb8db9f8
commit b420ed8248
762 changed files with 18410 additions and 53772 deletions

View file

@ -1,3 +1,25 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
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/bytesobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/osmodule.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pystate.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/weakrefobject.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
An implementation of the new I/O lib as defined by PEP 3116 - "New I/O"
@ -8,11 +30,6 @@
Mostly written by Amaury Forgeot d'Arc
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* Various interned strings */
PyObject *_PyIO_str_close;

View file

@ -1,7 +1,11 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_
#include "libc/calls/weirdtypes.h"
#include "third_party/python/Include/moduleobject.h"
#include "third_party/python/Include/object.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* clang-format off */
/*
* Declarations shared between the different parts of the io module
*/
/* ABCs */
extern PyTypeObject PyIOBase_Type;
@ -23,7 +27,7 @@ extern PyTypeObject PyIncrementalNewlineDecoder_Type;
#ifndef Py_LIMITED_API
#ifdef MS_WINDOWS
extern PyTypeObject PyWindowsConsoleIO_Type;
PyAPI_DATA(PyObject *) _PyWindowsConsoleIO_Type;
extern PyObject * _PyWindowsConsoleIO_Type;
#define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), (PyTypeObject*)_PyWindowsConsoleIO_Type))
#endif /* MS_WINDOWS */
#endif /* Py_LIMITED_API */
@ -34,10 +38,10 @@ extern int _PyIO_ConvertSsize_t(PyObject *, void *);
* with args=NULL, and return a new reference.
* BUT when args=Py_True is passed, they return a borrowed reference.
*/
extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args);
PyObject* _PyIOBase_check_readable(PyObject *, PyObject *);
PyObject* _PyIOBase_check_writable(PyObject *, PyObject *);
PyObject* _PyIOBase_check_seekable(PyObject *, PyObject *);
PyObject* _PyIOBase_check_closed(PyObject *, PyObject *);
/* Helper for finalization.
This function will revive an object ready to be deallocated and try to
@ -187,3 +191,7 @@ extern PyObject *_PyIO_empty_bytes;
extern PyObject *_PyIO_zero;
extern PyTypeObject _PyBytesIOBuffer_Type;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES__IO__IOMODULE_H_ */

View file

@ -1,4 +1,22 @@
#define PY_SSIZE_T_CLEAN
#include "libc/errno.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/memoryobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pythread.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
An implementation of Buffered I/O as defined by PEP 3116 - "New I/O"
@ -8,12 +26,6 @@
Written by Amaury Forgeot d'Arc and Antoine Pitrou
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/pythread.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/*[clinic input]
module _io
class _io._BufferedIOBase "PyObject *" "&PyBufferedIOBase_Type"

View file

@ -1,7 +1,23 @@
/* clang-format off */
#include "third_party/python/Include/Python.h"
#include "libc/assert.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/memoryobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*[clinic input]
module _io

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/
@ -129,11 +130,6 @@ PyDoc_STRVAR(_io_open__doc__,
#define _IO_OPEN_METHODDEF \
{"open", (PyCFunction)_io_open, METH_FASTCALL, _io_open__doc__},
static PyObject *
_io_open_impl(PyObject *module, PyObject *file, const char *mode,
int buffering, const char *encoding, const char *errors,
const char *newline, int closefd, PyObject *opener);
static PyObject *
_io_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/
@ -10,8 +11,6 @@ PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
#define _IO__BUFFEREDIOBASE_READINTO_METHODDEF \
{"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__},
static PyObject *
_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer);
static PyObject *
_io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/
@ -14,9 +15,6 @@ PyDoc_STRVAR(_io_FileIO_close__doc__,
#define _IO_FILEIO_CLOSE_METHODDEF \
{"close", (PyCFunction)_io_FileIO_close, METH_NOARGS, _io_FileIO_close__doc__},
static PyObject *
_io_FileIO_close_impl(fileio *self);
static PyObject *
_io_FileIO_close(fileio *self, PyObject *Py_UNUSED(ignored))
{
@ -41,10 +39,6 @@ PyDoc_STRVAR(_io_FileIO___init____doc__,
"*opener* must return an open file descriptor (passing os.open as *opener*\n"
"results in functionality similar to passing None).");
static int
_io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int closefd, PyObject *opener);
static int
_io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/
@ -11,9 +12,6 @@ PyDoc_STRVAR(_io__IOBase_tell__doc__,
#define _IO__IOBASE_TELL_METHODDEF \
{"tell", (PyCFunction)_io__IOBase_tell, METH_NOARGS, _io__IOBase_tell__doc__},
static PyObject *
_io__IOBase_tell_impl(PyObject *self);
static PyObject *
_io__IOBase_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -31,9 +29,6 @@ PyDoc_STRVAR(_io__IOBase_flush__doc__,
#define _IO__IOBASE_FLUSH_METHODDEF \
{"flush", (PyCFunction)_io__IOBase_flush, METH_NOARGS, _io__IOBase_flush__doc__},
static PyObject *
_io__IOBase_flush_impl(PyObject *self);
static PyObject *
_io__IOBase_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -51,9 +46,6 @@ PyDoc_STRVAR(_io__IOBase_close__doc__,
#define _IO__IOBASE_CLOSE_METHODDEF \
{"close", (PyCFunction)_io__IOBase_close, METH_NOARGS, _io__IOBase_close__doc__},
static PyObject *
_io__IOBase_close_impl(PyObject *self);
static PyObject *
_io__IOBase_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -72,9 +64,6 @@ PyDoc_STRVAR(_io__IOBase_seekable__doc__,
#define _IO__IOBASE_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io__IOBase_seekable, METH_NOARGS, _io__IOBase_seekable__doc__},
static PyObject *
_io__IOBase_seekable_impl(PyObject *self);
static PyObject *
_io__IOBase_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -92,9 +81,6 @@ PyDoc_STRVAR(_io__IOBase_readable__doc__,
#define _IO__IOBASE_READABLE_METHODDEF \
{"readable", (PyCFunction)_io__IOBase_readable, METH_NOARGS, _io__IOBase_readable__doc__},
static PyObject *
_io__IOBase_readable_impl(PyObject *self);
static PyObject *
_io__IOBase_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -112,9 +98,6 @@ PyDoc_STRVAR(_io__IOBase_writable__doc__,
#define _IO__IOBASE_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io__IOBase_writable, METH_NOARGS, _io__IOBase_writable__doc__},
static PyObject *
_io__IOBase_writable_impl(PyObject *self);
static PyObject *
_io__IOBase_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -132,9 +115,6 @@ PyDoc_STRVAR(_io__IOBase_fileno__doc__,
#define _IO__IOBASE_FILENO_METHODDEF \
{"fileno", (PyCFunction)_io__IOBase_fileno, METH_NOARGS, _io__IOBase_fileno__doc__},
static PyObject *
_io__IOBase_fileno_impl(PyObject *self);
static PyObject *
_io__IOBase_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -152,9 +132,6 @@ PyDoc_STRVAR(_io__IOBase_isatty__doc__,
#define _IO__IOBASE_ISATTY_METHODDEF \
{"isatty", (PyCFunction)_io__IOBase_isatty, METH_NOARGS, _io__IOBase_isatty__doc__},
static PyObject *
_io__IOBase_isatty_impl(PyObject *self);
static PyObject *
_io__IOBase_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -176,9 +153,6 @@ PyDoc_STRVAR(_io__IOBase_readline__doc__,
#define _IO__IOBASE_READLINE_METHODDEF \
{"readline", (PyCFunction)_io__IOBase_readline, METH_VARARGS, _io__IOBase_readline__doc__},
static PyObject *
_io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit);
static PyObject *
_io__IOBase_readline(PyObject *self, PyObject *args)
{
@ -208,9 +182,6 @@ PyDoc_STRVAR(_io__IOBase_readlines__doc__,
#define _IO__IOBASE_READLINES_METHODDEF \
{"readlines", (PyCFunction)_io__IOBase_readlines, METH_VARARGS, _io__IOBase_readlines__doc__},
static PyObject *
_io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint);
static PyObject *
_io__IOBase_readlines(PyObject *self, PyObject *args)
{

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/
@ -11,9 +12,6 @@ PyDoc_STRVAR(_io_StringIO_getvalue__doc__,
#define _IO_STRINGIO_GETVALUE_METHODDEF \
{"getvalue", (PyCFunction)_io_StringIO_getvalue, METH_NOARGS, _io_StringIO_getvalue__doc__},
static PyObject *
_io_StringIO_getvalue_impl(stringio *self);
static PyObject *
_io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored))
{

View file

@ -1,3 +1,10 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
Python 3
https://docs.python.org/3/license.html
╚─────────────────────────────────────────────────────────────────────────────*/
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/

View file

@ -1,3 +1,4 @@
/* clang-format off */
/*[clinic input]
preserve
[clinic start generated code]*/

View file

@ -1,12 +1,27 @@
/* clang-format off */
/* Author: Daniel Stutzbach */
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "libc/calls/calls.h"
#include "libc/errno.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/bytesobject.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
* Author: Daniel Stutzbach
*
* Known likely problems:
*
* - Files larger then 2**32-1
@ -96,8 +111,6 @@ fileio_dealloc_warn(fileio *self, PyObject *source)
static PyObject *
portable_lseek(int fd, PyObject *posobj, int whence);
static PyObject *portable_lseek(int fd, PyObject *posobj, int whence);
/* Returns 0 on success, -1 with exception set on failure. */
static int
internal_close(fileio *self)

View file

@ -1,4 +1,19 @@
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/bytearrayobject.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
An implementation of the I/O abstract base classes hierarchy
as defined by PEP 3116 - "New I/O"
@ -8,12 +23,6 @@
Written by Amaury Forgeot d'Arc and Antoine Pitrou
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/*[clinic input]
module _io
class _io._IOBase "PyObject *" "&PyIOBase_Type"

View file

@ -1,9 +1,19 @@
/* clang-format off */
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/accu.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/* Implementation note: the buffer is always at least one character longer
than the enclosed string, for proper functioning of _PyIO_find_line_ending.

View file

@ -1,4 +1,22 @@
#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"
#include "third_party/python/Include/codecs.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
An implementation of Text I/O as defined by PEP 3116 - "New I/O"
@ -7,11 +25,6 @@
Written by Amaury Forgeot d'Arc and Antoine Pitrou
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/*[clinic input]
module _io
class _io.IncrementalNewlineDecoder "nldecoder_object *" "&PyIncrementalNewlineDecoder_Type"

View file

@ -1,4 +1,7 @@
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
/*
An implementation of Windows console I/O
@ -7,10 +10,6 @@
Written by Steve Dower
*/
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* BUFSIZ determines how many characters can be typed at the console
before it starts blocking. */
#if BUFSIZ < (16*1024)
@ -399,7 +398,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
}
self->blksize = DEFAULT_BUFFER_SIZE;
memset(self->buf, 0, 4);
bzero(self->buf, 4);
if (_PyObject_SetAttrId((PyObject *)self, &PyId_name, nameobj) < 0)
goto error;
@ -1072,7 +1071,7 @@ winconsoleio_getstate(winconsoleio *self)
return NULL;
}
#include "clinic/winconsoleio.c.h"
#include "third_party/python/Modules/_io/clinic/winconsoleio.inc"
static PyMethodDef winconsoleio_methods[] = {
_IO__WINDOWSCONSOLEIO_READ_METHODDEF