Implement tree-shaking for Python sources

This commit is contained in:
Justine Tunney 2021-09-05 01:20:03 -07:00
parent 81287b7ec0
commit 44c87b83ff
110 changed files with 899 additions and 1922 deletions

View file

@ -5,6 +5,8 @@
#include "libc/nt/console.h"
#include "libc/nt/debug.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/regtype.h"
#include "libc/nt/errors.h"
#include "libc/nt/events.h"
#include "libc/nt/files.h"
@ -24,6 +26,8 @@
#undef NULL
#define NULL 0
#define ERROR_SUCCESS kNtErrorSuccess
#define FARPROC wambda
#define NEARPROC wambda
#define PROC wambda
@ -1320,7 +1324,6 @@
#define SOCKET_ERROR -1
#define WSA_INVALID_EVENT -1L
#define WAIT_FAILED -1U
#define WSA_WAIT_FAILED -1U
#define SOCKET uint64_t
#define WSA_WAIT_IO_COMPLETION 0xc0
#define WSA_WAIT_TIMEOUT 258

View file

@ -275,7 +275,6 @@ PyObject * _PyErr_FormatFromCause(
);
#endif
#ifdef MS_WINDOWS
PyObject * PyErr_SetFromWindowsErrWithFilename(
int ierr,
const char *filename /* decoded from the filesystem encoding */
@ -302,7 +301,6 @@ PyObject * PyErr_SetExcFromWindowsErrWithUnicodeFilename(
PyObject *,int, const Py_UNICODE *);
#endif
PyObject * PyErr_SetExcFromWindowsErr(PyObject *, int);
#endif /* MS_WINDOWS */
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
PyObject * PyErr_SetImportErrorSubclass(PyObject *, PyObject *,

View file

@ -1,10 +1,15 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_YOINK_H_
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_YOINK_H_
#include "libc/dce.h"
#define PYTHON_YOINK(s) \
__asm__(".section .yoink\n\t" \
"nopl\t\"py:" s "\"\n\t" \
#define PYTHON_YOINK(s) \
__asm__(".section .yoink\n\t" \
"nopl\t\"pyc:" s "\"\n\t" \
".previous")
#define PYTHON_PROVIDE(s) \
__asm__(".section .yoink\n" \
"\"pyc:" s "\":\n\t" \
".globl\t\"pyc:" s "\"\n\t" \
".previous")
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_YOINK_H_ */

View file

@ -1,6 +1,6 @@
import collections
import copyreg
import dbm
# import dbm
import io
import functools
import pickle
@ -979,7 +979,7 @@ class AbstractUnpickleTests(unittest.TestCase):
self.assertIs(self.loads(pickled), functools.reduce)
# whichdb.whichdb
pickled = b'\x80\x02cwhichdb\nwhichdb\n.'
self.assertIs(self.loads(pickled), dbm.whichdb)
# self.assertIs(self.loads(pickled), dbm.whichdb)
# Exception(), StandardError()
for name in (b'Exception', b'StandardError'):
pickled = (b'\x80\x02cexceptions\n' + name + b'\nU\x03ugh\x85R.')
@ -2257,7 +2257,7 @@ class AbstractPickleTests(unittest.TestCase):
(range(1, 7), '__builtin__', 'xrange'),
(map(int, '123'), 'itertools', 'imap'),
(functools.reduce, '__builtin__', 'reduce'),
(dbm.whichdb, 'whichdb', 'whichdb'),
# (dbm.whichdb, 'whichdb', 'whichdb'),
(Exception(), 'exceptions', 'Exception'),
(collections.UserDict(), 'UserDict', 'IterableUserDict'),
(collections.UserList(), 'UserList', 'UserList'),

View file

@ -19,7 +19,10 @@ PORT = 0
SUPPORTS_SSL = False
if hasattr(poplib, 'POP3_SSL'):
import ssl
try:
import ssl
except ImportError:
assert False
SUPPORTS_SSL = True
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")

View file

@ -23,8 +23,8 @@ try:
import ctypes
except ImportError:
ctypes = None
else:
import ctypes.util
# else:
# import ctypes.util
try:
import _thread

View file

@ -20,8 +20,11 @@
#include "third_party/python/Include/setobject.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_asyncio");
/*[clinic input]
module _asyncio
[clinic start generated code]*/

View file

@ -11,8 +11,11 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_bisect");
/* Bisection algorithms. Drop in replacement for bisect.py
Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru).

View file

@ -14,8 +14,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_codecs");
/* ------------------------------------------------------------------------
_codecs -- Provides access to the codec registry and the builtin

View file

@ -13,8 +13,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_collections");
/* collections module implementation of a deque() datatype
Written and maintained by Raymond D. Hettinger <python@rcn.com>
*/

View file

@ -7,8 +7,11 @@
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_crypt");
/* cryptmodule.c - by Steve Majewski
*/

View file

@ -10,8 +10,10 @@
#include "third_party/python/Include/pystate.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
/* csv module */
PYTHON_PROVIDE("_csv");
/*

View file

@ -4,8 +4,11 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_curses_panel");
/*
* Interface to the ncurses panel library
*

View file

@ -25,8 +25,11 @@
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_datetime");
/* C implementation for the date/time type documented at
* http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage
*/

View file

@ -1,6 +1,9 @@
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_dbm");
/* DBM module using dictionary interface */
/* Some Linux systems install gdbm/ndbm.h, but not ndbm.h. This supports

View file

@ -45,10 +45,13 @@
#include "third_party/python/Include/pythread.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_decimal/docstrings.h"
#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h"
/* clang-format off */
PYTHON_PROVIDE("_decimal");
asm(".ident\t\"\\n\
libmpdec (BSD-2)\\n\
Copyright 2008-2016 Stefan Krah\"");

View file

@ -22,8 +22,11 @@
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_elementtree");
/*--------------------------------------------------------------------
* Licensed to PSF under a Contributor Agreement.
* See http://www.python.org/psf/license for licensing details.

View file

@ -1,3 +1,9 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/assert.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
@ -11,8 +17,11 @@
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_functools");
/* _functools module written and maintained
by Hye-Shik Chang <perky@FreeBSD.org>
with adaptations by Raymond Hettinger <python@rcn.com>

View file

@ -4,8 +4,11 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_gdbm");
/* DBM module using dictionary interface */
/* Author: Anthony Baxter, after dbmmodule.c */
/* Doc strings: Mitch Chapman */

View file

@ -1,6 +1,14 @@
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/hashlib.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
/* Module that wraps all OpenSSL hash algorithms */
PYTHON_PROVIDE("_hashlib");
/* Module that wraps all OpenSSL hash algorithms */
/*
* Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)
* Licensed to PSF under a Contributor Agreement.
@ -12,14 +20,6 @@
*
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/hashlib.h"
#include "third_party/python/Include/pystrhex.h"
/* EVP is the preferred interface to hashing in OpenSSL */
#include <openssl/evp.h>
/* We use the object interface to discover what hashes OpenSSL supports. */

View file

@ -9,8 +9,11 @@
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_heapq");
/* Drop in replacement for heapq.py
C implementation derived directly from heapq.py in Py2.3

View file

@ -19,9 +19,12 @@
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/weakrefobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_io/_iomodule.h"
/* clang-format off */
PYTHON_PROVIDE("_io");
/*
An implementation of the new I/O lib as defined by PEP 3116 - "New I/O"

View file

@ -17,8 +17,11 @@
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_json");
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
#else

View file

@ -16,8 +16,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_locale");
/***********************************************************
Copyright (C) 1997, 2002, 2003, 2007, 2008 Martin von Loewis

View file

@ -13,9 +13,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/rotatingtree.h"
/* clang-format off */
PYTHON_PROVIDE("_lsprof");
/*** Selection of a high-precision timer ***/
#ifdef MS_WINDOWS

View file

@ -6,8 +6,11 @@
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_lzma");
/* _lzma - Low-level Python interface to liblzma.
Initial implementation by Per Øyvind Karlsen.

View file

@ -4,9 +4,12 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_multiprocessing/multiprocessing.h"
/* clang-format off */
PYTHON_PROVIDE("_multiprocessing");
/*
* Extension module used by multiprocessing package
*

View file

@ -11,8 +11,11 @@
#include "third_party/python/Include/opcode.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_opcode");
/*[clinic input]
module _opcode
[clinic start generated code]*/

View file

@ -14,8 +14,11 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_operator");
PyDoc_STRVAR(operator_doc,
"Operator interface.\n\
\n\

View file

@ -29,9 +29,12 @@
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/quickjs/internal.h"
/* clang-format off */
PYTHON_PROVIDE("_pickle");
PyDoc_STRVAR(pickle_module_doc,
"Optimized C implementation for the Python pickle module.");

View file

@ -23,9 +23,12 @@
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("_posixsubprocess");
/* Authors: Gregory P. Smith & Jeffrey Yasskin */
# define FD_DIR (IsBsd() ? "/dev/fd" : "/proc/self/fd")

View file

@ -15,8 +15,11 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_random");
/* ------------------------------------------------------------------
The code in this module was based on a download from:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

View file

@ -23,6 +23,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_sqlite/cache.h"
#include "third_party/python/Modules/_sqlite/connection.h"
#include "third_party/python/Modules/_sqlite/cursor.h"
@ -31,6 +32,8 @@
#include "third_party/python/Modules/_sqlite/row.h"
#include "third_party/python/Modules/_sqlite/statement.h"
PYTHON_PROVIDE("_sqlite3");
asm(".ident\t\"\\n\\n\
pysqlite (zlib license)\\n\
Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>\"");

View file

@ -20,9 +20,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/sre.h"
/* clang-format off */
PYTHON_PROVIDE("_sre");
/*
* Secret Labs' Regular Expression Engine
*

View file

@ -5,9 +5,12 @@
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/socketmodule.h"
/* clang-format off */
PYTHON_PROVIDE("_ssl");
/* SSL socket module
SSL support based on patches by Brian E Gallew and Laszlo Kovacs.

View file

@ -16,8 +16,11 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_stat");
/* stat.h interface
*
* The module defines all S_IF*, S_I*, UF_*, SF_* and ST_* constants to

View file

@ -21,8 +21,11 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_struct");
/* struct module -- pack values into and (out of) bytes objects */
/* New version supporting byte order, alignment and size options,

View file

@ -19,8 +19,11 @@
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_testbuffer");
/* C Extension module to test all aspects of PEP-3118.
Written by Stefan Krah. */

View file

@ -41,9 +41,12 @@
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("_testcapi");
/*
* C Extension module to test Python interpreter C APIs.
*

View file

@ -13,8 +13,11 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pystate.h"
#include "third_party/python/Include/typeslots.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_testmultiphase");
/* Testing module for multi-phase initialization of extension modules (PEP 489)
*/

View file

@ -5,8 +5,11 @@
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_thread");
/* Thread module */
/* Interface to Sjoerd's portable C thread library */

View file

@ -25,9 +25,12 @@
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/hashtable.h"
/* clang-format off */
PYTHON_PROVIDE("_tracemalloc");
/* Trace memory blocks allocated by PyMem_RawMalloc() */
#define TRACE_RAW_MALLOC

View file

@ -11,9 +11,12 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/weakrefobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/clinic/_weakref.inc"
/* clang-format off */
PYTHON_PROVIDE("_weakref");
#define GET_WEAKREFS_LISTPTR(o) \
((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o))

View file

@ -6,9 +6,12 @@
*/
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/winreparse.h"
/* clang-format off */
PYTHON_PROVIDE("_winapi");
/*
* Support routines from the Windows API
*

View file

@ -21,8 +21,11 @@
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("array");
/* Array object implementation */
/* An array is a uniform list -- all items have the same type.

View file

@ -17,8 +17,11 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pystate.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("atexit");
/*
* atexit - allow programmer to define multiple exit functions to be executed
* upon normal program termination.

View file

@ -15,8 +15,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("audioop");
/* audioopmodule - Module to detect peak values in arrays */
#if defined(__CHAR_UNSIGNED__)

View file

@ -16,9 +16,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/zlib/zlib.h"
/* clang-format off */
PYTHON_PROVIDE("binascii");
/*
** Routines to represent binary data in ASCII and vice-versa
**

View file

@ -4,14 +4,17 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_cn.inc"
/* clang-format off */
PYTHON_PROVIDE("_codecs_cn");
/*
* _codecs_cn.c: Codecs collection for Mainland Chinese encodings
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
/**

View file

@ -5,13 +5,17 @@
https://docs.python.org/3/license.html │
*/
#define USING_IMPORTED_MAPS
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_hk.inc"
/* clang-format off */
PYTHON_PROVIDE("_codecs_hk");
/*
* _codecs_hk.c: Codecs collection for encodings from Hong Kong
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
/*

View file

@ -5,10 +5,11 @@
https://docs.python.org/3/license.html │
*/
/* clang-format off */
/*
* _codecs_iso2022.c: Codecs collection for ISO-2022 encodings.
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
#define USING_IMPORTED_MAPS
@ -17,11 +18,14 @@
#define EMULATE_JISX0213_2000_ENCODE_INVALID MAP_UNMAPPABLE
#define EMULATE_JISX0213_2000_DECODE_INVALID MAP_UNMAPPABLE
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/alg_jisx0201.inc"
#include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc"
PYTHON_PROVIDE("_codecs_iso2022");
/* STATE
state->c[0-3]

View file

@ -8,7 +8,7 @@
/*
* _codecs_jp.c: Codecs collection for Japanese encodings
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
#define USING_BINARY_PAIR_SEARCH
@ -18,8 +18,11 @@
#include "third_party/python/Modules/cjkcodecs/mappings_jp.inc"
#include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc"
#include "third_party/python/Modules/cjkcodecs/alg_jisx0201.inc"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc"
PYTHON_PROVIDE("_codecs_jp");
/*
* CP932 codec
*/

View file

@ -9,12 +9,15 @@
/*
* _codecs_kr.c: Codecs collection for Korean encodings
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/mappings_kr.inc"
PYTHON_PROVIDE("_codecs_kr");
/*
* EUC-KR codec
*/

View file

@ -2,12 +2,15 @@
/*
* _codecs_tw.c: Codecs collection for Taiwan's encodings
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
* Written by Hye-Shik "Bourne to Macro" Chang <perky@FreeBSD.org>
*/
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/mappings_tw.inc"
PYTHON_PROVIDE("_codecs_tw");
/*
* BIG5 codec
*/

View file

@ -17,9 +17,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/multibytecodec.h"
/* clang-format off */
PYTHON_PROVIDE("_multibytecodec");
#include "third_party/python/Modules/cjkcodecs/clinic/multibytecodec.inc"
/*

View file

@ -18,9 +18,12 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymath.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_math.h"
/* clang-format off */
PYTHON_PROVIDE("cmath");
/* Complex math module */
/* much code borrowed from mathmodule.c */

View file

@ -15,8 +15,11 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("errno");
static PyMethodDef errno_methods[] = {
{NULL, NULL}
};

View file

@ -28,9 +28,12 @@
#include "third_party/python/Include/pythread.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("faulthandler");
/* Allocate at maximum 100 MB of the stack to raise the stack overflow */
#define STACK_OVERFLOW_MAX_SIZE (100*1024*1024)

View file

@ -21,8 +21,11 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("fcntl");
/* fcntl module */
/*[clinic input]

View file

@ -22,8 +22,11 @@
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/weakrefobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("gc");
/*
Reference Cycle Garbage Collection

View file

@ -16,10 +16,13 @@
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/clinic/grpmodule.inc"
#include "third_party/python/Modules/posixmodule.h"
/* clang-format off */
PYTHON_PROVIDE("grp");
/* UNIX group file access module */
/*[clinic input]

View file

@ -13,8 +13,11 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("itertools");
/* Itertools module written and maintained
by Raymond D. Hettinger <python@rcn.com>
*/

View file

@ -23,8 +23,34 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
STATIC_YOINK("PyInit__codecs"); // for pylifecycle.o
STATIC_YOINK("PyInit__collections"); // for pylifecycle.o
STATIC_YOINK("PyInit__functools"); // for pylifecycle.o
STATIC_YOINK("PyInit__heapq"); // for pylifecycle.o
STATIC_YOINK("PyInit__locale"); // for pylifecycle.o
STATIC_YOINK("PyInit__operator"); // for pylifecycle.o
STATIC_YOINK("PyInit__signal"); // for pylifecycle.o
STATIC_YOINK("PyInit__sre"); // for pylifecycle.o
STATIC_YOINK("PyInit__stat"); // for pylifecycle.o
STATIC_YOINK("PyInit_errno"); // for pylifecycle.o
STATIC_YOINK("PyInit_itertools"); // for pylifecycle.o
PYTHON_YOINK("encodings.aliases"); // for pylifecycle.o
PYTHON_YOINK("encodings.latin_1"); // for pylifecycle.o
PYTHON_YOINK("encodings.utf_8"); // for pylifecycle.o
PYTHON_YOINK("io"); // for pylifecycle.o
PYTHON_YOINK("site"); // for pylifecycle.o
PYTHON_YOINK("struct"); // for memoryobject.o
PYTHON_YOINK("_bootlocale");
PYTHON_YOINK("_locale");
PYTHON_YOINK("locale");
PYTHON_YOINK("_sysconfigdata_m_cosmo_x86_64-cosmo");
PYTHON_YOINK("sysconfig");
/* Python interpreter main program */
#if defined(MS_WINDOWS)

View file

@ -19,10 +19,13 @@
#include "third_party/python/Include/pymath.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/_math.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("math");
/* Math module -- standard C math library functions, pi and e */
/* Here are some comments from Tim Peters, extracted from the

View file

@ -13,9 +13,12 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/hashlib.h"
/* clang-format off */
PYTHON_PROVIDE("_md5");
/* See below for information about the original code this module was
based upon. Additional work performed by:

View file

@ -26,8 +26,11 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("mmap");
/*
/ Author: Sam Rushing <rushing@nightmare.com>
/ Hacked for Unix by AMK

View file

@ -7,8 +7,11 @@
#define PY_SSIZE_T_CLEAN
#include "libc/sysv/consts/o.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("ossaudiodev");
/*
* ossaudiodev -- Python interface to the OSS (Open Sound System) API.
* This is the standard audio API for Linux and some

View file

@ -24,8 +24,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/token.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("parser");
/* parsermodule.c
*
* Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic

View file

@ -59,10 +59,13 @@
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/posixmodule.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("posix");
/* POSIX module implementation */
/* This file is also used for Windows NT/MS-Win. In that case the

View file

@ -13,10 +13,13 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/clinic/pwdmodule.inc"
#include "third_party/python/Modules/posixmodule.h"
/* clang-format off */
PYTHON_PROVIDE("pwd");
/* UNIX password file access module */
/*[clinic input]

View file

@ -20,9 +20,12 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/expat/expat.h"
/* clang-format off */
PYTHON_PROVIDE("pyexpat");
/* Do not emit Clinic output to a file as that wreaks havoc with conditionally
included methods. */
/*[clinic input]

File diff suppressed because it is too large Load diff

View file

@ -19,9 +19,12 @@
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("resource");
/* On some systems, these aren't in any header file.
On others they are, with inconsistent prototypes.
We declare the (default) return type, to shut up gcc -Wall;

View file

@ -29,9 +29,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("select");
/* select - Module containing unix select(2) call.
Under Unix, the file descriptors are small integers.
Under Win32, select only exists for sockets, and sockets may

View file

@ -13,9 +13,12 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/hashlib.h"
/* clang-format off */
PYTHON_PROVIDE("_sha1");
/* SHA1 module */
/* This module provides an interface to the SHA1 algorithm */

View file

@ -15,9 +15,12 @@
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/hashlib.h"
/* clang-format off */
PYTHON_PROVIDE("_sha256");
/* This module provides an interface to NIST's SHA-256 and SHA-224 Algorithms */
/* See below for information about the original code this module was

View file

@ -14,9 +14,12 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/hashlib.h"
/* clang-format off */
PYTHON_PROVIDE("_sha512");
/* This module provides an interface to NIST's SHA-512 and SHA-384 Algorithms */
/* See below for information about the original code this module was

View file

@ -26,10 +26,13 @@
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/posixmodule.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("_signal");
/* Signal module -- many thanks to Lance Ellinghaus */
/* XXX Signals should be recorded per thread, now we have thread state. */

View file

@ -50,10 +50,13 @@
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/socketmodule.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("_socket");
/*
This module provides an interface to Berkeley socket IPC.

View file

@ -8,9 +8,12 @@
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/moduleobject.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/clinic/spwdmodule.inc"
/* clang-format off */
PYTHON_PROVIDE("spwd");
/* UNIX shadow password file access module */
/* A lot of code has been taken from pwdmodule.c */
/* For info also see http://www.unixpapa.com/incnote/passwd.html */

View file

@ -12,8 +12,11 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/symtable.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_symtable");
static PyObject *
symtable_symtable(PyObject *self, PyObject *args)
{

View file

@ -16,8 +16,11 @@
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("syslog");
/***********************************************************
Copyright 1994 by Lance Ellinghouse,
Cathedral City, California Republic, United States of America.

View file

@ -22,8 +22,11 @@
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("termios");
/* termiosmodule.c -- POSIX terminal I/O module implementation. */
PyDoc_STRVAR(termios__doc__,

View file

@ -34,9 +34,12 @@
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pytime.h"
#include "third_party/python/Include/structseq.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PYTHON_PROVIDE("time");
typedef int clockid_t;
#undef HAVE_CLOCK_SETTIME

View file

@ -16,8 +16,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/ucnhash.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("unicodedata");
/* ------------------------------------------------------------------------
unicodedata -- Provides access to the Unicode database.

View file

@ -12,8 +12,11 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/typeslots.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("xxlimited");
/* Use this file as a template to start implementing a module that
also declares object types. All occurrences of 'Xxo' should be changed
to something reasonable for your objects. After that, all other

View file

@ -11,8 +11,11 @@
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("xx");
/* Use this file as a template to start implementing a module that
also declares object types. All occurrences of 'Xxo' should be changed
to something reasonable for your objects. After that, all other

View file

@ -15,8 +15,11 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("xxsubtype");
PyDoc_STRVAR(xxsubtype__doc__,
"xxsubtype is an example module showing how to subtype builtin types from C.\n"
"test_descr.py in the standard test suite requires it in order to complete.\n"

View file

@ -32,8 +32,11 @@
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("zipimport");
#define IS_SOURCE 0x0
#define IS_BYTECODE 0x1
#define IS_PACKAGE 0x2

View file

@ -13,9 +13,12 @@
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/zlib/zlib.h"
/* clang-format off */
PYTHON_PROVIDE("zlib");
/* zlibmodule.c -- gzip-compatible data compression */
/* See http://zlib.net/ */

View file

@ -23,6 +23,7 @@
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
/* File object implementation (what's left of it -- see io.py) */
@ -46,27 +47,6 @@
/* External C interface */
PyObject *
PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding,
const char *errors, const char *newline, int closefd)
{
PyObject *io, *stream;
_Py_IDENTIFIER(open);
io = PyImport_ImportModule("io");
if (io == NULL)
return NULL;
stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode,
buffering, encoding, errors,
newline, closefd);
Py_DECREF(io);
if (stream == NULL)
return NULL;
/* ignore name attribute because the name attribute of _BufferedIOMixin
and TextIOWrapper is read only */
return stream;
}
PyObject *
PyFile_GetLine(PyObject *f, int n)
{

34
third_party/python/Objects/fromfd.c vendored Normal file
View file

@ -0,0 +1,34 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_YOINK("io");
PyObject *
PyFile_FromFd(int fd, const char *name, const char *mode, int buffering,
const char *encoding, const char *errors, const char *newline,
int closefd)
{
PyObject *io, *stream;
_Py_IDENTIFIER(open);
io = PyImport_ImportModule("io");
if (io == NULL)
return NULL;
stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode,
buffering, encoding, errors,
newline, closefd);
Py_DECREF(io);
if (stream == NULL)
return NULL;
/* ignore name attribute because the name attribute of _BufferedIOMixin
and TextIOWrapper is read only */
return stream;
}

View file

@ -21,6 +21,7 @@
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/sliceobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
/****************************************************************************/

View file

@ -38,9 +38,12 @@
#include "third_party/python/Include/ucnhash.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Objects/stringlib/eq.inc"
/* clang-format off */
PYTHON_PROVIDE("_string");
/*
Unicode implementation based on original code by Fredrik Lundh,
@ -94,11 +97,6 @@ NOTE: In the interpreter's initialization phase, some globals are currently
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Maximum code point of Unicode 6.0: 0x10ffff (1,114,111) */
#define MAX_UNICODE 0x10ffff
@ -15760,8 +15758,3 @@ PyInit__string(void)
{
return PyModule_Create(&_string_module);
}
#ifdef __cplusplus
}
#endif

View file

@ -356,7 +356,7 @@ winreg_DeleteKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject
static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
HKEY key;
Py_UNICODE *sub_key;
REGSAM access = KEY_WOW64_64KEY;
REGSAM access = /*wut*/ -1 /* KEY_WOW64_64KEY */;
int reserved = 0;
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,

View file

@ -4,6 +4,18 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/isystem/windows.h"
#include "libc/nt/registry.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pyhash.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structmember.h"
/* clang-format off */
/*
@ -20,9 +32,6 @@
*/
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/structmember.h"
static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK);
static BOOL clinic_HKEY_converter(PyObject *ob, void *p);
@ -164,7 +173,7 @@ static PyObject *
PyHKEY_intFunc(PyObject *ob)
{
PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
return PyLong_FromVoidPtr(pyhkey->hkey);
return PyLong_FromVoidPtr((void *)pyhkey->hkey);
}
static PyObject *
@ -841,7 +850,7 @@ winreg_ConnectRegistry_impl(PyObject *module, Py_UNICODE *computer_name,
HKEY retKey;
long rc;
Py_BEGIN_ALLOW_THREADS
rc = RegConnectRegistryW(computer_name, key, &retKey);
rc = RegConnectRegistry(computer_name, key, &retKey);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS) {
PyErr_SetFromWindowsErrWithFunction(rc, "ConnectRegistry");

View file

@ -0,0 +1,2 @@
#include "third_party/python/Programs/repl.c"
PYTHON_YOINK("http.server");

View file

@ -1,46 +1,5 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/sig.h"
#include "libc/unicode/locale.h"
#include "libc/x/x.h"
#include "third_party/linenoise/linenoise.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/funcobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/moduleobject.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
#include "third_party/python/Programs/repl.c"
STATIC_YOINK(".python/");
PYTHON_YOINK("__future__");
PYTHON_YOINK("_bootlocale");
PYTHON_YOINK("_collections_abc");
@ -651,209 +610,3 @@ PYTHON_YOINK("asyncio.unix_events");
PYTHON_YOINK("asyncio.windows_events");
PYTHON_YOINK("asyncio.windows_utils");
#endif
const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
static jmp_buf jbuf;
static void
OnKeyboardInterrupt(int sig)
{
gclongjmp(jbuf, 1);
}
static void
AddCompletion(linenoiseCompletions *c, char *s)
{
c->cvec = realloc(c->cvec, ++c->len * sizeof(*c->cvec));
c->cvec[c->len - 1] = s;
}
static void
CompleteDict(const char *b, const char *q, const char *p,
linenoiseCompletions *c, PyObject *o)
{
const char *s;
PyObject *k, *v;
Py_ssize_t i, m;
for (i = 0; PyDict_Next(o, &i, &k, &v);) {
if ((v != Py_None && PyUnicode_Check(k) &&
(s = PyUnicode_AsUTF8AndSize(k, &m)) &&
m >= q - p && !memcmp(s, p, q - p))) {
AddCompletion(c, xasprintf("%.*s%.*s", p - b, b, m, s));
}
}
}
static void
CompleteDir(const char *b, const char *q, const char *p,
linenoiseCompletions *c, PyObject *o)
{
Py_ssize_t m;
const char *s;
PyObject *d, *i, *k;
if (!(d = PyObject_Dir(o))) return;
if ((i = PyObject_GetIter(d))) {
while ((k = PyIter_Next(i))) {
if (((s = PyUnicode_AsUTF8AndSize(k, &m)) &&
m >= q - p && !memcmp(s, p, q - p))) {
AddCompletion(c, xasprintf("%.*s%.*s", p - b, b, m, s));
}
Py_DECREF(k);
}
Py_DECREF(i);
}
Py_DECREF(d);
}
static void
TerminalCompletion(const char *p, linenoiseCompletions *c)
{
PyObject *o, *t, *i;
const char *q, *s, *b;
for (b = p, p += strlen(p); p > b; --p) {
if (!isalnum(p[-1]) && p[-1] != '.' && p[-1] != '_') {
break;
}
}
o = PyModule_GetDict(PyImport_AddModule("__main__"));
if (!*(q = strchrnul(p, '.'))) {
CompleteDict(b, q, p, c, o);
CompleteDir(b, q, p, c, PyDict_GetItemString(o, "__builtins__"));
} else {
s = strndup(p, q - p);
if ((t = PyDict_GetItemString(o, s))) {
Py_INCREF(t);
} else {
o = PyDict_GetItemString(o, "__builtins__");
if (PyObject_HasAttrString(o, s)) {
t = PyObject_GetAttrString(o, s);
}
}
while ((p = q + 1), (o = t)) {
if (*(q = strchrnul(p, '.'))) {
t = PyObject_GetAttrString(o, gc(strndup(p, q - p)));
Py_DECREF(o);
} else {
CompleteDir(b, q, p, c, o);
Py_DECREF(o);
break;
}
}
free(s);
}
}
static char *
TerminalHint(const char *p, const char **ansi1, const char **ansi2)
{
char *h = 0;
linenoiseCompletions c = {0};
TerminalCompletion(p, &c);
if (c.len == 1) {
h = strdup(c.cvec[0] + strlen(p));
}
linenoiseFreeCompletions(&c);
return h;
}
static char *
TerminalReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
{
size_t n;
char *p, *q;
PyOS_sighandler_t saint;
saint = PyOS_setsig(SIGINT, OnKeyboardInterrupt);
if (setjmp(jbuf)) {
linenoiseDisableRawMode(STDIN_FILENO);
PyOS_setsig(SIGINT, saint);
return NULL;
}
p = ezlinenoise(prompt, "python");
PyOS_setsig(SIGINT, saint);
if (p) {
n = strlen(p);
q = PyMem_RawMalloc(n + 2);
strcpy(mempcpy(q, p, n), "\n");
free(p);
clearerr(sys_stdin);
} else {
q = PyMem_RawMalloc(1);
if (q) *q = 0;
}
return q;
}
int
main(int argc, char **argv)
{
wchar_t **argv_copy;
/* We need a second copy, as Python might modify the first one. */
wchar_t **argv_copy2;
int i, res;
char *oldloc;
/* if (FindDebugBinary()) { */
/* ShowCrashReports(); */
/* } */
PyOS_ReadlineFunctionPointer = TerminalReadline;
linenoiseSetCompletionCallback(TerminalCompletion);
linenoiseSetHintsCallback(TerminalHint);
linenoiseSetFreeHintsCallback(free);
/* Force malloc() allocator to bootstrap Python */
_PyMem_SetupAllocators("malloc");
argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
if (!argv_copy || !argv_copy2) {
fprintf(stderr, "out of memory\n");
return 1;
}
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
* Python requires non-stop mode. Alas, some platforms enable FP
* exceptions by default. Here we disable them.
*/
#ifdef __FreeBSD__
fedisableexcept(FE_OVERFLOW);
#endif
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
if (!oldloc) {
fprintf(stderr, "out of memory\n");
return 1;
}
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
if (!argv_copy[i]) {
PyMem_RawFree(oldloc);
fprintf(stderr, "Fatal Python error: "
"unable to decode the command line argument #%i\n",
i + 1);
return 1;
}
argv_copy2[i] = argv_copy[i];
}
argv_copy2[argc] = argv_copy[argc] = NULL;
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
res = Py_Main(argc, argv_copy);
/* Force again malloc() allocator to release memory blocks allocated
before Py_Main() */
_PyMem_SetupAllocators("malloc");
for (i = 0; i < argc; i++) {
PyMem_RawFree(argv_copy2[i]);
}
PyMem_RawFree(argv_copy);
PyMem_RawFree(argv_copy2);
return res;
}

247
third_party/python/Programs/repl.c vendored Normal file
View file

@ -0,0 +1,247 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/sig.h"
#include "libc/unicode/locale.h"
#include "libc/x/x.h"
#include "third_party/linenoise/linenoise.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/funcobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/moduleobject.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
static jmp_buf jbuf;
static void
OnKeyboardInterrupt(int sig)
{
gclongjmp(jbuf, 1);
}
static void
AddCompletion(linenoiseCompletions *c, char *s)
{
c->cvec = realloc(c->cvec, ++c->len * sizeof(*c->cvec));
c->cvec[c->len - 1] = s;
}
static void
CompleteDict(const char *b, const char *q, const char *p,
linenoiseCompletions *c, PyObject *o)
{
const char *s;
PyObject *k, *v;
Py_ssize_t i, m;
for (i = 0; PyDict_Next(o, &i, &k, &v);) {
if ((v != Py_None && PyUnicode_Check(k) &&
(s = PyUnicode_AsUTF8AndSize(k, &m)) &&
m >= q - p && !memcmp(s, p, q - p))) {
AddCompletion(c, xasprintf("%.*s%.*s", p - b, b, m, s));
}
}
}
static void
CompleteDir(const char *b, const char *q, const char *p,
linenoiseCompletions *c, PyObject *o)
{
Py_ssize_t m;
const char *s;
PyObject *d, *i, *k;
if (!(d = PyObject_Dir(o))) return;
if ((i = PyObject_GetIter(d))) {
while ((k = PyIter_Next(i))) {
if (((s = PyUnicode_AsUTF8AndSize(k, &m)) &&
m >= q - p && !memcmp(s, p, q - p))) {
AddCompletion(c, xasprintf("%.*s%.*s", p - b, b, m, s));
}
Py_DECREF(k);
}
Py_DECREF(i);
}
Py_DECREF(d);
}
static void
TerminalCompletion(const char *p, linenoiseCompletions *c)
{
PyObject *o, *t, *i;
const char *q, *s, *b;
for (b = p, p += strlen(p); p > b; --p) {
if (!isalnum(p[-1]) && p[-1] != '.' && p[-1] != '_') {
break;
}
}
o = PyModule_GetDict(PyImport_AddModule("__main__"));
if (!*(q = strchrnul(p, '.'))) {
CompleteDict(b, q, p, c, o);
CompleteDir(b, q, p, c, PyDict_GetItemString(o, "__builtins__"));
} else {
s = strndup(p, q - p);
if ((t = PyDict_GetItemString(o, s))) {
Py_INCREF(t);
} else {
o = PyDict_GetItemString(o, "__builtins__");
if (PyObject_HasAttrString(o, s)) {
t = PyObject_GetAttrString(o, s);
}
}
while ((p = q + 1), (o = t)) {
if (*(q = strchrnul(p, '.'))) {
t = PyObject_GetAttrString(o, gc(strndup(p, q - p)));
Py_DECREF(o);
} else {
CompleteDir(b, q, p, c, o);
Py_DECREF(o);
break;
}
}
free(s);
}
}
static char *
TerminalHint(const char *p, const char **ansi1, const char **ansi2)
{
char *h = 0;
linenoiseCompletions c = {0};
TerminalCompletion(p, &c);
if (c.len == 1) {
h = strdup(c.cvec[0] + strlen(p));
}
linenoiseFreeCompletions(&c);
return h;
}
static char *
TerminalReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
{
size_t n;
char *p, *q;
PyOS_sighandler_t saint;
saint = PyOS_setsig(SIGINT, OnKeyboardInterrupt);
if (setjmp(jbuf)) {
linenoiseDisableRawMode(STDIN_FILENO);
PyOS_setsig(SIGINT, saint);
return NULL;
}
p = ezlinenoise(prompt, "python");
PyOS_setsig(SIGINT, saint);
if (p) {
n = strlen(p);
q = PyMem_RawMalloc(n + 2);
strcpy(mempcpy(q, p, n), "\n");
free(p);
clearerr(sys_stdin);
} else {
q = PyMem_RawMalloc(1);
if (q) *q = 0;
}
return q;
}
int
main(int argc, char **argv)
{
wchar_t **argv_copy;
/* We need a second copy, as Python might modify the first one. */
wchar_t **argv_copy2;
int i, res;
char *oldloc;
/* if (FindDebugBinary()) { */
/* ShowCrashReports(); */
/* } */
PyOS_ReadlineFunctionPointer = TerminalReadline;
linenoiseSetCompletionCallback(TerminalCompletion);
linenoiseSetHintsCallback(TerminalHint);
linenoiseSetFreeHintsCallback(free);
/* Force malloc() allocator to bootstrap Python */
_PyMem_SetupAllocators("malloc");
argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
if (!argv_copy || !argv_copy2) {
fprintf(stderr, "out of memory\n");
return 1;
}
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
* Python requires non-stop mode. Alas, some platforms enable FP
* exceptions by default. Here we disable them.
*/
#ifdef __FreeBSD__
fedisableexcept(FE_OVERFLOW);
#endif
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
if (!oldloc) {
fprintf(stderr, "out of memory\n");
return 1;
}
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
if (!argv_copy[i]) {
PyMem_RawFree(oldloc);
fprintf(stderr, "Fatal Python error: "
"unable to decode the command line argument #%i\n",
i + 1);
return 1;
}
argv_copy2[i] = argv_copy[i];
}
argv_copy2[argc] = argv_copy[argc] = NULL;
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
res = Py_Main(argc, argv_copy);
/* Force again malloc() allocator to release memory blocks allocated
before Py_Main() */
_PyMem_SetupAllocators("malloc");
for (i = 0; i < argc; i++) {
PyMem_RawFree(argv_copy2[i]);
}
PyMem_RawFree(argv_copy);
PyMem_RawFree(argv_copy2);
return res;
}

View file

@ -17,8 +17,11 @@
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_ast");
/* File automatically generated by Parser/asdl_c.py. */
static PyTypeObject AST_type;
@ -7862,6 +7865,7 @@ failed:
static struct PyModuleDef _astmodule = {
PyModuleDef_HEAD_INIT, "_ast"
};
PyMODINIT_FUNC
PyInit__ast(void)
{
@ -8112,5 +8116,3 @@ int PyAST_Check(PyObject* obj)
return -1;
return PyObject_IsInstance(obj, (PyObject*)&AST_type);
}

Some files were not shown because too many files have changed in this diff Show more