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,5 +1,8 @@
#ifndef Py_PYTHONRUN_H
#define Py_PYTHONRUN_H
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyarena.h"
#include "third_party/python/Include/pystate.h"
COSMOPOLITAN_C_START_
/* clang-format off */
@ -20,44 +23,44 @@ typedef struct {
#endif
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
PyAPI_FUNC(int) PyRun_AnyFileExFlags(
int PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
int PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
int PyRun_AnyFileExFlags(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
int closeit,
PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
int PyRun_SimpleFileExFlags(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
int closeit,
PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
int PyRun_InteractiveOneFlags(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_InteractiveOneObject(
int PyRun_InteractiveOneObject(
FILE *fp,
PyObject *filename,
PyCompilerFlags *flags);
PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
int PyRun_InteractiveLoopFlags(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
PyCompilerFlags *flags);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
struct _mod * PyParser_ASTFromString(
const char *s,
const char *filename, /* decoded from the filesystem encoding */
int start,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
struct _mod * PyParser_ASTFromStringObject(
const char *s,
PyObject *filename,
int start,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
struct _mod * PyParser_ASTFromFile(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
const char* enc,
@ -67,7 +70,7 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
PyCompilerFlags *flags,
int *errcode,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
struct _mod * PyParser_ASTFromFileObject(
FILE *fp,
PyObject *filename,
const char* enc,
@ -85,21 +88,21 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
#define PyParser_SimpleParseFile(FP, S, B) \
PyParser_SimpleParseFileFlags(FP, S, B, 0)
#endif
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
struct _node * PyParser_SimpleParseStringFlags(const char *, int,
int);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
struct _node * PyParser_SimpleParseStringFlagsFilename(const char *,
const char *,
int, int);
#endif
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
struct _node * PyParser_SimpleParseFileFlags(FILE *, const char *,
int, int);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
PyObject * PyRun_StringFlags(const char *, int, PyObject *,
PyObject *, PyCompilerFlags *);
PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
PyObject * PyRun_FileExFlags(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
int start,
@ -110,36 +113,36 @@ PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
#endif
#ifdef Py_LIMITED_API
PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
PyObject * Py_CompileString(const char *, const char *, int);
#else
#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
PyObject * Py_CompileStringExFlags(
const char *str,
const char *filename, /* decoded from the filesystem encoding */
int start,
PyCompilerFlags *flags,
int optimize);
PyAPI_FUNC(PyObject *) Py_CompileStringObject(
PyObject * Py_CompileStringObject(
const char *str,
PyObject *filename, int start,
PyCompilerFlags *flags,
int optimize);
#endif
PyAPI_FUNC(struct symtable *) Py_SymtableString(
struct symtable * Py_SymtableString(
const char *str,
const char *filename, /* decoded from the filesystem encoding */
int start);
#ifndef Py_LIMITED_API
PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
struct symtable * Py_SymtableStringObject(
const char *str,
PyObject *filename,
int start);
#endif
PyAPI_FUNC(void) PyErr_Print(void);
PyAPI_FUNC(void) PyErr_PrintEx(int);
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
void PyErr_Print(void);
void PyErr_PrintEx(int);
void PyErr_Display(PyObject *, PyObject *, PyObject *);
#ifndef Py_LIMITED_API
/* Use macros for a bunch of old variants */
@ -164,12 +167,12 @@ PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
/* Stuff with no proper home (yet) */
#ifndef Py_LIMITED_API
PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
char * PyOS_Readline(FILE *, FILE *, const char *);
#endif
PyAPI_DATA(int) (*PyOS_InputHook)(void);
PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
extern int (*PyOS_InputHook)(void);
extern char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
#ifndef Py_LIMITED_API
PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
extern PyThreadState* _PyOS_ReadlineTState;
#endif
/* Stack size, in "pointers" (so we get extra safety margins
@ -184,7 +187,7 @@ PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
#ifdef USE_STACKCHECK
/* Check that we aren't overflowing our stack */
PyAPI_FUNC(int) PyOS_CheckStack(void);
int PyOS_CheckStack(void);
#endif
COSMOPOLITAN_C_END_