Perform build and magnum tuning

Building o//third_party/python now takes 5 seconds on my PC

This change works towards modifying Python to use runtime dispatching
when appropriate. For example, when loading the magnums in the socket
module, it's a good idea to check if the magnum is zero, because that
means the local system platform doesn't support it.
This commit is contained in:
Justine Tunney 2021-08-10 10:26:13 -07:00
parent ee7e296339
commit d26d7ae0e4
1028 changed files with 6576 additions and 172777 deletions

View file

@ -1,57 +1,29 @@
#ifndef Py_PYTHON_H
#define Py_PYTHON_H
/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/rand/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/o.h"
#include "third_party/python/Include/patchlevel.h"
#include "third_party/python/Include/pymacconfig.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
/* Include nearly all Python header files */
#include "patchlevel.h"
#include "pyconfig.h"
#include "pymacconfig.h"
#include <limits.h>
#ifndef UCHAR_MAX
#error "Something's broken. UCHAR_MAX should be defined in limits.h."
#endif
#if UCHAR_MAX != 255
#error "Python's source code assumes C's unsigned char is an 8-bit type."
#endif
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
#define _SGI_MP_SOURCE
#endif
#include <stdio.h>
#ifndef NULL
# error "Python.h requires that stdio.h define NULL."
#endif
#include <string.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
/* For size_t? */
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
/* CAUTION: Build setups should ensure that NDEBUG is defined on the
* compiler command line when building Python in release mode; else
* assert() calls won't be removed.
*/
#include <assert.h>
#include "pyport.h"
#include "pymacro.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/pymacro.h"
/* A convenient way for code to know if clang's memory sanitizer is enabled. */
#if defined(__has_feature)
@ -62,7 +34,7 @@
# endif
#endif
#include "pyatomic.h"
#include "third_party/python/Include/pyatomic.h"
/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.
* PYMALLOC_DEBUG is in error if pymalloc is not in use.
@ -73,76 +45,77 @@
#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)
#error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
#endif
#include "pymath.h"
#include "pytime.h"
#include "pymem.h"
#include "object.h"
#include "objimpl.h"
#include "typeslots.h"
#include "pyhash.h"
#include "third_party/python/Include/pymath.h"
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/pymem.h"
#include "pydebug.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/typeslots.h"
#include "third_party/python/Include/pyhash.h"
#include "bytearrayobject.h"
#include "bytesobject.h"
#include "unicodeobject.h"
#include "longobject.h"
#include "longintrepr.h"
#include "boolobject.h"
#include "floatobject.h"
#include "complexobject.h"
#include "rangeobject.h"
#include "memoryobject.h"
#include "tupleobject.h"
#include "listobject.h"
#include "dictobject.h"
#include "odictobject.h"
#include "enumobject.h"
#include "setobject.h"
#include "methodobject.h"
#include "moduleobject.h"
#include "funcobject.h"
#include "classobject.h"
#include "fileobject.h"
#include "pycapsule.h"
#include "traceback.h"
#include "sliceobject.h"
#include "cellobject.h"
#include "iterobject.h"
#include "genobject.h"
#include "descrobject.h"
#include "warnings.h"
#include "weakrefobject.h"
#include "structseq.h"
#include "namespaceobject.h"
#include "third_party/python/Include/pydebug.h"
#include "codecs.h"
#include "pyerrors.h"
#include "third_party/python/Include/bytearrayobject.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/longintrepr.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/complexobject.h"
#include "third_party/python/Include/rangeobject.h"
#include "third_party/python/Include/memoryobject.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/odictobject.h"
#include "third_party/python/Include/enumobject.h"
#include "third_party/python/Include/setobject.h"
#include "third_party/python/Include/methodobject.h"
#include "third_party/python/Include/moduleobject.h"
#include "third_party/python/Include/funcobject.h"
#include "third_party/python/Include/classobject.h"
#include "third_party/python/Include/fileobject.h"
#include "third_party/python/Include/pycapsule.h"
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/cellobject.h"
#include "third_party/python/Include/iterobject.h"
#include "third_party/python/Include/genobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/weakrefobject.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/namespaceobject.h"
#include "pystate.h"
#include "third_party/python/Include/codecs.h"
#include "third_party/python/Include/pyerrors.h"
#include "pyarena.h"
#include "modsupport.h"
#include "pythonrun.h"
#include "pylifecycle.h"
#include "ceval.h"
#include "sysmodule.h"
#include "osmodule.h"
#include "intrcheck.h"
#include "import.h"
#include "third_party/python/Include/pystate.h"
#include "abstract.h"
#include "bltinmodule.h"
#include "third_party/python/Include/pyarena.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/osmodule.h"
#include "third_party/python/Include/intrcheck.h"
#include "third_party/python/Include/import.h"
#include "compile.h"
#include "eval.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bltinmodule.h"
#include "pyctype.h"
#include "pystrtod.h"
#include "pystrcmp.h"
#include "dtoa.h"
#include "fileutils.h"
#include "pyfpe.h"
#include "third_party/python/Include/compile.h"
#include "third_party/python/Include/eval.h"
#include "third_party/python/Include/pyctype.h"
#include "third_party/python/Include/pystrtod.h"
#include "third_party/python/Include/pystrcmp.h"
#include "third_party/python/Include/dtoa.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/pyfpe.h"
#endif /* !Py_PYTHON_H */

View file

@ -1,8 +1,7 @@
#ifndef Py_ABSTRACTOBJECT_H
#define Py_ABSTRACTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifdef PY_SSIZE_T_CLEAN
#define PyObject_CallFunction _PyObject_CallFunction_SizeT
@ -1370,8 +1369,5 @@ PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
const Py_ssize_t *shape);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* Py_ABSTRACTOBJECT_H */

View file

@ -1,20 +1,8 @@
#ifndef Py_LIMITED_API
#ifndef Py_ACCU_H
#define Py_ACCU_H
/*** This is a private API for use by the interpreter and the stdlib.
*** Its definition may be changed or removed at any moment.
***/
/*
* A two-level accumulator of unicode objects that avoids both the overhead
* of keeping a huge number of small separate objects, and the quadratic
* behaviour of using a naive repeated concatenation scheme.
*/
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#undef small /* defined by some Windows headers */
@ -29,9 +17,6 @@ PyAPI_FUNC(PyObject *) _PyAccu_FinishAsList(_PyAccu *acc);
PyAPI_FUNC(PyObject *) _PyAccu_Finish(_PyAccu *acc);
PyAPI_FUNC(void) _PyAccu_Destroy(_PyAccu *acc);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* Py_ACCU_H */
#endif /* Py_LIMITED_API */

View file

@ -1,5 +1,6 @@
#ifndef Py_ASDL_H
#define Py_ASDL_H
/* clang-format off */
typedef PyObject * identifier;
typedef PyObject * string;

View file

@ -1,9 +1,9 @@
#ifndef Py_AST_H
#define Py_AST_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
extern int foo;
PyAPI_FUNC(int) PyAST_Validate(mod_ty);
PyAPI_FUNC(mod_ty) PyAST_FromNode(
const node *n,
@ -16,7 +16,5 @@ PyAPI_FUNC(mod_ty) PyAST_FromNodeObject(
PyObject *filename,
PyArena *arena);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_AST_H */

View file

@ -1,11 +1,7 @@
#ifndef Py_BITSET_H
#define Py_BITSET_H
#ifdef __cplusplus
extern "C" {
#endif
/* Bitset interface */
COSMOPOLITAN_C_START_
/* clang-format off */
#define BYTE char
@ -26,7 +22,5 @@ void mergebitset(bitset bs1, bitset bs2, int nbits);
#define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit))
#define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_BITSET_H */

View file

@ -1,14 +1,11 @@
#ifndef Py_BLTINMODULE_H
#define Py_BLTINMODULE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_DATA(PyTypeObject) PyFilter_Type;
PyAPI_DATA(PyTypeObject) PyMap_Type;
PyAPI_DATA(PyTypeObject) PyZip_Type;
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_BLTINMODULE_H */

View file

@ -1,11 +1,7 @@
/* Boolean object interface */
#ifndef Py_BOOLOBJECT_H
#define Py_BOOLOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_DATA(PyTypeObject) PyBool_Type;
@ -18,17 +14,15 @@ Don't forget to apply Py_INCREF() when returning either!!! */
PyAPI_DATA(struct _longobject) _Py_FalseStruct, _Py_TrueStruct;
/* Use these macros */
#define Py_False ((PyObject *) &_Py_FalseStruct)
#define Py_True ((PyObject *) &_Py_TrueStruct)
#define Py_False ((PyObject *)&_Py_FalseStruct)
#define Py_True ((PyObject *)&_Py_TrueStruct)
/* Macros for returning Py_True or Py_False, respectively */
#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
/* Function to return a bool from a C long */
PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_BOOLOBJECT_H */

View file

@ -1,12 +1,7 @@
/* ByteArray object interface */
#ifndef Py_BYTEARRAYOBJECT_H
#define Py_BYTEARRAYOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
COSMOPOLITAN_C_START_
/* clang-format off */
/* Type PyByteArrayObject represents a mutable array of bytes.
* The Python API is that of a sequence;
@ -56,7 +51,5 @@ PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
PyAPI_DATA(char) _PyByteArray_empty_string[];
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_BYTEARRAYOBJECT_H */

View file

@ -1,6 +1,7 @@
#ifndef Py_LIMITED_API
#ifndef Py_BYTES_CTYPE_H
#define Py_BYTES_CTYPE_H
/* clang-format off */
/*
* The internal implementation behind PyBytes (bytes) and PyByteArray (bytearray)

View file

@ -1,13 +1,7 @@
/* Bytes (String) object interface */
#ifndef Py_BYTESOBJECT_H
#define Py_BYTESOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
COSMOPOLITAN_C_START_
/* clang-format off */
/*
Type PyBytesObject represents a character string. An extra zero byte is
@ -218,7 +212,5 @@ PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
Py_ssize_t size);
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_BYTESOBJECT_H */

View file

@ -1,10 +1,8 @@
/* Cell object interface */
#ifndef Py_LIMITED_API
#ifndef Py_CELLOBJECT_H
#define Py_CELLOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct {
PyObject_HEAD
@ -22,8 +20,6 @@ PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
#define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_TUPLEOBJECT_H */
#endif /* Py_LIMITED_API */

View file

@ -1,9 +1,7 @@
#ifndef Py_CEVAL_H
#define Py_CEVAL_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Interface to random parts in ceval.c */
@ -232,7 +230,5 @@ PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
#define FVS_MASK 0x4
#define FVS_HAVE_SPEC 0x4
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_CEVAL_H */

View file

@ -1,13 +1,8 @@
/* Former class object interface -- now only bound methods are here */
/* Revealing some structures (not for general use) */
#ifndef Py_LIMITED_API
#ifndef Py_CLASSOBJECT_H
#define Py_CLASSOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct {
PyObject_HEAD
@ -51,8 +46,6 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
#define PyInstanceMethod_GET_FUNCTION(meth) \
(((PyInstanceMethodObject *)meth) -> func)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_CLASSOBJECT_H */
#endif /* Py_LIMITED_API */

View file

@ -1,11 +1,8 @@
/* Definitions for bytecode */
#ifndef Py_LIMITED_API
#ifndef Py_CODE_H
#define Py_CODE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef uint16_t _Py_CODEUNIT;
@ -150,8 +147,6 @@ PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
void *extra);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_CODE_H */
#endif /* Py_LIMITED_API */

View file

@ -1,8 +1,7 @@
#ifndef Py_CODECREGISTRY_H
#define Py_CODECREGISTRY_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* ------------------------------------------------------------------------
@ -234,7 +233,5 @@ PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);
PyAPI_DATA(const char *) Py_hexdigits;
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_CODECREGISTRY_H */

View file

@ -1,12 +1,14 @@
#ifndef Py_COMPILE_H
#define Py_COMPILE_H
#include "third_party/python/Include/code.h"
COSMOPOLITAN_C_START_
#define Py_single_input 256
#define Py_file_input 257
#define Py_eval_input 258
#ifndef Py_LIMITED_API
#include "code.h"
#ifdef __cplusplus
extern "C" {
#endif
/* clang-format off */
/* Public interface */
struct _node; /* Declare the existence of this type */
@ -58,16 +60,6 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
#define PY_INVALID_STACK_EFFECT INT_MAX
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
#ifdef __cplusplus
}
#endif
#endif /* !Py_LIMITED_API */
/* These definitions must match corresponding definitions in graminit.h.
There's code in compile.c that checks that they are the same. */
#define Py_single_input 256
#define Py_file_input 257
#define Py_eval_input 258
COSMOPOLITAN_C_END_
#endif /* !Py_COMPILE_H */

View file

@ -1,10 +1,7 @@
/* Complex number structure */
#ifndef Py_COMPLEXOBJECT_H
#define Py_COMPLEXOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
typedef struct {
@ -63,7 +60,5 @@ PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter(
Py_ssize_t end);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_COMPLEXOBJECT_H */

View file

@ -1,11 +1,8 @@
/* datetime.h
*/
#ifndef Py_LIMITED_API
#ifndef DATETIME_H
#define DATETIME_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Fields are packed into successive bytes, each viewed as unsigned and
* big-endian, unless otherwise noted:
@ -253,8 +250,6 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
#endif /* Py_BUILD_CORE */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif
#endif /* !Py_LIMITED_API */

View file

@ -1,9 +1,7 @@
/* Descriptors */
#ifndef Py_DESCROBJECT_H
#define Py_DESCROBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef PyObject *(*getter)(PyObject *, void *);
typedef int (*setter)(PyObject *, PyObject *, void *);
@ -100,8 +98,6 @@ PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
PyAPI_DATA(PyTypeObject) PyProperty_Type;
#ifdef __cplusplus
}
#endif
#endif /* !Py_DESCROBJECT_H */
COSMOPOLITAN_C_END_
#endif /* !Py_DESCROBJECT_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_DICTOBJECT_H
#define Py_DICTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Dictionary object type -- mapping from hashable object to object */
@ -171,7 +169,5 @@ int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name,
PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_DICTOBJECT_H */

View file

@ -1,8 +1,7 @@
#ifndef Py_LIMITED_API
#ifndef PY_NO_SHORT_FLOAT_REPR
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
@ -11,9 +10,6 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif
#endif

View file

@ -1,3 +1,5 @@
/* clang-format off */
/* Copyright (c) 2008-2009, Google Inc.
* All rights reserved.
*
@ -369,9 +371,7 @@
#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
/* Use the macros above rather than using these functions directly. */
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
void AnnotateRWLockCreate(const char *file, int line,
const volatile void *lock);
void AnnotateRWLockDestroy(const char *file, int line,
@ -455,9 +455,7 @@ void AnnotateFlushState(const char *file, int line);
*/
int RunningOnValgrind(void);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)

View file

@ -1,17 +1,10 @@
#ifndef Py_ENUMOBJECT_H
#define Py_ENUMOBJECT_H
/* Enumerate Object */
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_DATA(PyTypeObject) PyEnum_Type;
PyAPI_DATA(PyTypeObject) PyReversed_Type;
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_ENUMOBJECT_H */

View file

@ -1,8 +1,7 @@
#ifndef Py_ERRCODE_H
#define Py_ERRCODE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Error codes passed around between file input, tokenizer, parser and
@ -32,7 +31,5 @@ extern "C" {
#define E_IDENTIFIER 26 /* Invalid characters in identifier */
#define E_BADSINGLE 27 /* Ill-formed single statement input */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_ERRCODE_H */

View file

@ -1,11 +1,7 @@
/* Interface to execute compiled code */
#ifndef Py_EVAL_H
#define Py_EVAL_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
@ -21,7 +17,5 @@ PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_EVAL_H */

View file

@ -1,10 +1,7 @@
/* File object interface (what's left of it -- see io.py) */
#ifndef Py_FILEOBJECT_H
#define Py_FILEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#define PY_STDIOTEXTMODE "b"
@ -44,7 +41,5 @@ PyAPI_DATA(PyTypeObject) PyStdPrinter_Type;
#define _PyIsSelectable_fd(FD) (1)
#endif /* HAVE_SELECT */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_FILEOBJECT_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_FILEUTILS_H
#define Py_FILEUTILS_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
@ -152,8 +150,5 @@ PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_FILEUTILS_H */

View file

@ -1,15 +1,7 @@
/* Float object interface */
/*
PyFloatObject represents a (double precision) floating point number.
*/
#ifndef Py_FLOATOBJECT_H
#define Py_FLOATOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
typedef struct {
@ -124,7 +116,5 @@ PyAPI_FUNC(int) _PyFloat_FormatAdvancedWriter(
Py_ssize_t end);
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_FLOATOBJECT_H */

View file

@ -1,12 +1,8 @@
/* Frame object interface */
#ifndef Py_LIMITED_API
#ifndef Py_FRAMEOBJECT_H
#define Py_FRAMEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct {
int b_type; /* what kind of block this is */
@ -88,8 +84,6 @@ PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
/* Return the line of code the frame is currently executing. */
PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_FRAMEOBJECT_H */
#endif /* Py_LIMITED_API */

View file

@ -1,11 +1,8 @@
/* Function object interface */
#ifndef Py_LIMITED_API
#ifndef Py_FUNCOBJECT_H
#define Py_FUNCOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Function objects and code objects should not be confused with each other:
*
@ -96,8 +93,6 @@ PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_FUNCOBJECT_H */
#endif /* Py_LIMITED_API */

View file

@ -1,12 +1,8 @@
/* Generator object interface */
#ifndef Py_LIMITED_API
#ifndef Py_GENOBJECT_H
#define Py_GENOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
struct _frame; /* Avoid including frameobject.h */
@ -97,8 +93,6 @@ int PyAsyncGen_ClearFreeLists(void);
#undef _PyGenObject_HEAD
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_GENOBJECT_H */
#endif /* Py_LIMITED_API */

View file

@ -1,3 +1,4 @@
/* clang-format off */
/* Generated by Parser/pgen */
#define single_input 256

View file

@ -1,13 +1,8 @@
/* Grammar interface */
#ifndef Py_GRAMMAR_H
#define Py_GRAMMAR_H
#ifdef __cplusplus
extern "C" {
#endif
#include "bitset.h" /* Sigh... */
#include "third_party/python/Include/bitset.h"
COSMOPOLITAN_C_START_
/* clang-format off */
/* A label of an arc */
@ -88,7 +83,5 @@ void PyGrammar_RemoveAccelerators(grammar *);
void printgrammar(grammar *g, FILE *fp);
void printnonterminals(grammar *g, FILE *fp);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_GRAMMAR_H */

View file

@ -1,11 +1,7 @@
/* Module definition and import interface */
#ifndef Py_IMPORT_H
#define Py_IMPORT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyImportZip_Init(void);
@ -134,7 +130,5 @@ struct _frozen {
PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules;
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_IMPORT_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_INTRCHECK_H
#define Py_INTRCHECK_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(int) PyOS_InterruptOccurred(void);
PyAPI_FUNC(void) PyOS_InitInterrupts(void);
@ -18,7 +16,5 @@ PyAPI_FUNC(void*) _PyOS_SigintEvent(void);
#endif
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_INTRCHECK_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_ITEROBJECT_H
#define Py_ITEROBJECT_H
/* Iterators (the basic kind, over a sequence) */
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
PyAPI_DATA(PyTypeObject) PyCallIter_Type;
@ -18,8 +16,6 @@ PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_ITEROBJECT_H */

View file

@ -1,7 +1,10 @@
#ifndef Py_LISTOBJECT_H
#define Py_LISTOBJECT_H
COSMOPOLITAN_C_START_
/* clang-format off */
/* List object interface */
/* List object interface
/*
Another generally useful object type is a list of object pointers.
This is a mutable type: the list items can be changed, and items can be
added or removed. Out-of-range indices or non-list objects are ignored.
@ -13,11 +16,6 @@ inserted in the list. Similarly, PyList_GetItem does not increment the
returned item's reference count.
*/
#ifndef Py_LISTOBJECT_H
#define Py_LISTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_LIMITED_API
typedef struct {
@ -75,7 +73,5 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
#define _PyList_ITEMS(op) (((PyListObject *)(op))->ob_item)
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_LISTOBJECT_H */

View file

@ -1,10 +1,10 @@
#ifndef Py_LIMITED_API
#ifndef Py_LONGINTREPR_H
#define Py_LONGINTREPR_H
#ifdef __cplusplus
extern "C" {
#endif
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/pyport.h"
COSMOPOLITAN_C_START_
/* clang-format off */
/* This is published for the benefit of "friends" marshal.c and _decimal.c. */
@ -92,8 +92,6 @@ PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
/* Return a copy of src. */
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_LONGINTREPR_H */
#endif /* Py_LIMITED_API */

View file

@ -1,9 +1,7 @@
#ifndef Py_LONGOBJECT_H
#define Py_LONGOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Long (arbitrary precision) integer object interface */
@ -209,7 +207,5 @@ PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_LONGOBJECT_H */

View file

@ -1,11 +1,7 @@
/* Interface for marshal.c */
#ifndef Py_MARSHAL_H
#define Py_MARSHAL_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#define Py_MARSHAL_VERSION 4
@ -19,10 +15,7 @@ PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *);
PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *);
#endif
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *,
Py_ssize_t);
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *, Py_ssize_t);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_MARSHAL_H */

View file

@ -1,10 +1,7 @@
/* Memory view object. In Python this is available as "memoryview". */
#ifndef Py_MEMORYOBJECT_H
#define Py_MEMORYOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
@ -66,7 +63,5 @@ typedef struct {
} PyMemoryViewObject;
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_MEMORYOBJECT_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_METAGRAMMAR_H
#define Py_METAGRAMMAR_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#define MSTART 256
#define RULE 257
@ -12,7 +10,5 @@ extern "C" {
#define ITEM 260
#define ATOM 261
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_METAGRAMMAR_H */

View file

@ -1,11 +1,7 @@
/* Method object interface */
#ifndef Py_METHODOBJECT_H
#define Py_METHODOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* This is about the type 'builtin_function_or_method',
not Python methods in user-defined classes. See classobject.h
@ -104,7 +100,5 @@ PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out);
PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_METHODOBJECT_H */

View file

@ -1,15 +1,8 @@
#ifndef Py_MODSUPPORT_H
#define Py_MODSUPPORT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Module support interface */
#include <stdarg.h>
#pragma GCC diagnostic ignored "-Wredundant-decls"
COSMOPOLITAN_C_START_
/* clang-format off */
/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
to mean Py_ssize_t */
@ -179,7 +172,5 @@ PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
PyAPI_DATA(char *) _Py_PackageContext;
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_MODSUPPORT_H */

View file

@ -1,11 +1,7 @@
/* Module object interface */
#ifndef Py_MODULEOBJECT_H
#define Py_MODULEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_DATA(PyTypeObject) PyModule_Type;
@ -83,7 +79,5 @@ typedef struct PyModuleDef{
freefunc m_free;
} PyModuleDef;
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_MODULEOBJECT_H */

View file

@ -1,11 +1,7 @@
/* simple namespace object interface */
#ifndef NAMESPACEOBJECT_H
#define NAMESPACEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyNamespace_Type;
@ -13,7 +9,5 @@ PyAPI_DATA(PyTypeObject) _PyNamespace_Type;
PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !NAMESPACEOBJECT_H */

View file

@ -1,11 +1,7 @@
/* Parse tree node interface */
#ifndef Py_NODE_H
#define Py_NODE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct _node {
short n_type;
@ -38,7 +34,5 @@ PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);
PyAPI_FUNC(void) PyNode_ListTree(node *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_NODE_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_OBJECT_H
#define Py_OBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Object and type object interface */
@ -1072,7 +1070,5 @@ PyAPI_FUNC(void)
_PyObject_DebugTypeStats(FILE *out);
#endif /* ifndef Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_OBJECT_H */

View file

@ -1,15 +1,8 @@
/* The PyObject_ memory family: high-level object memory interfaces.
See pymem.h for the low-level PyMem_ family.
*/
#ifndef Py_OBJIMPL_H
#define Py_OBJIMPL_H
#include "pymem.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "third_party/python/Include/pymem.h"
COSMOPOLITAN_C_START_
/* clang-format off */
/* BEWARE:
@ -364,7 +357,5 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_OBJIMPL_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_ODICTOBJECT_H
#define Py_ODICTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* OrderedDict */
/* This API is optional and mostly redundant. */
@ -37,7 +35,5 @@ PyAPI_FUNC(int) PyODict_DelItem(PyObject *od, PyObject *key);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_ODICTOBJECT_H */

14
third_party/python/Include/opcode.h generated vendored
View file

@ -1,12 +1,10 @@
/* Auto-generated by Tools/scripts/generate_opcode_h.py */
#ifndef Py_OPCODE_H
#define Py_OPCODE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Auto-generated by Tools/scripts/generate_opcode_h.py */
/* Instruction opcodes for compiled code */
/* Instruction opcodes for compiled code */
#define POP_TOP 1
#define ROT_TWO 2
#define ROT_THREE 3
@ -140,7 +138,5 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE,
#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_OPCODE_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_OSDEFS_H
#define Py_OSDEFS_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Operating system dependencies */
@ -19,15 +17,6 @@ extern "C" {
#define SEP L'/'
#endif
/* Max pathname length */
#ifdef __hpux
#include <sys/param.h>
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX MAXPATHLEN
#endif
#endif
#ifndef MAXPATHLEN
#if defined(PATH_MAX) && PATH_MAX > 1024
#define MAXPATHLEN PATH_MAX
@ -41,7 +30,5 @@ extern "C" {
#define DELIM L':'
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_OSDEFS_H */

View file

@ -1,17 +1,11 @@
/* os module interface */
#ifndef Py_OSMODULE_H
#define Py_OSMODULE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
PyAPI_FUNC(PyObject *) PyOS_FSPath(PyObject *path);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_OSMODULE_H */

View file

@ -1,11 +1,8 @@
/* Parser-tokenizer link interface */
#ifndef Py_LIMITED_API
#ifndef Py_PARSETOK_H
#define Py_PARSETOK_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct {
int error;
@ -101,8 +98,6 @@ PyAPI_FUNC(node *) PyParser_ParseStringObject(
PyAPI_FUNC(void) PyParser_SetError(perrdetail *);
PyAPI_FUNC(void) PyParser_ClearError(perrdetail *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PARSETOK_H */
#endif /* !Py_LIMITED_API */

View file

@ -1,3 +1,4 @@
/* clang-format off */
/* Python version identification scheme.

View file

@ -1,9 +1,7 @@
#ifndef Py_PGEN_H
#define Py_PGEN_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Parser generator interface */
@ -12,7 +10,5 @@ extern grammar *meta_grammar(void);
struct _node;
extern grammar *pgen(struct _node *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PGEN_H */

View file

@ -1,13 +1,8 @@
#ifndef Py_PGENHEADERS_H
#define Py_PGENHEADERS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Include files and extern declarations used by most of the parser. */
#include "Python.h"
#include "third_party/python/Include/Python.h"
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
@ -37,7 +32,5 @@ PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
#define tok_dump _Py_tok_dump
#define translatelabels _Py_translatelabels
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PGENHEADERS_H */

View file

@ -1,43 +1,6 @@
#ifndef Py_CURSES_H
#define Py_CURSES_H
#ifdef __APPLE__
/*
** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
** against multiple definition of wchar_t.
*/
#ifdef _BSD_WCHAR_T_DEFINED_
#define _WCHAR_T
#endif
#endif /* __APPLE__ */
#ifdef __FreeBSD__
/*
** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
** against multiple definition of wchar_t and wint_t.
*/
#ifdef _XOPEN_SOURCE_EXTENDED
#ifndef __FreeBSD_version
#include <osreldate.h>
#endif
#if __FreeBSD_version >= 500000
#ifndef __wchar_t
#define __wchar_t
#endif
#ifndef __wint_t
#define __wint_t
#endif
#else
#ifndef _WCHAR_T
#define _WCHAR_T
#endif
#ifndef _WINT_T
#define _WINT_T
#endif
#endif
#endif
#endif
/* clang-format off */
#if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS)
/* The following definition is necessary for ncurses 5.7; without it,
@ -46,12 +9,6 @@
#define NCURSES_OPAQUE 0
#endif
#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#else
#include <curses.h>
#endif
#ifdef HAVE_NCURSES_H
/* configure was checking <curses.h>, but we will
use <ncurses.h>, which has some or all these features. */
@ -66,9 +23,7 @@
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
#define PyCurses_API_pointers 4
@ -169,10 +124,5 @@ static PyObject *PyCurses_ ## X (PyObject *self) \
Py_INCREF(Py_None); \
return Py_None; }
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !defined(Py_CURSES_H) */

View file

@ -1,64 +1,56 @@
/* An arena-like memory interface for the compiler.
*/
#ifndef Py_LIMITED_API
#ifndef Py_PYARENA_H
#define Py_PYARENA_H
COSMOPOLITAN_C_START_
/* clang-format off */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _arena PyArena;
typedef struct _arena PyArena;
/* PyArena_New() and PyArena_Free() create a new arena and free it,
respectively. Once an arena has been created, it can be used
to allocate memory via PyArena_Malloc(). Pointers to PyObject can
also be registered with the arena via PyArena_AddPyObject(), and the
arena will ensure that the PyObjects stay alive at least until
PyArena_Free() is called. When an arena is freed, all the memory it
allocated is freed, the arena releases internal references to registered
PyObject*, and none of its pointers are valid.
XXX (tim) What does "none of its pointers are valid" mean? Does it
XXX mean that pointers previously obtained via PyArena_Malloc() are
XXX no longer valid? (That's clearly true, but not sure that's what
XXX the text is trying to say.)
/* PyArena_New() and PyArena_Free() create a new arena and free it,
respectively. Once an arena has been created, it can be used
to allocate memory via PyArena_Malloc(). Pointers to PyObject can
also be registered with the arena via PyArena_AddPyObject(), and the
arena will ensure that the PyObjects stay alive at least until
PyArena_Free() is called. When an arena is freed, all the memory it
allocated is freed, the arena releases internal references to registered
PyObject*, and none of its pointers are valid.
XXX (tim) What does "none of its pointers are valid" mean? Does it
XXX mean that pointers previously obtained via PyArena_Malloc() are
XXX no longer valid? (That's clearly true, but not sure that's what
XXX the text is trying to say.)
PyArena_New() returns an arena pointer. On error, it
returns a negative number and sets an exception.
XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
XXX and looks like it may or may not set an exception (e.g., if the
XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
XXX and an exception is set; OTOH, if the internal
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
XXX an exception is not set in that case).
*/
PyAPI_FUNC(PyArena *) PyArena_New(void);
PyAPI_FUNC(void) PyArena_Free(PyArena *);
PyArena_New() returns an arena pointer. On error, it
returns a negative number and sets an exception.
XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
XXX and looks like it may or may not set an exception (e.g., if the
XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
XXX and an exception is set; OTOH, if the internal
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
XXX an exception is not set in that case).
*/
PyAPI_FUNC(PyArena *) PyArena_New(void);
PyAPI_FUNC(void) PyArena_Free(PyArena *);
/* Mostly like malloc(), return the address of a block of memory spanning
* `size` bytes, or return NULL (without setting an exception) if enough
* new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
* size=0 does not guarantee to return a unique pointer (the pointer
* returned may equal one or more other pointers obtained from
* PyArena_Malloc()).
* Note that pointers obtained via PyArena_Malloc() must never be passed to
* the system free() or realloc(), or to any of Python's similar memory-
* management functions. PyArena_Malloc()-obtained pointers remain valid
* until PyArena_Free(ar) is called, at which point all pointers obtained
* from the arena `ar` become invalid simultaneously.
*/
PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
/* Mostly like malloc(), return the address of a block of memory spanning
* `size` bytes, or return NULL (without setting an exception) if enough
* new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
* size=0 does not guarantee to return a unique pointer (the pointer
* returned may equal one or more other pointers obtained from
* PyArena_Malloc()).
* Note that pointers obtained via PyArena_Malloc() must never be passed to
* the system free() or realloc(), or to any of Python's similar memory-
* management functions. PyArena_Malloc()-obtained pointers remain valid
* until PyArena_Free(ar) is called, at which point all pointers obtained
* from the arena `ar` become invalid simultaneously.
*/
PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
/* This routine isn't a proper arena allocation routine. It takes
* a PyObject* and records it so that it can be DECREFed when the
* arena is freed.
*/
PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
#ifdef __cplusplus
}
#endif
/* This routine isn't a proper arena allocation routine. It takes
* a PyObject* and records it so that it can be DECREFed when the
* arena is freed.
*/
PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
COSMOPOLITAN_C_END_
#endif /* !Py_PYARENA_H */
#endif /* Py_LIMITED_API */

View file

@ -1,14 +1,9 @@
#ifndef Py_ATOMIC_H
#define Py_ATOMIC_H
#ifdef Py_BUILD_CORE
#include "dynamic_annotations.h"
#include "pyconfig.h"
#if defined(HAVE_STD_ATOMIC)
#include <stdatomic.h>
#endif
#include "third_party/python/Include/dynamic_annotations.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
/* This is modeled after the atomics interface from C1x, according to
* the draft at

View file

@ -1,3 +1,7 @@
#ifndef Py_CAPSULE_H
#define Py_CAPSULE_H
COSMOPOLITAN_C_START_
/* clang-format off */
/* Capsule objects let you wrap a C "void *" pointer in a Python
object. They're a way of passing data through the Python interpreter
@ -12,12 +16,6 @@
documentation.
*/
#ifndef Py_CAPSULE_H
#define Py_CAPSULE_H
#ifdef __cplusplus
extern "C" {
#endif
PyAPI_DATA(PyTypeObject) PyCapsule_Type;
typedef void (*PyCapsule_Destructor)(PyObject *);
@ -52,8 +50,5 @@ PyAPI_FUNC(void *) PyCapsule_Import(
const char *name, /* UTF-8 encoded string */
int no_block);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_CAPSULE_H */

View file

@ -1,6 +1,7 @@
#ifndef Py_LIMITED_API
#ifndef PYCTYPE_H
#define PYCTYPE_H
/* clang-format off */
#define PY_CTF_LOWER 0x01
#define PY_CTF_UPPER 0x02

View file

@ -1,9 +1,8 @@
#ifndef Py_LIMITED_API
#ifndef Py_PYDEBUG_H
#define Py_PYDEBUG_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* These global variable are defined in pylifecycle.c */
/* XXX (ncoghlan): move these declarations to pylifecycle.h? */
@ -33,8 +32,6 @@ PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
PYTHONPATH and PYTHONHOME from the environment */
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYDEBUG_H */
#endif /* Py_LIMITED_API */

View file

@ -1,19 +0,0 @@
/* Python DTrace provider */
provider python {
probe function__entry(const char *, const char *, int);
probe function__return(const char *, const char *, int);
probe instance__new__start(const char *, const char *);
probe instance__new__done(const char *, const char *);
probe instance__delete__start(const char *, const char *);
probe instance__delete__done(const char *, const char *);
probe line(const char *, const char *, int);
probe gc__start(int);
probe gc__done(long);
};
#pragma D attributes Evolving/Evolving/Common provider python provider
#pragma D attributes Evolving/Evolving/Common provider python module
#pragma D attributes Evolving/Evolving/Common provider python function
#pragma D attributes Evolving/Evolving/Common provider python name
#pragma D attributes Evolving/Evolving/Common provider python args

View file

@ -1,13 +1,8 @@
/* Static DTrace probes interface */
#ifndef Py_DTRACE_H
#define Py_DTRACE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
#ifdef WITH_DTRACE
#include "pydtrace_probes.h"
/* pydtrace_probes.h, on systems with DTrace, is auto-generated to include
@ -25,29 +20,56 @@ extern "C" {
/* Without DTrace, compile to nothing. */
static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) {}
static inline void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1, int arg2) {}
static inline void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1, int arg2) {}
static inline void PyDTrace_GC_START(int arg0) {}
static inline void PyDTrace_GC_DONE(int arg0) {}
static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {}
static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {}
static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {}
static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {}
static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) {
}
static inline void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1,
int arg2) {
}
static inline void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1,
int arg2) {
}
static inline void PyDTrace_GC_START(int arg0) {
}
static inline void PyDTrace_GC_DONE(int arg0) {
}
static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {
}
static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {
}
static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {
}
static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {
}
static inline int PyDTrace_LINE_ENABLED(void) { return 0; }
static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) { return 0; }
static inline int PyDTrace_FUNCTION_RETURN_ENABLED(void) { return 0; }
static inline int PyDTrace_GC_START_ENABLED(void) { return 0; }
static inline int PyDTrace_GC_DONE_ENABLED(void) { return 0; }
static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) { return 0; }
static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) { return 0; }
static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) { return 0; }
static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) { return 0; }
static inline int PyDTrace_LINE_ENABLED(void) {
return 0;
}
static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) {
return 0;
}
static inline int PyDTrace_FUNCTION_RETURN_ENABLED(void) {
return 0;
}
static inline int PyDTrace_GC_START_ENABLED(void) {
return 0;
}
static inline int PyDTrace_GC_DONE_ENABLED(void) {
return 0;
}
static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) {
return 0;
}
static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) {
return 0;
}
static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) {
return 0;
}
static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) {
return 0;
}
#endif /* !WITH_DTRACE */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_DTRACE_H */

View file

@ -1,10 +1,7 @@
#ifndef Py_ERRORS_H
#define Py_ERRORS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Error objects */
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
/* PyException_HEAD defines the initial segment of every exception class. */
@ -491,13 +488,10 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
# define vsnprintf _vsnprintf
#endif
#include <stdarg.h>
PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_ERRORS_H */

View file

@ -1,3 +1,4 @@
/* clang-format off */
/* Stuff to export relevant 'expat' entry points from pyexpat to other
* parser modules, such as cElementTree. */

View file

@ -1,176 +1,21 @@
#ifndef Py_PYFPE_H
#define Py_PYFPE_H
#ifdef __cplusplus
extern "C" {
#endif
/*
---------------------------------------------------------------------
/ Copyright (c) 1996. \
| The Regents of the University of California. |
| All rights reserved. |
| |
| Permission to use, copy, modify, and distribute this software for |
| any purpose without fee is hereby granted, provided that this en- |
| tire notice is included in all copies of any software which is or |
| includes a copy or modification of this software and in all |
| copies of the supporting documentation for such software. |
| |
| This work was produced at the University of California, Lawrence |
| Livermore National Laboratory under contract no. W-7405-ENG-48 |
| between the U.S. Department of Energy and The Regents of the |
| University of California for the operation of UC LLNL. |
| |
| DISCLAIMER |
| |
| This software was prepared as an account of work sponsored by an |
| agency of the United States Government. Neither the United States |
| Government nor the University of California nor any of their em- |
| ployees, makes any warranty, express or implied, or assumes any |
| liability or responsibility for the accuracy, completeness, or |
| usefulness of any information, apparatus, product, or process |
| disclosed, or represents that its use would not infringe |
| privately-owned rights. Reference herein to any specific commer- |
| cial products, process, or service by trade name, trademark, |
| manufacturer, or otherwise, does not necessarily constitute or |
| imply its endorsement, recommendation, or favoring by the United |
| States Government or the University of California. The views and |
| opinions of authors expressed herein do not necessarily state or |
| reflect those of the United States Government or the University |
| of California, and shall not be used for advertising or product |
\ endorsement purposes. /
---------------------------------------------------------------------
*/
/*
* Define macros for handling SIGFPE.
* Lee Busby, LLNL, November, 1996
* busby1@llnl.gov
*
*********************************************
* Overview of the system for handling SIGFPE:
*
* This file (Include/pyfpe.h) defines a couple of "wrapper" macros for
* insertion into your Python C code of choice. Their proper use is
* discussed below. The file Python/pyfpe.c defines a pair of global
* variables PyFPE_jbuf and PyFPE_counter which are used by the signal
* handler for SIGFPE to decide if a particular exception was protected
* by the macros. The signal handler itself, and code for enabling the
* generation of SIGFPE in the first place, is in a (new) Python module
* named fpectl. This module is standard in every respect. It can be loaded
* either statically or dynamically as you choose, and like any other
* Python module, has no effect until you import it.
*
* In the general case, there are three steps toward handling SIGFPE in any
* Python code:
*
* 1) Add the *_PROTECT macros to your C code as required to protect
* dangerous floating point sections.
*
* 2) Turn on the inclusion of the code by adding the ``--with-fpectl''
* flag at the time you run configure. If the fpectl or other modules
* which use the *_PROTECT macros are to be dynamically loaded, be
* sure they are compiled with WANT_SIGFPE_HANDLER defined.
*
* 3) When python is built and running, import fpectl, and execute
* fpectl.turnon_sigfpe(). This sets up the signal handler and enables
* generation of SIGFPE whenever an exception occurs. From this point
* on, any properly trapped SIGFPE should result in the Python
* FloatingPointError exception.
*
* Step 1 has been done already for the Python kernel code, and should be
* done soon for the NumPy array package. Step 2 is usually done once at
* python install time. Python's behavior with respect to SIGFPE is not
* changed unless you also do step 3. Thus you can control this new
* facility at compile time, or run time, or both.
*
********************************
* Using the macros in your code:
*
* static PyObject *foobar(PyObject *self,PyObject *args)
* {
* ....
* PyFPE_START_PROTECT("Error in foobar", return 0)
* result = dangerous_op(somearg1, somearg2, ...);
* PyFPE_END_PROTECT(result)
* ....
* }
*
* If a floating point error occurs in dangerous_op, foobar returns 0 (NULL),
* after setting the associated value of the FloatingPointError exception to
* "Error in foobar". ``Dangerous_op'' can be a single operation, or a block
* of code, function calls, or any combination, so long as no alternate
* return is possible before the PyFPE_END_PROTECT macro is reached.
*
* The macros can only be used in a function context where an error return
* can be recognized as signaling a Python exception. (Generally, most
* functions that return a PyObject * will qualify.)
*
* Guido's original design suggestion for PyFPE_START_PROTECT and
* PyFPE_END_PROTECT had them open and close a local block, with a locally
* defined jmp_buf and jmp_buf pointer. This would allow recursive nesting
* of the macros. The Ansi C standard makes it clear that such local
* variables need to be declared with the "volatile" type qualifier to keep
* setjmp from corrupting their values. Some current implementations seem
* to be more restrictive. For example, the HPUX man page for setjmp says
*
* Upon the return from a setjmp() call caused by a longjmp(), the
* values of any non-static local variables belonging to the routine
* from which setjmp() was called are undefined. Code which depends on
* such values is not guaranteed to be portable.
*
* I therefore decided on a more limited form of nesting, using a counter
* variable (PyFPE_counter) to keep track of any recursion. If an exception
* occurs in an ``inner'' pair of macros, the return will apparently
* come from the outermost level.
*
*/
COSMOPOLITAN_C_START_
/* clang-format off */
#ifdef WANT_SIGFPE_HANDLER
#include <signal.h>
#include <setjmp.h>
#include <math.h>
extern jmp_buf PyFPE_jbuf;
extern int PyFPE_counter;
extern double PyFPE_dummy(void *);
#define PyFPE_START_PROTECT(err_string, leave_stmt) \
if (!PyFPE_counter++ && setjmp(PyFPE_jbuf)) { \
PyErr_SetString(PyExc_FloatingPointError, err_string); \
PyFPE_counter = 0; \
leave_stmt; \
}
/*
* This (following) is a heck of a way to decrement a counter. However,
* unless the macro argument is provided, code optimizers will sometimes move
* this statement so that it gets executed *before* the unsafe expression
* which we're trying to protect. That pretty well messes things up,
* of course.
*
* If the expression(s) you're trying to protect don't happen to return a
* value, you will need to manufacture a dummy result just to preserve the
* correct ordering of statements. Note that the macro passes the address
* of its argument (so you need to give it something which is addressable).
* If your expression returns multiple results, pass the last such result
* to PyFPE_END_PROTECT.
*
* Note that PyFPE_dummy returns a double, which is cast to int.
* This seeming insanity is to tickle the Floating Point Unit (FPU).
* If an exception has occurred in a preceding floating point operation,
* some architectures (notably Intel 80x86) will not deliver the interrupt
* until the *next* floating point operation. This is painful if you've
* already decremented PyFPE_counter.
*/
#define PyFPE_END_PROTECT(v) PyFPE_counter -= (int)PyFPE_dummy(&(v));
#else
#define PyFPE_START_PROTECT(err_string, leave_stmt)
#define PyFPE_END_PROTECT(v)
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYFPE_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_PYGETOPT_H
#define Py_PYGETOPT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_DATA(int) _PyOS_opterr;
@ -15,7 +13,5 @@ PyAPI_FUNC(void) _PyOS_ResetGetOpt(void);
PyAPI_FUNC(int) _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYGETOPT_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_HASH_H
#define Py_HASH_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Helpers for hash functions */
#ifndef Py_LIMITED_API
@ -138,8 +136,6 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
# endif /* uint64_t && uint32_t && aligned */
#endif /* Py_HASH_ALGORITHM */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_HASH_H */

View file

@ -1,11 +1,7 @@
/* Interfaces to configure, query, create & destroy the Python runtime */
#ifndef Py_PYLIFECYCLE_H
#define Py_PYLIFECYCLE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
@ -125,7 +121,5 @@ PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYLIFECYCLE_H */

View file

@ -1,5 +1,7 @@
#ifndef PYMACCONFIG_H
#define PYMACCONFIG_H
/* clang-format off */
/*
* This file moves some of the autoconf magic to compile-time
* when building on MacOSX. This is needed for building 4-way

View file

@ -1,5 +1,6 @@
#ifndef Py_PYMACRO_H
#define Py_PYMACRO_H
/* clang-format off */
/* Minimum value between x and y */
#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))

View file

@ -1,7 +1,7 @@
#ifndef Py_PYMATH_H
#define Py_PYMATH_H
#include "pyconfig.h" /* include for defines */
#include "third_party/python/pyconfig.h"
/* clang-format off */
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to mathematical
@ -29,10 +29,10 @@ extern double hypot(double, double);
/* extra declarations */
#ifndef _MSC_VER
#ifndef __STDC__
extern double fmod (double, double);
extern double frexp (double, int *);
extern double ldexp (double, int);
extern double modf (double, double *);
extern double fmod(double, double);
extern double frexp(double, int *);
extern double ldexp(double, int);
extern double modf(double, double *);
extern double pow(double, double);
#endif /* __STDC__ */
#endif /* _MSC_VER */
@ -60,7 +60,6 @@ extern double pow(double, double);
#define Py_MATH_TAU 6.2831853071795864769252867665590057683943L
#endif
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
register and into a 64-bit memory location, rounding from extended
precision to double precision in the process. On other platforms it does
@ -69,12 +68,12 @@ extern double pow(double, double);
/* we take double rounding as evidence of x87 usage */
#ifndef Py_LIMITED_API
#ifndef Py_FORCE_DOUBLE
# ifdef X87_DOUBLE_ROUNDING
#ifdef X87_DOUBLE_ROUNDING
PyAPI_FUNC(double) _Py_force_double(double);
# define Py_FORCE_DOUBLE(X) (_Py_force_double(X))
# else
# define Py_FORCE_DOUBLE(X) (X)
# endif
#define Py_FORCE_DOUBLE(X) (_Py_force_double(X))
#else
#define Py_FORCE_DOUBLE(X) (X)
#endif
#endif
#endif
@ -115,12 +114,12 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
* Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
*/
#ifndef Py_IS_INFINITY
# if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1
# define Py_IS_INFINITY(X) isinf(X)
# else
# define Py_IS_INFINITY(X) ((X) && \
(Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))
# endif
#if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1
#define Py_IS_INFINITY(X) isinf(X)
#else
#define Py_IS_INFINITY(X) \
((X) && (Py_FORCE_DOUBLE(X) * 0.5 == Py_FORCE_DOUBLE(X)))
#endif
#endif
/* Py_IS_FINITE(X)
@ -157,27 +156,29 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
*/
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
#if !defined(__INTEL_COMPILER)
#define Py_NAN (Py_HUGE_VAL * 0.)
#define Py_NAN (Py_HUGE_VAL * 0.)
#else /* __INTEL_COMPILER */
#if defined(ICC_NAN_STRICT)
#pragma float_control(push)
#pragma float_control(precise, on)
#pragma float_control(except, on)
#if defined(_MSC_VER)
__declspec(noinline)
#else /* Linux */
__attribute__((noinline))
#endif /* _MSC_VER */
static double __icc_nan()
{
return sqrt(-1.0);
}
#pragma float_control (pop)
#define Py_NAN __icc_nan()
#else /* ICC_NAN_RELAXED as default for Intel Compiler */
static const union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
#define Py_NAN (__nan_store.__icc_nan)
#endif /* ICC_NAN_STRICT */
#if defined(ICC_NAN_STRICT)
#pragma float_control(push)
#pragma float_control(precise, on)
#pragma float_control(except, on)
#if defined(_MSC_VER)
__declspec(noinline)
#else /* Linux */
__attribute__((noinline))
#endif /* _MSC_VER */
static double __icc_nan() {
return sqrt(-1.0);
}
#pragma float_control(pop)
#define Py_NAN __icc_nan()
#else /* ICC_NAN_RELAXED as default for Intel Compiler */
static const union {
unsigned char buf[8];
double __icc_nan;
} __nan_store = {0, 0, 0, 0, 0, 0, 0xf8, 0x7f};
#define Py_NAN (__nan_store.__icc_nan)
#endif /* ICC_NAN_STRICT */
#endif /* __INTEL_COMPILER */
#endif
@ -210,21 +211,25 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#define Py_OVERFLOWED(X) isinf(X)
#else
#define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
(X) == Py_HUGE_VAL || \
(X) == -Py_HUGE_VAL))
#define Py_OVERFLOWED(X) \
((X) != 0.0 && (errno == ERANGE || (X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL))
#endif
/* Return whether integral type *type* is signed or not. */
#define _Py_IntegralTypeSigned(type) ((type)(-1) < 0)
/* Return the maximum value of integral type *type*. */
#define _Py_IntegralTypeMax(type) ((_Py_IntegralTypeSigned(type)) ? (((((type)1 << (sizeof(type)*CHAR_BIT - 2)) - 1) << 1) + 1) : ~(type)0)
#define _Py_IntegralTypeMax(type) \
((_Py_IntegralTypeSigned(type)) \
? (((((type)1 << (sizeof(type) * CHAR_BIT - 2)) - 1) << 1) + 1) \
: ~(type)0)
/* Return the minimum value of integral type *type*. */
#define _Py_IntegralTypeMin(type) ((_Py_IntegralTypeSigned(type)) ? -_Py_IntegralTypeMax(type) - 1 : 0)
#define _Py_IntegralTypeMin(type) \
((_Py_IntegralTypeSigned(type)) ? -_Py_IntegralTypeMax(type) - 1 : 0)
/* Check whether *v* is in the range of integral type *type*. This is most
* useful if *v* is floating-point, since demoting a floating-point *v* to an
* integral type that cannot represent *v*'s integral part is undefined
* behavior. */
#define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
#define _Py_InIntegralTypeRange(type, v) \
(_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
#endif /* Py_PYMATH_H */

View file

@ -1,15 +1,8 @@
/* The PyMem_ family: low-level memory allocation interfaces.
See objimpl.h for the PyObject_ memory family.
*/
#ifndef Py_PYMEM_H
#define Py_PYMEM_H
#include "pyport.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "third_party/python/Include/pyport.h"
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
@ -228,8 +221,5 @@ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain,
PyAPI_FUNC(void) PyMem_SetupDebugHooks(void);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYMEM_H */

View file

@ -1,9 +1,19 @@
#ifndef Py_PYPORT_H
#define Py_PYPORT_H
#include "pyconfig.h" /* include for defines */
#include <inttypes.h>
#include "libc/calls/calls.h"
#include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/math.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/itimer.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/termios.h"
#include "libc/time/time.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to basic
@ -44,8 +54,8 @@ Used in: Py_SAFE_DOWNCAST
#ifndef PY_LONG_LONG
#define PY_LONG_LONG long long
/* If LLONG_MAX is defined in limits.h, use that. */
#define PY_LLONG_MIN LLONG_MIN
#define PY_LLONG_MAX LLONG_MAX
#define PY_LLONG_MIN LLONG_MIN
#define PY_LLONG_MAX LLONG_MAX
#define PY_ULLONG_MAX ULLONG_MAX
#endif
@ -73,19 +83,19 @@ Used in: Py_SAFE_DOWNCAST
* without loss of information. Similarly for intptr_t, wrt a signed
* integral type.
*/
typedef uintptr_t Py_uintptr_t;
typedef intptr_t Py_intptr_t;
typedef uintptr_t Py_uintptr_t;
typedef intptr_t Py_intptr_t;
/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
* sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
* unsigned integral type). See PEP 353 for details.
*/
#ifdef HAVE_SSIZE_T
typedef ssize_t Py_ssize_t;
typedef ssize_t Py_ssize_t;
#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
typedef Py_intptr_t Py_ssize_t;
typedef Py_intptr_t Py_ssize_t;
#else
# error "Python needs a typedef for Py_ssize_t in pyport.h."
#error "Python needs a typedef for Py_ssize_t in pyport.h."
#endif
/* Py_hash_t is the same size as a pointer. */
@ -106,9 +116,9 @@ typedef int Py_ssize_clean_t;
#define PY_SIZE_MAX SIZE_MAX
/* Largest positive value of type Py_ssize_t. */
#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1) >> 1))
/* Smallest negative value of type Py_ssize_t. */
#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX - 1)
/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
* format to convert an argument with the width of a size_t or Py_ssize_t.
@ -135,15 +145,15 @@ typedef int Py_ssize_clean_t;
* Py_ssize_t on the platform.
*/
#ifndef PY_FORMAT_SIZE_T
# if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
# define PY_FORMAT_SIZE_T ""
# elif SIZEOF_SIZE_T == SIZEOF_LONG
# define PY_FORMAT_SIZE_T "l"
# elif defined(MS_WINDOWS)
# define PY_FORMAT_SIZE_T "I"
# else
# error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
# endif
#if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
#define PY_FORMAT_SIZE_T ""
#elif SIZEOF_SIZE_T == SIZEOF_LONG
#define PY_FORMAT_SIZE_T "l"
#elif defined(MS_WINDOWS)
#define PY_FORMAT_SIZE_T "I"
#else
#error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
#endif
#endif
/* Py_LOCAL can be used instead of static to get the fastest possible calling
@ -169,15 +179,15 @@ typedef int Py_ssize_clean_t;
#pragma optimize("agtw", on)
#endif
/* ignore warnings if the compiler decides not to inline a function */
#pragma warning(disable: 4710)
#pragma warning(disable : 4710)
/* fastest possible local call under MSVC */
#define Py_LOCAL(type) static type __fastcall
#define Py_LOCAL(type) static type __fastcall
#define Py_LOCAL_INLINE(type) static __inline type __fastcall
#elif defined(USE_INLINE)
#define Py_LOCAL(type) static type
#define Py_LOCAL(type) static type
#define Py_LOCAL_INLINE(type) static inline type
#else
#define Py_LOCAL(type) static type
#define Py_LOCAL(type) static type
#define Py_LOCAL_INLINE(type) static type
#endif
@ -185,79 +195,7 @@ typedef int Py_ssize_clean_t;
* see https://bugs.python.org/issue28126 */
#define Py_MEMCPY memcpy
#include <stdlib.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
#endif
#include <math.h> /* Moved here from the math section, before extern "C" */
/********************************************
* WRAPPER FOR <time.h> and/or <sys/time.h> *
********************************************/
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else /* !TIME_WITH_SYS_TIME */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else /* !HAVE_SYS_TIME_H */
#include <time.h>
#endif /* !HAVE_SYS_TIME_H */
#endif /* !TIME_WITH_SYS_TIME */
/******************************
* WRAPPER FOR <sys/select.h> *
******************************/
/* NB caller must include <sys/types.h> */
#ifdef HAVE_SYS_SELECT_H
// #include <sys/select.h>
#endif /* !HAVE_SYS_SELECT_H */
/*******************************
* stat() and fstat() fiddling *
*******************************/
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#elif defined(HAVE_STAT_H)
#include <stat.h>
#endif
#ifndef S_IFMT
/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
#define S_IFMT 0170000
#endif
#ifndef S_IFLNK
/* Windows doesn't define S_IFLNK but posixmodule.c maps
* IO_REPARSE_TAG_SYMLINK to S_IFLNK */
# define S_IFLNK 0120000
#endif
#ifndef S_ISREG
#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
#ifndef S_ISDIR
#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISCHR
#define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
#endif
#ifdef __cplusplus
/* Move this down here since some C++ #include's don't like to be included
inside an extern "C" */
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* Py_ARITHMETIC_RIGHT_SHIFT
* C doesn't define whether a right-shift of a signed integer sign-extends
@ -279,7 +217,7 @@ extern "C" {
*/
#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
((I) < 0 ? -1 - ((-1 - (I)) >> (J)) : (I) >> (J))
#else
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
#endif
@ -299,7 +237,7 @@ extern "C" {
*/
#ifdef Py_DEBUG
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
(assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
(assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
#else
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
#endif
@ -313,19 +251,22 @@ extern "C" {
* This isn't reliable. See Py_OVERFLOWED comments.
* X is evaluated more than once.
*/
#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
#if defined(__FreeBSD__) || defined(__OpenBSD__) || \
(defined(__hpux) && defined(__ia64))
#define _Py_SET_EDOM_FOR_NAN(X) \
if (isnan(X)) errno = EDOM;
#else
#define _Py_SET_EDOM_FOR_NAN(X) ;
#endif
#define Py_SET_ERRNO_ON_MATH_ERROR(X) \
do { \
if (errno == 0) { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
errno = ERANGE; \
else _Py_SET_EDOM_FOR_NAN(X) \
} \
} while(0)
#define Py_SET_ERRNO_ON_MATH_ERROR(X) \
do { \
if (errno == 0) { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
errno = ERANGE; \
else \
_Py_SET_EDOM_FOR_NAN(X) \
} \
} while (0)
/* Py_SET_ERANGE_ON_OVERFLOW(x)
* An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
@ -346,26 +287,22 @@ extern "C" {
* This isn't reliable. See Py_OVERFLOWED comments.
* X and Y may be evaluated more than once.
*/
#define Py_ADJUST_ERANGE1(X) \
do { \
if (errno == 0) { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
errno = ERANGE; \
} \
else if (errno == ERANGE && (X) == 0.0) \
errno = 0; \
} while(0)
#define Py_ADJUST_ERANGE1(X) \
do { \
if (errno == 0) { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) errno = ERANGE; \
} else if (errno == ERANGE && (X) == 0.0) \
errno = 0; \
} while (0)
#define Py_ADJUST_ERANGE2(X, Y) \
do { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
(Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
if (errno == 0) \
errno = ERANGE; \
} \
else if (errno == ERANGE) \
errno = 0; \
} while(0)
#define Py_ADJUST_ERANGE2(X, Y) \
do { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || (Y) == Py_HUGE_VAL || \
(Y) == -Py_HUGE_VAL) { \
if (errno == 0) errno = ERANGE; \
} else if (errno == ERANGE) \
errno = 0; \
} while (0)
/* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are
* required to support the short float repr introduced in Python 3.1) require
@ -394,62 +331,21 @@ extern "C" {
#ifdef HAVE_GCC_ASM_FOR_X87
#define HAVE_PY_SET_53BIT_PRECISION 1
/* _Py_get/set_387controlword functions are defined in Python/pymath.c */
#define _Py_SET_53BIT_PRECISION_HEADER \
unsigned short old_387controlword, new_387controlword
#define _Py_SET_53BIT_PRECISION_START \
do { \
old_387controlword = _Py_get_387controlword(); \
new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
if (new_387controlword != old_387controlword) \
_Py_set_387controlword(new_387controlword); \
} while (0)
#define _Py_SET_53BIT_PRECISION_END \
if (new_387controlword != old_387controlword) \
_Py_set_387controlword(old_387controlword)
#define _Py_SET_53BIT_PRECISION_HEADER \
unsigned short old_387controlword, new_387controlword
#define _Py_SET_53BIT_PRECISION_START \
do { \
old_387controlword = _Py_get_387controlword(); \
new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
if (new_387controlword != old_387controlword) \
_Py_set_387controlword(new_387controlword); \
} while (0)
#define _Py_SET_53BIT_PRECISION_END \
if (new_387controlword != old_387controlword) \
_Py_set_387controlword(old_387controlword)
#endif
/* get and set x87 control word for VisualStudio/x86 */
#if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */
#define HAVE_PY_SET_53BIT_PRECISION 1
#define _Py_SET_53BIT_PRECISION_HEADER \
unsigned int old_387controlword, new_387controlword, out_387controlword
/* We use the __control87_2 function to set only the x87 control word.
The SSE control word is unaffected. */
#define _Py_SET_53BIT_PRECISION_START \
do { \
__control87_2(0, 0, &old_387controlword, NULL); \
new_387controlword = \
(old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
if (new_387controlword != old_387controlword) \
__control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
&out_387controlword, NULL); \
} while (0)
#define _Py_SET_53BIT_PRECISION_END \
do { \
if (new_387controlword != old_387controlword) \
__control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
&out_387controlword, NULL); \
} while (0)
#endif
#ifdef HAVE_GCC_ASM_FOR_MC68881
#define HAVE_PY_SET_53BIT_PRECISION 1
#define _Py_SET_53BIT_PRECISION_HEADER \
unsigned int old_fpcr, new_fpcr
#define _Py_SET_53BIT_PRECISION_START \
do { \
__asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
/* Set double precision / round to nearest. */ \
new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
if (new_fpcr != old_fpcr) \
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
} while (0)
#define _Py_SET_53BIT_PRECISION_END \
do { \
if (new_fpcr != old_fpcr) \
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
} while (0)
#endif
/* default definitions are empty */
#ifndef HAVE_PY_SET_53BIT_PRECISION
@ -471,7 +367,7 @@ extern "C" {
*/
#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
#define PY_NO_SHORT_FLOAT_REPR
#endif
@ -483,7 +379,6 @@ extern "C" {
#define PY_NO_SHORT_FLOAT_REPR
#endif
/* Py_DEPRECATED(version)
* Declare a variable, type, or function deprecated.
* Usage:
@ -491,8 +386,8 @@ extern "C" {
* typedef int T1 Py_DEPRECATED(2.4);
* extern int x() Py_DEPRECATED(2.5);
*/
#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
(__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#if defined(__GNUC__) && \
((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
#else
#define Py_DEPRECATED(VERSION_UNUSED)
@ -512,76 +407,18 @@ extern int gethostname(char *, int);
#endif
#ifdef HAVE__GETPTY
#include <sys/types.h> /* we need to import mode_t */
extern char * _getpty(int *, int, mode_t, int);
#endif
/* On QNX 6, struct termio must be declared by including sys/termio.h
if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
be included before termios.h or it will generate an error. */
#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
#include <sys/termio.h>
extern char *_getpty(int *, int, mode_t, int);
#endif
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
functions, even though they are included in libutil. */
#include <termios.h>
extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
/* On 4.4BSD-descendants, ctype functions serves the whole range of
* wchar_t character set rather than single byte code points only.
* This characteristic can break some operations of string object
* including str.upper() and str.split() on UTF-8 locales. This
* workaround was provided by Tim Robbins of FreeBSD project.
*/
#ifdef __FreeBSD__
#include <osreldate.h>
#if (__FreeBSD_version >= 500040 && __FreeBSD_version < 602113) || \
(__FreeBSD_version >= 700000 && __FreeBSD_version < 700054) || \
(__FreeBSD_version >= 800000 && __FreeBSD_version < 800001)
# define _PY_PORT_CTYPE_UTF8_ISSUE
#endif
#endif
#if defined(__APPLE__)
# define _PY_PORT_CTYPE_UTF8_ISSUE
#endif
#ifdef _PY_PORT_CTYPE_UTF8_ISSUE
#ifndef __cplusplus
/* The workaround below is unsafe in C++ because
* the <locale> defines these symbols as real functions,
* with a slightly different signature.
* See issue #10910
*/
#include <ctype.h>
#include <wctype.h>
#undef isalnum
#define isalnum(c) iswalnum(btowc(c))
#undef isalpha
#define isalpha(c) iswalpha(btowc(c))
#undef islower
#define islower(c) iswlower(btowc(c))
#undef isspace
#define isspace(c) iswspace(btowc(c))
#undef isupper
#define isupper(c) iswupper(btowc(c))
#undef tolower
#define tolower(c) towlower(btowc(c))
#undef toupper
#define toupper(c) towupper(btowc(c))
#endif
#endif
/* Declarations for symbol visibility.
PyAPI_FUNC(type): Declares a public Python API function and return type
@ -595,84 +432,16 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
we support a HAVE_DECLSPEC_DLL macro to save duplication.
*/
/*
All windows ports, except cygwin, are handled in PC/pyconfig.h.
Cygwin is the only other autoconf platform requiring special
linkage handling and it uses __declspec().
*/
#if defined(__CYGWIN__)
# define HAVE_DECLSPEC_DLL
#endif
/* only get special linkage if built as shared or platform is Cygwin */
#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
# if defined(HAVE_DECLSPEC_DLL)
# ifdef Py_BUILD_CORE
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
/* module init functions inside the core need no external linkage */
/* except for Cygwin to handle embedding */
# if defined(__CYGWIN__)
# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# else /* __CYGWIN__ */
# define PyMODINIT_FUNC PyObject*
# endif /* __CYGWIN__ */
# else /* Py_BUILD_CORE */
/* Building an extension module, or an embedded situation */
/* public Python functions and data are imported */
/* Under Cygwin, auto-import functions to prevent compilation */
/* failures similar to those described at the bottom of 4.1: */
/* http://docs.python.org/extending/windows.html#a-cookbook-approach */
# if !defined(__CYGWIN__)
# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
# endif /* !__CYGWIN__ */
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
/* module init functions outside the core must be exported */
# if defined(__cplusplus)
# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
# else /* __cplusplus */
# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# endif /* __cplusplus */
# endif /* Py_BUILD_CORE */
# endif /* HAVE_DECLSPEC */
#endif /* Py_ENABLE_SHARED */
/* If no external linkage macros defined by now, create defaults */
#ifndef PyAPI_FUNC
# define PyAPI_FUNC(RTYPE) RTYPE
#endif
#ifndef PyAPI_DATA
# define PyAPI_DATA(RTYPE) extern RTYPE
#endif
#ifndef PyMODINIT_FUNC
# if defined(__cplusplus)
# define PyMODINIT_FUNC extern "C" PyObject*
# else /* __cplusplus */
# define PyMODINIT_FUNC PyObject*
# endif /* __cplusplus */
#define PyAPI_FUNC(RTYPE) RTYPE
#define PyAPI_DATA(RTYPE) extern RTYPE
#ifdef __cplusplus
#define PyMODINIT_FUNC extern "C" PyObject *
#else
#define PyMODINIT_FUNC PyObject *
#endif
/* limits.h constants that may be missing */
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef LONG_MAX
#if SIZEOF_LONG == 4
#define LONG_MAX 0X7FFFFFFFL
#elif SIZEOF_LONG == 8
#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
#else
#error "could not set LONG_MAX in pyport.h"
#endif
#endif
#ifndef LONG_MIN
#define LONG_MIN (-LONG_MAX-1)
#endif
#ifndef LONG_BIT
#define LONG_BIT (8 * SIZEOF_LONG)
#endif
@ -686,15 +455,13 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
/*
* Hide GCC attributes from compilers that don't support them.
*/
#if (!defined(__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
(__GNUC__ == 2 && __GNUC_MINOR__ < 7))
#define Py_GCC_ATTRIBUTE(x)
#else
#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
@ -713,7 +480,7 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
* when using do{...}while(0) macros
*/
#ifdef __SUNPRO_C
#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
#pragma error_messages(off, E_END_OF_LOOP_CODE_NOT_REACHED)
#endif
#ifndef Py_LL
@ -733,35 +500,14 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
*/
#ifdef WORDS_BIGENDIAN
#define PY_BIG_ENDIAN 1
#define PY_BIG_ENDIAN 1
#define PY_LITTLE_ENDIAN 0
#else
#define PY_BIG_ENDIAN 0
#define PY_BIG_ENDIAN 0
#define PY_LITTLE_ENDIAN 1
#endif
#ifdef Py_BUILD_CORE
/*
* Macros to protect CRT calls against instant termination when passed an
* invalid parameter (issue23524).
*/
#if defined _MSC_VER && _MSC_VER >= 1900
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
#define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
#define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
#else
#define _Py_BEGIN_SUPPRESS_IPH
#define _Py_END_SUPPRESS_IPH
#endif /* _MSC_VER >= 1900 */
#endif /* Py_BUILD_CORE */
#ifdef __ANDROID__
#include <android/api-level.h>
#endif
#endif /* Py_PYPORT_H */

View file

@ -1,12 +1,7 @@
/* Thread and interpreter state structures and their interfaces */
#ifndef Py_PYSTATE_H
#define Py_PYSTATE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* This limitation is for performance and simplicity. If needed it can be
removed (with effort). */
@ -318,7 +313,5 @@ typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYSTATE_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_STRCMP_H
#define Py_STRCMP_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(int) PyOS_mystrnicmp(const char *, const char *, Py_ssize_t);
PyAPI_FUNC(int) PyOS_mystricmp(const char *, const char *);
@ -16,8 +14,5 @@ PyAPI_FUNC(int) PyOS_mystricmp(const char *, const char *);
#define PyOS_stricmp PyOS_mystricmp
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_STRCMP_H */

View file

@ -1,9 +1,7 @@
#ifndef Py_STRHEX_H
#define Py_STRHEX_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
/* Returns a str() containing the hex representation of argbuf. */
@ -12,8 +10,5 @@ PyAPI_FUNC(PyObject*) _Py_strhex(const char* argbuf, const Py_ssize_t arglen);
PyAPI_FUNC(PyObject*) _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_STRHEX_H */

View file

@ -1,10 +1,7 @@
#ifndef Py_STRTOD_H
#define Py_STRTOD_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(double) PyOS_string_to_double(const char *str,
char **endptr,
@ -38,8 +35,5 @@ PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);
#define Py_DTST_INFINITE 1
#define Py_DTST_NAN 2
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_STRTOD_H */

View file

@ -1,11 +1,7 @@
/* Interfaces to parse and execute pieces of python code */
#ifndef Py_PYTHONRUN_H
#define Py_PYTHONRUN_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
@ -191,7 +187,5 @@ PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
PyAPI_FUNC(int) PyOS_CheckStack(void);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYTHONRUN_H */

View file

@ -1,14 +1,11 @@
#ifndef Py_PYTHREAD_H
#define Py_PYTHREAD_H
COSMOPOLITAN_C_START_
/* clang-format off */
typedef void *PyThread_type_lock;
typedef void *PyThread_type_sema;
#ifdef __cplusplus
extern "C" {
#endif
/* Return status codes for Python lock acquisition. Chosen for maximum
* backwards compatibility, ie failure -> 0, success -> 1. */
typedef enum PyLockStatus {
@ -83,8 +80,5 @@ PyAPI_FUNC(void) PyThread_delete_key_value(int key);
/* Cleanup after a fork */
PyAPI_FUNC(void) PyThread_ReInitTLS(void);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_PYTHREAD_H */

View file

@ -1,17 +1,15 @@
#ifndef Py_LIMITED_API
#ifndef Py_PYTIME_H
#define Py_PYTIME_H
#include "pyconfig.h" /* include for defines */
#include "object.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/pyconfig.h"
COSMOPOLITAN_C_START_
/* clang-format off */
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to time related
functions and constants
**************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
store a duration, and so indirectly a date (related to another date, like
@ -203,9 +201,6 @@ PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm);
Return 0 on success, raise an exception and return -1 on error. */
PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* Py_PYTIME_H */
#endif /* Py_LIMITED_API */

View file

@ -1,11 +1,7 @@
/* Range object interface */
#ifndef Py_RANGEOBJECT_H
#define Py_RANGEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/*
A range object represents an integer range. This is an immutable object;
@ -21,7 +17,5 @@ PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_RANGEOBJECT_H */

View file

@ -1,10 +1,7 @@
/* Set object interface */
#ifndef Py_SETOBJECT_H
#define Py_SETOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
@ -102,7 +99,5 @@ PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);
(Py_TYPE(ob) == &PyFrozenSet_Type || \
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_SETOBJECT_H */

View file

@ -1,8 +1,7 @@
#ifndef Py_SLICEOBJECT_H
#define Py_SLICEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* The unique ellipsis object "..." */
@ -59,7 +58,5 @@ PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length,
Py_ssize_t step);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_SLICEOBJECT_H */

View file

@ -1,20 +1,15 @@
#ifndef Py_STRUCTMEMBER_H
#define Py_STRUCTMEMBER_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* Interface to map C struct members to Python object attributes */
#include <stddef.h> /* For offsetof */
/* An array of PyMemberDef structures defines the name, type and offset
of selected members of a C structure. These can be read by
PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
flag is set). The array must be terminated with an entry whose name
pointer is NULL. */
typedef struct PyMemberDef {
char *name;
int type;
@ -67,8 +62,5 @@ typedef struct PyMemberDef {
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_STRUCTMEMBER_H */

View file

@ -1,11 +1,7 @@
/* Named tuple object interface */
#ifndef Py_STRUCTSEQ_H
#define Py_STRUCTSEQ_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct PyStructSequence_Field {
char *name;
@ -43,7 +39,5 @@ typedef PyTupleObject PyStructSequence;
PyAPI_FUNC(void) PyStructSequence_SetItem(PyObject*, Py_ssize_t, PyObject*);
PyAPI_FUNC(PyObject*) PyStructSequence_GetItem(PyObject*, Py_ssize_t);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_STRUCTSEQ_H */

View file

@ -1,14 +1,8 @@
#ifndef Py_LIMITED_API
#ifndef Py_SYMTABLE_H
#define Py_SYMTABLE_H
#ifdef __cplusplus
extern "C" {
#endif
/* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
* names.
*/
COSMOPOLITAN_C_START_
/* clang-format off */
typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
_Py_block_ty;
@ -112,8 +106,6 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define GENERATOR 1
#define GENERATOR_EXPRESSION 2
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_SYMTABLE_H */
#endif /* Py_LIMITED_API */

View file

@ -1,11 +1,7 @@
/* System module interface */
#ifndef Py_SYSMODULE_H
#define Py_SYSMODULE_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
@ -37,7 +33,5 @@ PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_SYSMODULE_H */

View file

@ -1,11 +1,8 @@
/* Token types */
#ifndef Py_LIMITED_API
#ifndef Py_TOKEN_H
#define Py_TOKEN_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#undef TILDE /* Prevent clash of our definition with system macro. Ex AIX, ioctl.h */
@ -83,8 +80,6 @@ PyAPI_FUNC(int) PyToken_OneChar(int);
PyAPI_FUNC(int) PyToken_TwoChars(int, int);
PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int);
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_TOKEN_H */
#endif /* Py_LIMITED_API */

View file

@ -1,11 +1,8 @@
#ifndef Py_TRACEBACK_H
#define Py_TRACEBACK_H
#ifdef __cplusplus
extern "C" {
#endif
#include "pystate.h"
#include "third_party/python/Include/pystate.h"
COSMOPOLITAN_C_START_
/* clang-format off */
struct _frame;
@ -112,8 +109,5 @@ PyAPI_FUNC(void) _Py_DumpHexadecimal(
Py_ssize_t width);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_TRACEBACK_H */

View file

@ -1,11 +1,7 @@
/* Tuple object interface */
#ifndef Py_TUPLEOBJECT_H
#define Py_TUPLEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/*
Another generally useful object type is a tuple of object pointers.
@ -67,7 +63,5 @@ PyAPI_FUNC(int) PyTuple_ClearFreeList(void);
PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_TUPLEOBJECT_H */

View file

@ -1,3 +1,4 @@
/* clang-format off */
/* Do not renumber the file; these numbers are part of the stable ABI. */
/* Disabled, see #10181 */
#undef Py_bf_getbuffer

View file

@ -1,10 +1,8 @@
/* Unicode name database interface */
#ifndef Py_LIMITED_API
#ifndef Py_UCNHASH_H
#define Py_UCNHASH_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
/* revised ucnhash CAPI interface (exported through a "wrapper") */
@ -29,8 +27,6 @@ typedef struct {
} _PyUnicode_Name_CAPI;
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_UCNHASH_H */
#endif /* !Py_LIMITED_API */

View file

@ -1,10 +1,9 @@
#ifndef Py_UNICODEOBJECT_H
#define Py_UNICODEOBJECT_H
#include <stdarg.h>
COSMOPOLITAN_C_START_
/* clang-format off */
/*
Unicode implementation based on original code by Fredrik Lundh,
modified by Marc-Andre Lemburg (mal@lemburg.com) according to the
Unicode Integration Proposal. (See
@ -55,8 +54,6 @@ Copyright (c) Corporation for National Research Initiatives.
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* -------------------------------------------------------------------- */
#include <ctype.h>
/* === Internal API ======================================================= */
/* --- Internal Unicode Format -------------------------------------------- */
@ -103,14 +100,6 @@ typedef wchar_t Py_UNICODE;
# endif
#endif
#ifdef HAVE_WCHAR_H
/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
# ifdef _HAVE_BSDI
# include <time.h>
# endif
# include <wchar.h>
#endif
/* Py_UCS4 and Py_UCS2 are typedefs for the respective
unicode representations. */
typedef uint32_t Py_UCS4;
@ -186,10 +175,6 @@ typedef uint8_t Py_UCS1;
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
extern "C" {
#endif
/* --- Unicode Type ------------------------------------------------------- */
#ifndef Py_LIMITED_API
@ -2336,7 +2321,5 @@ PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void);
PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_UNICODEOBJECT_H */

View file

@ -1,8 +1,7 @@
#ifndef Py_WARNINGS_H
#define Py_WARNINGS_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) _PyWarnings_Init(void);
@ -56,8 +55,6 @@ PyErr_WarnExplicitFormat(PyObject *category,
#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
#endif
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_WARNINGS_H */

View file

@ -1,11 +1,7 @@
/* Weak references objects for Python. */
#ifndef Py_WEAKREFOBJECT_H
#define Py_WEAKREFOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
COSMOPOLITAN_C_START_
/* clang-format off */
typedef struct _PyWeakReference PyWeakReference;
@ -79,8 +75,5 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
? ((PyWeakReference *)(ref))->wr_object \
: Py_None)
#ifdef __cplusplus
}
#endif
COSMOPOLITAN_C_END_
#endif /* !Py_WEAKREFOBJECT_H */