Decentralize Python native module linkage

We can now link even smaller Python binaries. For example, the hello.com
program in the Python build directory is a compiled linked executable of
hello.py which just prints hello world. Using decentralized sections, we
can make that binary 1.9mb in size (noting that python.com is 6.3 megs!)

This works for nontrivial programs too. For example, say we want an APE
binary that's equivalent to python.com -m http.server. Our makefile now
builds such a binary using the new launcher and it's only 3.2mb in size
since Python sources get turned into ELF objects, which tell our linker
that we need things like native hashing algorithm code.
This commit is contained in:
Justine Tunney 2021-09-07 11:40:11 -07:00
parent dfa0359b50
commit 559b024e1d
129 changed files with 2798 additions and 13514 deletions

View file

@ -107,7 +107,7 @@ struct _inittab {
const char *name; /* ASCII encoded string */
PyObject* (*initfunc)(void);
};
extern struct _inittab _PyImport_Inittab[];
extern const struct _inittab _PyImport_Inittab[];
extern struct _inittab * PyImport_Inittab;
int PyImport_ExtendInittab(struct _inittab *newtab);
#endif /* Py_LIMITED_API */

View file

@ -59,6 +59,7 @@ wchar_t * Py_GetPrefix(void);
wchar_t * Py_GetExecPrefix(void);
wchar_t * Py_GetPath(void);
void Py_SetPath(const wchar_t *);
void Py_LimitedPath(void);
#ifdef MS_WINDOWS
int _Py_CheckPython3();
#endif

View file

@ -7,28 +7,15 @@ Don't import directly from third-party code; use the `locale` module instead!
import sys
import _locale
if sys.platform.startswith("win"):
def getpreferredencoding(do_setlocale=True):
return _locale._getdefaultlocale()[1]
else:
try:
_locale.CODESET
except AttributeError:
def getpreferredencoding(do_setlocale=True):
# This path for legacy systems needs the more complex
# getdefaultlocale() function, import the full locale module.
import locale
return locale.getpreferredencoding(do_setlocale)
else:
def getpreferredencoding(do_setlocale=True):
assert not do_setlocale
result = _locale.nl_langinfo(_locale.CODESET)
if not result and sys.platform in ('darwin', 'cosmo'):
# nl_langinfo can return an empty string
# when the setting has an invalid value.
# Default to UTF-8 in that case because
# UTF-8 is the default charset on OSX and
# returning nothing will crash the
# interpreter.
result = 'UTF-8'
return result
def getpreferredencoding(do_setlocale=True):
assert not do_setlocale
result = _locale.nl_langinfo(_locale.CODESET)
if not result and sys.platform in ('darwin', 'cosmo'):
# nl_langinfo can return an empty string
# when the setting has an invalid value.
# Default to UTF-8 in that case because
# UTF-8 is the default charset on OSX and
# returning nothing will crash the
# interpreter.
result = 'UTF-8'
return result

View file

@ -11,7 +11,7 @@ FUNCTIONS:
"""
import time
import locale
# import locale
import calendar
from re import compile as re_compile
from re import IGNORECASE
@ -28,7 +28,8 @@ __all__ = []
def _getlang():
# Figure out what the current language is set to.
return locale.getlocale(locale.LC_TIME)
# return locale.getlocale(locale.LC_TIME)
return (None, None)
class LocaleTime(object):
"""Stores and handles locale-specific information related to time.

View file

@ -39,17 +39,10 @@ from _weakref import proxy as _proxy
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
from reprlib import recursive_repr as _recursive_repr
try:
from _collections import deque
except ImportError:
pass
else:
MutableSequence.register(deque)
from _collections import deque
MutableSequence.register(deque)
try:
from _collections import defaultdict
except ImportError:
pass
from _collections import defaultdict
################################################################################

View file

@ -11,8 +11,7 @@ new(name, data=b'', **kwargs) - returns a new hash object implementing the
Named constructor functions are also available, these are faster
than using new(name):
md5(), sha1(), sha224(), sha256(), sha384(), sha512(),
sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256.
md5(), sha1(), sha224(), sha256(), sha384(), sha512(), and blake2b256().
More algorithms may be available on your platform but the above are guaranteed
to exist. See the algorithms_guaranteed and algorithms_available attributes
@ -56,9 +55,7 @@ More condensed:
# This tuple and __get_builtin_constructor() must be modified if a new
# always available algorithm is added.
__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
'shake_128', 'shake_256')
'blake2b256')
algorithms_guaranteed = set(__always_supported)
algorithms_available = set(__always_supported)
@ -73,23 +70,12 @@ def __get_builtin_constructor(name):
constructor = cache.get(name)
if constructor is not None:
return constructor
try:
if name in ('SHA1', 'sha1'):
import _sha1
cache['SHA1'] = cache['sha1'] = _sha1.sha1
elif name in ('MD5', 'md5'):
import _md5
cache['MD5'] = cache['md5'] = _md5.md5
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
cache['SHA224'] = cache['sha224'] = _sha256.sha224
cache['SHA256'] = cache['sha256'] = _sha256.sha256
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
cache['SHA384'] = cache['sha384'] = _sha512.sha384
cache['SHA512'] = cache['sha512'] = _sha512.sha512
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
'shake_128', 'shake_256'}:
if name in ('MD5', 'md5'):
import _md5
cache['MD5'] = cache['md5'] = _md5.md5
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
'shake_128', 'shake_256'}:
try:
import _sha3
cache['sha3_224'] = _sha3.sha3_224
cache['sha3_256'] = _sha3.sha3_256
@ -97,21 +83,19 @@ def __get_builtin_constructor(name):
cache['sha3_512'] = _sha3.sha3_512
cache['shake_128'] = _sha3.shake_128
cache['shake_256'] = _sha3.shake_256
except ImportError:
pass # no extension module, this hash is unsupported.
except ImportError:
raise ValueError('unsupported hash type ' + name)
constructor = cache.get(name)
if constructor is not None:
return constructor
raise ValueError('unsupported hash type ' + name)
def __get_openssl_constructor(name):
def __get_mbedtls_constructor(name):
try:
f = getattr(_hashlib, 'openssl_' + name)
f = getattr(_hashlib, 'mbedtls_' + name)
# Allow the C module to raise ValueError. The function will be
# defined but the hash not actually available thanks to OpenSSL.
# defined but the hash not actually available thanks to Mbedtls.
f()
# Use the C function directly (very fast)
return f
@ -134,25 +118,21 @@ def __hash_new(name, data=b'', **kwargs):
try:
return _hashlib.new(name, data)
except ValueError:
# If the _hashlib module (OpenSSL) doesn't support the named
# If the _hashlib module (Mbedtls) doesn't support the named
# hash, try using our builtin implementations.
# This allows for SHA224/256 and SHA384/512 support even though
# the OpenSSL library prior to 0.9.8 doesn't provide them.
# the Mbedtls library prior to 0.9.8 doesn't provide them.
return __get_builtin_constructor(name)(data)
try:
import _hashlib
new = __hash_new
__get_hash = __get_openssl_constructor
algorithms_available = algorithms_available.union(
_hashlib.openssl_md_meth_names)
except ImportError:
new = __py_new
__get_hash = __get_builtin_constructor
import _hashlib
new = __hash_new
__get_hash = __get_mbedtls_constructor
algorithms_available = algorithms_available.union(
_hashlib.mbedtls_md_meth_names)
try:
# OpenSSL's PKCS5_PBKDF2_HMAC requires OpenSSL 1.0+ with HMAC and SHA
# Mbedtls's PKCS5_PBKDF2_HMAC requires Mbedtls 1.0+ with HMAC and SHA
from _hashlib import pbkdf2_hmac
except ImportError:
_trans_5C = bytes((x ^ 0x5C) for x in range(256))
@ -162,7 +142,7 @@ except ImportError:
"""Password based key derivation function 2 (PKCS #5 v2.0)
This Python implementations based on the hmac module about as fast
as OpenSSL's PKCS5_PBKDF2_HMAC for short passwords and much faster
as Mbedtls's PKCS5_PBKDF2_HMAC for short passwords and much faster
for long passwords.
"""
if not isinstance(hash_name, str):
@ -216,26 +196,19 @@ except ImportError:
return dkey[:dklen]
try:
# OpenSSL's scrypt requires OpenSSL 1.1+
# Mbedtls's scrypt requires Mbedtls 1.1+
from _hashlib import scrypt
except ImportError:
pass
md5 = __get_hash('md5')
sha1 = __get_hash('sha1')
sha224 = __get_hash('sha224')
sha256 = __get_hash('sha256')
sha384 = __get_hash('sha384')
sha512 = __get_hash('sha512')
sha3_224 = __get_hash('sha3_224')
sha3_256 = __get_hash('sha3_256')
sha3_384 = __get_hash('sha3_384')
sha3_512 = __get_hash('sha3_512')
shake_128 = __get_hash('shake_128')
shake_256 = __get_hash('shake_256')
blake2b256 = __get_hash('blake2b256')
# Cleanup locals()
del __always_supported, __get_hash
del __py_new, __hash_new, __get_openssl_constructor
del __py_new, __hash_new, __get_mbedtls_constructor

1
third_party/python/Lib/hello.py vendored Normal file
View file

@ -0,0 +1 @@
print("hello world")

View file

@ -1364,7 +1364,7 @@ def _get_supported_file_loaders():
extensions = ExtensionFileLoader, _imp.extension_suffixes()
source = SourceFileLoader, SOURCE_SUFFIXES
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
return [extensions, bytecode, source]
return [bytecode, extensions, source]
def _setup(_bootstrap_module):

15
third_party/python/Lib/launchpy.py vendored Normal file
View file

@ -0,0 +1,15 @@
import sys
from importlib import _bootstrap_external
def run_module_as_main(mod_name):
path = "/zip/.python/%s.pyc" % (mod_name.replace(".", "/"))
loader = _bootstrap_external.SourcelessFileLoader(mod_name, path)
code = loader.get_code(mod_name)
globs = sys.modules["__main__"].__dict__
globs["__name__"] = "__main__"
globs["__file__"] = path
globs["__package__"] = None
globs["__loader__"] = loader
globs["__spec__"] = None
exec(code, globs)
return globs

View file

@ -1158,7 +1158,10 @@ def popen(cmd, mode="r", buffering=-1):
raise ValueError("invalid mode %r" % mode)
if buffering == 0 or buffering is None:
raise ValueError("popen() does not support unbuffered streams")
import subprocess, io
try:
import subprocess, io
except ImportError:
raise ImportError('please use subprocess module')
if mode == "r":
proc = subprocess.Popen(cmd,
shell=True,

View file

@ -2193,10 +2193,13 @@ def _start_server(urlhandler, port):
>>> print(serverthread.error)
None
"""
import http.server
import email.message
import select
import threading
try:
import http.server
import email.message
import select
import threading
except ImportError:
sys.exit(1)
class DocHandler(http.server.BaseHTTPRequestHandler):

View file

@ -626,7 +626,10 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
raise ValueError("bad value for 'compress', or compression format not "
"supported : {0}".format(compress))
import tarfile # late import for breaking circular dependency
try:
import tarfile
except ImportError:
raise
compress_ext = '.' + tar_compression if compress else ''
archive_name = base_name + '.tar' + compress_ext
@ -669,7 +672,10 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
The output zip file will be named 'base_name' + ".zip". Returns the
name of the output zip file.
"""
import zipfile # late import for breaking circular dependency
try:
import zipfile
except ImportError:
raise
zip_filename = base_name + ".zip"
archive_dir = os.path.dirname(base_name)
@ -877,7 +883,10 @@ def _ensure_directory(path):
def _unpack_zipfile(filename, extract_dir):
"""Unpack zip `filename` to `extract_dir`
"""
import zipfile # late import for breaking circular dependency
try:
import zipfile
except ImportError:
raise
if not zipfile.is_zipfile(filename):
raise ReadError("%s is not a zip file" % filename)
@ -911,7 +920,10 @@ def _unpack_zipfile(filename, extract_dir):
def _unpack_tarfile(filename, extract_dir):
"""Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir`
"""
import tarfile # late import for breaking circular dependency
try:
import tarfile
except ImportError:
raise
try:
tarobj = tarfile.open(filename)
except tarfile.TarError:
@ -1003,22 +1015,6 @@ if hasattr(os, 'statvfs'):
used = (st.f_blocks - st.f_bfree) * st.f_frsize
return _ntuple_diskusage(total, used, free)
elif os.name == 'nt':
import nt
__all__.append('disk_usage')
_ntuple_diskusage = collections.namedtuple('usage', 'total used free')
def disk_usage(path):
"""Return disk usage statistics about the given path.
Returned values is a named tuple with attributes 'total', 'used' and
'free', which are the amount of total, used and free space, in bytes.
"""
total, free = nt._getdiskusage(path)
used = total - free
return _ntuple_diskusage(total, used, free)
def chown(path, user=None, group=None):
"""Change owner user and group of the given path.

View file

@ -6,6 +6,7 @@
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -282,3 +283,8 @@ PyInit__bisect(void)
{
return PyModule_Create(&_bisectmodule);
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__bisect = {
"_bisect",
PyInit__bisect,
};

View file

@ -9,6 +9,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
@ -814,3 +815,8 @@ PyInit__bz2(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__bz2 = {
"_bz2",
PyInit__bz2,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/codecs.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"

View file

@ -4,6 +4,7 @@
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"

View file

@ -7,6 +7,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
@ -1715,3 +1716,8 @@ PyInit__csv(void)
PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__csv = {
"_csv",
PyInit__csv,
};

View file

@ -1,552 +0,0 @@
/*-*- 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/yoink.h"
/* clang-format off */
PYTHON_PROVIDE("_curses_panel");
PYTHON_PROVIDE("_curses_panel.bottom_panel");
PYTHON_PROVIDE("_curses_panel.error");
PYTHON_PROVIDE("_curses_panel.new_panel");
PYTHON_PROVIDE("_curses_panel.top_panel");
PYTHON_PROVIDE("_curses_panel.update_panels");
PYTHON_PROVIDE("_curses_panel.version");
/*
* Interface to the ncurses panel library
*
* Original version by Thomas Gellekum
*/
/* Release Number */
static const char PyCursesVersion[] = "2.1";
/* Includes */
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/py_curses.h"
typedef struct {
PyObject *PyCursesError;
PyObject *PyCursesPanel_Type;
} _curses_panelstate;
#define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o))
static int
_curses_panel_clear(PyObject *m)
{
Py_CLEAR(_curses_panelstate(m)->PyCursesError);
return 0;
}
static int
_curses_panel_traverse(PyObject *m, visitproc visit, void *arg)
{
Py_VISIT(_curses_panelstate(m)->PyCursesError);
return 0;
}
static void
_curses_panel_free(void *m)
{
_curses_panel_clear((PyObject *) m);
}
static struct PyModuleDef _curses_panelmodule;
#define _curses_panelstate_global \
((_curses_panelstate *) PyModule_GetState(PyState_FindModule(&_curses_panelmodule)))
/* Utility Functions */
/*
* Check the return code from a curses function and return None
* or raise an exception as appropriate.
*/
static PyObject *
PyCursesCheckERR(int code, const char *fname)
{
if (code != ERR) {
Py_INCREF(Py_None);
return Py_None;
} else {
if (fname == NULL) {
PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_ERR);
} else {
PyErr_Format(_curses_panelstate_global->PyCursesError, "%s() returned ERR", fname);
}
return NULL;
}
}
/*****************************************************************************
The Panel Object
******************************************************************************/
/* Definition of the panel object and panel type */
typedef struct {
PyObject_HEAD
PANEL *pan;
PyCursesWindowObject *wo; /* for reference counts */
} PyCursesPanelObject;
#define PyCursesPanel_Check(v) \
(Py_TYPE(v) == _curses_panelstate_global->PyCursesPanel_Type)
/* Some helper functions. The problem is that there's always a window
associated with a panel. To ensure that Python's GC doesn't pull
this window from under our feet we need to keep track of references
to the corresponding window object within Python. We can't use
dupwin(oldwin) to keep a copy of the curses WINDOW because the
contents of oldwin is copied only once; code like
win = newwin(...)
pan = win.panel()
win.addstr(some_string)
pan.window().addstr(other_string)
will fail. */
/* We keep a linked list of PyCursesPanelObjects, lop. A list should
suffice, I don't expect more than a handful or at most a few
dozens of panel objects within a typical program. */
typedef struct _list_of_panels {
PyCursesPanelObject *po;
struct _list_of_panels *next;
} list_of_panels;
/* list anchor */
static list_of_panels *lop;
/* Insert a new panel object into lop */
static int
insert_lop(PyCursesPanelObject *po)
{
list_of_panels *new;
if ((new = (list_of_panels *)PyMem_Malloc(sizeof(list_of_panels))) == NULL) {
PyErr_NoMemory();
return -1;
}
new->po = po;
new->next = lop;
lop = new;
return 0;
}
/* Remove the panel object from lop */
static void
remove_lop(PyCursesPanelObject *po)
{
list_of_panels *temp, *n;
temp = lop;
if (temp->po == po) {
lop = temp->next;
PyMem_Free(temp);
return;
}
while (temp->next == NULL || temp->next->po != po) {
if (temp->next == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"remove_lop: can't find Panel Object");
return;
}
temp = temp->next;
}
n = temp->next->next;
PyMem_Free(temp->next);
temp->next = n;
return;
}
/* Return the panel object that corresponds to pan */
static PyCursesPanelObject *
find_po(PANEL *pan)
{
list_of_panels *temp;
for (temp = lop; temp->po->pan != pan; temp = temp->next)
if (temp->next == NULL) return NULL; /* not found!? */
return temp->po;
}
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
X - function name
TYPE - parameter Type
ERGSTR - format string for construction of the return value
PARSESTR - format string for argument parsing */
#define Panel_NoArgNoReturnFunction(X) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
{ return PyCursesCheckERR(X(self->pan), # X); }
#define Panel_NoArgTrueFalseFunction(X) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
{ \
if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
else { Py_INCREF(Py_True); return Py_True; } }
#define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
{ \
TYPE arg1, arg2; \
if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \
return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); }
/* ------------- PANEL routines --------------- */
Panel_NoArgNoReturnFunction(bottom_panel)
Panel_NoArgNoReturnFunction(hide_panel)
Panel_NoArgNoReturnFunction(show_panel)
Panel_NoArgNoReturnFunction(top_panel)
Panel_NoArgTrueFalseFunction(panel_hidden)
Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x")
/* Allocation and deallocation of Panel Objects */
static PyObject *
PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
{
PyCursesPanelObject *po;
po = PyObject_NEW(PyCursesPanelObject,
(PyTypeObject *)(_curses_panelstate_global)->PyCursesPanel_Type);
if (po == NULL) return NULL;
po->pan = pan;
if (insert_lop(po) < 0) {
po->wo = NULL;
Py_DECREF(po);
return NULL;
}
po->wo = wo;
Py_INCREF(wo);
return (PyObject *)po;
}
static void
PyCursesPanel_Dealloc(PyCursesPanelObject *po)
{
PyObject *obj = (PyObject *) panel_userptr(po->pan);
if (obj) {
(void)set_panel_userptr(po->pan, NULL);
Py_DECREF(obj);
}
(void)del_panel(po->pan);
if (po->wo != NULL) {
Py_DECREF(po->wo);
remove_lop(po);
}
PyObject_DEL(po);
}
/* panel_above(NULL) returns the bottom panel in the stack. To get
this behaviour we use curses.panel.bottom_panel(). */
static PyObject *
PyCursesPanel_above(PyCursesPanelObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
pan = panel_above(self->pan);
if (pan == NULL) { /* valid output, it means the calling panel
is on top of the stack */
Py_INCREF(Py_None);
return Py_None;
}
po = find_po(pan);
if (po == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"panel_above: can't find Panel Object");
return NULL;
}
Py_INCREF(po);
return (PyObject *)po;
}
/* panel_below(NULL) returns the top panel in the stack. To get
this behaviour we use curses.panel.top_panel(). */
static PyObject *
PyCursesPanel_below(PyCursesPanelObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
pan = panel_below(self->pan);
if (pan == NULL) { /* valid output, it means the calling panel
is on the bottom of the stack */
Py_INCREF(Py_None);
return Py_None;
}
po = find_po(pan);
if (po == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"panel_below: can't find Panel Object");
return NULL;
}
Py_INCREF(po);
return (PyObject *)po;
}
static PyObject *
PyCursesPanel_window(PyCursesPanelObject *self)
{
Py_INCREF(self->wo);
return (PyObject *)self->wo;
}
static PyObject *
PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
{
PyCursesPanelObject *po;
PyCursesWindowObject *temp;
int rtn;
if (PyTuple_Size(args) != 1) {
PyErr_SetString(PyExc_TypeError, "replace requires one argument");
return NULL;
}
if (!PyArg_ParseTuple(args, "O!;window object",
&PyCursesWindow_Type, &temp))
return NULL;
po = find_po(self->pan);
if (po == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"replace_panel: can't find Panel Object");
return NULL;
}
rtn = replace_panel(self->pan, temp->win);
if (rtn == ERR) {
PyErr_SetString(_curses_panelstate_global->PyCursesError, "replace_panel() returned ERR");
return NULL;
}
Py_INCREF(temp);
Py_SETREF(po->wo, temp);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
{
PyObject *oldobj;
int rc;
PyCursesInitialised;
Py_INCREF(obj);
oldobj = (PyObject *) panel_userptr(self->pan);
rc = set_panel_userptr(self->pan, (void*)obj);
if (rc == ERR) {
/* In case of an ncurses error, decref the new object again */
Py_DECREF(obj);
}
Py_XDECREF(oldobj);
return PyCursesCheckERR(rc, "set_panel_userptr");
}
static PyObject *
PyCursesPanel_userptr(PyCursesPanelObject *self)
{
PyObject *obj;
PyCursesInitialised;
obj = (PyObject *) panel_userptr(self->pan);
if (obj == NULL) {
PyErr_SetString(_curses_panelstate_global->PyCursesError, "no userptr set");
return NULL;
}
Py_INCREF(obj);
return obj;
}
/* Module interface */
static PyMethodDef PyCursesPanel_Methods[] = {
{"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS},
{"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS},
{"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS},
{"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS},
{"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS},
{"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS},
{"replace", (PyCFunction)PyCursesPanel_replace_panel, METH_VARARGS},
{"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O},
{"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS},
{"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS},
{"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS},
{"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
/* -------------------------------------------------------*/
static PyType_Slot PyCursesPanel_Type_slots[] = {
{Py_tp_dealloc, PyCursesPanel_Dealloc},
{Py_tp_methods, PyCursesPanel_Methods},
{0, 0},
};
static PyType_Spec PyCursesPanel_Type_spec = {
"_curses_panel.curses panel",
sizeof(PyCursesPanelObject),
0,
Py_TPFLAGS_DEFAULT,
PyCursesPanel_Type_slots
};
/* Wrapper for panel_above(NULL). This function returns the bottom
panel of the stack, so it's renamed to bottom_panel().
panel.above() *requires* a panel object in the first place which
may be undesirable. */
static PyObject *
PyCurses_bottom_panel(PyObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
PyCursesInitialised;
pan = panel_above(NULL);
if (pan == NULL) { /* valid output, it means
there's no panel at all */
Py_INCREF(Py_None);
return Py_None;
}
po = find_po(pan);
if (po == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"panel_above: can't find Panel Object");
return NULL;
}
Py_INCREF(po);
return (PyObject *)po;
}
static PyObject *
PyCurses_new_panel(PyObject *self, PyObject *args)
{
PyCursesWindowObject *win;
PANEL *pan;
if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win))
return NULL;
pan = new_panel(win->win);
if (pan == NULL) {
PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesPanel_New(pan, win);
}
/* Wrapper for panel_below(NULL). This function returns the top panel
of the stack, so it's renamed to top_panel(). panel.below()
*requires* a panel object in the first place which may be
undesirable. */
static PyObject *
PyCurses_top_panel(PyObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
PyCursesInitialised;
pan = panel_below(NULL);
if (pan == NULL) { /* valid output, it means
there's no panel at all */
Py_INCREF(Py_None);
return Py_None;
}
po = find_po(pan);
if (po == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"panel_below: can't find Panel Object");
return NULL;
}
Py_INCREF(po);
return (PyObject *)po;
}
static PyObject *PyCurses_update_panels(PyObject *self)
{
PyCursesInitialised;
update_panels();
Py_INCREF(Py_None);
return Py_None;
}
/* List of functions defined in the module */
static PyMethodDef PyCurses_methods[] = {
{"bottom_panel", (PyCFunction)PyCurses_bottom_panel, METH_NOARGS},
{"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS},
{"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS},
{"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
/* Initialization function for the module */
static struct PyModuleDef _curses_panelmodule = {
PyModuleDef_HEAD_INIT,
"_curses_panel",
NULL,
sizeof(_curses_panelstate),
PyCurses_methods,
NULL,
_curses_panel_traverse,
_curses_panel_clear,
_curses_panel_free
};
PyMODINIT_FUNC
PyInit__curses_panel(void)
{
PyObject *m, *d, *v;
/* Create the module and add the functions */
m = PyModule_Create(&_curses_panelmodule);
if (m == NULL)
goto fail;
d = PyModule_GetDict(m);
/* Initialize object type */
v = PyType_FromSpec(&PyCursesPanel_Type_spec);
if (v == NULL)
goto fail;
((PyTypeObject *)v)->tp_new = NULL;
_curses_panelstate(m)->PyCursesPanel_Type = v;
import_curses();
if (PyErr_Occurred())
goto fail;
/* For exception _curses_panel.error */
_curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError);
/* Make the version available */
v = PyUnicode_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
return m;
fail:
Py_XDECREF(m);
return NULL;
}

File diff suppressed because it is too large Load diff

View file

@ -6041,6 +6041,11 @@ PyInit__datetime(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__datetime = {
"_datetime",
PyInit__datetime,
};
/* ---------------------------------------------------------------------------
Some time zone algebra. For a datetime x, let
x.n = x stripped of its timezone -- its naive time.

View file

@ -5992,7 +5992,7 @@ error:
return NULL; /* GCOV_NOT_REACHED */
}
_Section(".rodata.pytab") struct _inittab _PyImport_Inittab__decimal = {
"_decimal",
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__decimal = {
"_decimal",
PyInit__decimal,
};

View file

@ -4091,3 +4091,8 @@ PyInit__elementtree(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__elementtree = {
"_elementtree",
PyInit__elementtree,
};

View file

@ -10,6 +10,7 @@
#include "third_party/python/Include/classobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"

View file

@ -5,8 +5,10 @@
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "third_party/mbedtls/error.h"
#include "third_party/mbedtls/md.h"
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/structmember.h"
#include "third_party/python/Include/yoink.h"
@ -21,15 +23,15 @@ PYTHON_PROVIDE("_hashlib.__name__");
PYTHON_PROVIDE("_hashlib.__package__");
PYTHON_PROVIDE("_hashlib.__spec__");
PYTHON_PROVIDE("_hashlib.new");
PYTHON_PROVIDE("_hashlib.openssl_md5");
PYTHON_PROVIDE("_hashlib.openssl_md_meth_names");
PYTHON_PROVIDE("_hashlib.openssl_sha1");
PYTHON_PROVIDE("_hashlib.openssl_sha224");
PYTHON_PROVIDE("_hashlib.openssl_sha256");
PYTHON_PROVIDE("_hashlib.openssl_sha384");
PYTHON_PROVIDE("_hashlib.openssl_sha512");
PYTHON_PROVIDE("_hashlib.mbedtls_md5");
PYTHON_PROVIDE("_hashlib.mbedtls_md_meth_names");
PYTHON_PROVIDE("_hashlib.mbedtls_sha1");
PYTHON_PROVIDE("_hashlib.mbedtls_sha224");
PYTHON_PROVIDE("_hashlib.mbedtls_sha256");
PYTHON_PROVIDE("_hashlib.mbedtls_sha384");
PYTHON_PROVIDE("_hashlib.mbedtls_sha512");
#include "third_party/python/Modules/clinic/_hashopenssl.inc"
#include "third_party/python/Modules/clinic/_hashmbedtls.inc"
/*[clinic input]
module _hashlib
[clinic start generated code]*/
@ -51,49 +53,26 @@ typedef struct {
} EVPobject;
static PyTypeObject EVPtype;
static PyObject *CONST_md5_name_obj;
static PyObject *CONST_sha1_name_obj;
static PyObject *CONST_sha224_name_obj;
static PyObject *CONST_sha256_name_obj;
static PyObject *CONST_sha384_name_obj;
static PyObject *CONST_sha512_name_obj;
#define DEFINE_CONSTS_FOR_NEW(Name) \
static PyObject *CONST_ ## Name ## _name_obj = NULL; \
static mbedtls_md_context_t *CONST_new_ ## Name ## _ctx_p = NULL;
static mbedtls_md_context_t *CONST_new_ ## Name ## _ctx_p = NULL
DEFINE_CONSTS_FOR_NEW(md5)
DEFINE_CONSTS_FOR_NEW(sha1)
DEFINE_CONSTS_FOR_NEW(sha224)
DEFINE_CONSTS_FOR_NEW(sha256)
DEFINE_CONSTS_FOR_NEW(sha384)
DEFINE_CONSTS_FOR_NEW(sha512)
DEFINE_CONSTS_FOR_NEW(md5);
DEFINE_CONSTS_FOR_NEW(sha1);
DEFINE_CONSTS_FOR_NEW(sha224);
DEFINE_CONSTS_FOR_NEW(sha256);
DEFINE_CONSTS_FOR_NEW(sha384);
DEFINE_CONSTS_FOR_NEW(sha512);
DEFINE_CONSTS_FOR_NEW(blake2b256);
/* LCOV_EXCL_START */
static PyObject *
_setException(PyObject *exc)
_setException(PyObject *exc, int rc)
{
/* unsigned long errcode; */
/* const char *lib, *func, *reason; */
/* errcode = ERR_peek_last_error(); */
/* if (!errcode) { */
/* PyErr_SetString(exc, "unknown reasons"); */
/* return NULL; */
/* } */
/* ERR_clear_error(); */
/* lib = ERR_lib_error_string(errcode); */
/* func = ERR_func_error_string(errcode); */
/* reason = ERR_reason_error_string(errcode); */
/* if (lib && func) { */
/* PyErr_Format(exc, "[%s: %s] %s", lib, func, reason); */
/* } */
/* else if (lib) { */
/* PyErr_Format(exc, "[%s] %s", lib, reason); */
/* } */
/* else { */
/* PyErr_SetString(exc, reason); */
/* } */
PyErr_SetString(exc, "failhouse");
char b[128];
mbedtls_strerror(rc, b, sizeof(b));
PyErr_SetString(exc, b);
return NULL;
}
/* LCOV_EXCL_STOP */
@ -122,6 +101,7 @@ newEVPobject(PyObject *name)
static void
EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
{
int rc;
unsigned int process;
const unsigned char *cp = (const unsigned char *)vp;
while (0 < len) {
@ -129,8 +109,8 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
process = MUNCH_SIZE;
else
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
if (!mbedtls_md_update(self->ctx, (const void*)cp, process)) {
_setException(PyExc_ValueError);
if ((rc = mbedtls_md_update(self->ctx, (const void*)cp, process))) {
_setException(PyExc_ValueError, rc);
break;
}
len -= process;
@ -156,12 +136,11 @@ EVP_dealloc(EVPobject *self)
static int
locked_mbedtls_md_clone(mbedtls_md_context_t *new_ctx_p, EVPobject *self)
{
int result;
int rc;
ENTER_HASHLIB(self);
result = mbedtls_md_clone(new_ctx_p, self->ctx);
result = 0;
rc = mbedtls_md_clone(new_ctx_p, self->ctx);
LEAVE_HASHLIB(self);
return result;
return rc;
}
/* External methods for a hash object */
@ -171,11 +150,12 @@ PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object.");
static PyObject *
EVP_copy(EVPobject *self, PyObject *unused)
{
int rc;
EVPobject *newobj;
if ( (newobj = newEVPobject(self->name))==NULL)
return NULL;
if (!locked_mbedtls_md_clone(newobj->ctx, self)) {
return _setException(PyExc_ValueError);
if ((rc = locked_mbedtls_md_clone(newobj->ctx, self))) {
return _setException(PyExc_ValueError, rc);
}
return (PyObject *)newobj;
}
@ -186,6 +166,7 @@ PyDoc_STRVAR(EVP_digest__doc__,
static PyObject *
EVP_digest(EVPobject *self, PyObject *unused)
{
int rc;
unsigned char digest[MBEDTLS_MD_MAX_SIZE];
mbedtls_md_context_t *temp_ctx;
PyObject *retval;
@ -195,12 +176,12 @@ EVP_digest(EVPobject *self, PyObject *unused)
PyErr_NoMemory();
return NULL;
}
if (!locked_mbedtls_md_clone(temp_ctx, self)) {
return _setException(PyExc_ValueError);
if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) {
return _setException(PyExc_ValueError, rc);
}
digest_size = mbedtls_md_get_size(temp_ctx->md_info);
if (!mbedtls_md_finish(temp_ctx, digest)) {
_setException(PyExc_ValueError);
if ((rc = mbedtls_md_finish(temp_ctx, digest))) {
_setException(PyExc_ValueError, rc);
return NULL;
}
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
@ -214,6 +195,7 @@ PyDoc_STRVAR(EVP_hexdigest__doc__,
static PyObject *
EVP_hexdigest(EVPobject *self, PyObject *unused)
{
int rc;
unsigned char digest[MBEDTLS_MD_MAX_SIZE];
mbedtls_md_context_t *temp_ctx;
unsigned int digest_size;
@ -223,12 +205,12 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
return NULL;
}
/* Get the raw (binary) digest value */
if (!locked_mbedtls_md_clone(temp_ctx, self)) {
return _setException(PyExc_ValueError);
if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) {
return _setException(PyExc_ValueError, rc);
}
digest_size = mbedtls_md_get_size(temp_ctx->md_info);
if (!mbedtls_md_finish(temp_ctx, digest)) {
_setException(PyExc_ValueError);
if ((rc = mbedtls_md_finish(temp_ctx, digest))) {
_setException(PyExc_ValueError, rc);
return NULL;
}
mbedtls_md_free(temp_ctx);
@ -432,6 +414,7 @@ EVPnew(PyObject *name_obj,
const mbedtls_md_context_t *initial_ctx,
const unsigned char *cp, Py_ssize_t len)
{
int rc;
EVPobject *self;
if (!digest && !initial_ctx) {
PyErr_SetString(PyExc_ValueError, "unsupported hash type");
@ -442,8 +425,8 @@ EVPnew(PyObject *name_obj,
if (initial_ctx) {
mbedtls_md_clone(self->ctx, initial_ctx);
} else {
if (!mbedtls_md_setup(self->ctx, digest, 0)) {
_setException(PyExc_ValueError);
if ((rc = mbedtls_md_setup(self->ctx, digest, 0))) {
_setException(PyExc_ValueError, rc);
Py_DECREF(self);
return NULL;
}
@ -497,8 +480,8 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
return ret_obj;
}
#if (OPENSSL_VERSION_NUMBER >= 0x10000000 && !defined(OPENSSL_NO_HMAC) \
&& !defined(OPENSSL_NO_SHA))
#if (MBEDTLS_VERSION_NUMBER >= 0x10000000 && !defined(MBEDTLS_NO_HMAC) \
&& !defined(MBEDTLS_NO_SHA))
#define PY_PBKDF2_HMAC 1
@ -510,7 +493,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
* more. The improved algorithm is not subject to a Denial-of-Service
* vulnerability with overly large passwords.
*
* Also OpenSSL < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only
* Also Mbedtls < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only
* PKCS5_PBKDF2_SHA1.
*/
static int
@ -680,9 +663,9 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
#endif
Py_END_ALLOW_THREADS
if (!retval) {
if (retval) {
Py_CLEAR(key_obj);
_setException(PyExc_ValueError);
_setException(PyExc_ValueError, retval);
goto end;
}
@ -694,7 +677,7 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
#endif
#if OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)
#if MBEDTLS_VERSION_NUMBER > 0x10100000L && !defined(MBEDTLS_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)
#define PY_SCRYPT 1
/* XXX: Parameters salt, n, r and p should be required keyword-only parameters.
They are optional in the Argument Clinic declaration only due to a
@ -764,8 +747,8 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
return NULL;
}
if (maxmem < 0 || maxmem > INT_MAX) {
/* OpenSSL 1.1.0 restricts maxmem to 32MB. It may change in the
future. The maxmem constant is private to OpenSSL. */
/* Mbedtls 1.1.0 restricts maxmem to 32MB. It may change in the
future. The maxmem constant is private to Mbedtls. */
PyErr_Format(PyExc_ValueError,
"maxmem must be positive and smaller than %d",
INT_MAX);
@ -777,7 +760,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
INT_MAX);
return NULL;
}
/* let OpenSSL validate the rest */
/* let Mbedtls validate the rest */
retval = EVP_PBE_scrypt(NULL, 0, NULL, 0, n, r, p, maxmem, NULL, 0);
if (!retval) {
/* sorry, can't do much better */
@ -835,6 +818,7 @@ generate_hash_name_list(void)
static PyObject * \
EVP_new_ ## NAME (PyObject *self, PyObject *args) \
{ \
int rc; \
PyObject *data_obj = NULL; \
Py_buffer view = { 0 }; \
PyObject *ret_obj; \
@ -845,9 +829,10 @@ generate_hash_name_list(void)
\
if (CONST_new_ ## NAME ## _ctx_p == NULL) { \
mbedtls_md_context_t *ctx_p = calloc(1, sizeof(mbedtls_md_context_t)); \
rc = MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE; \
if (!mbedtls_md_info_from_string(#NAME) || \
!mbedtls_md_setup(ctx_p, mbedtls_md_info_from_string(#NAME), 0)) { \
_setException(PyExc_ValueError); \
(rc = mbedtls_md_setup(ctx_p, mbedtls_md_info_from_string(#NAME), 0))) { \
_setException(PyExc_ValueError, rc); \
mbedtls_md_free(ctx_p); \
return NULL; \
} \
@ -871,12 +856,12 @@ generate_hash_name_list(void)
/* a PyMethodDef structure for the constructor */
#define CONSTRUCTOR_METH_DEF(NAME) \
{"openssl_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \
{"mbedtls_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \
PyDoc_STR("Returns a " #NAME \
" hash object; optionally initialized with a string") \
}
/* used in the init function to setup a constructor: initialize OpenSSL
/* used in the init function to setup a constructor: initialize Mbedtls
constructor constants if they haven't been initialized already. */
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) \
if (CONST_ ## NAME ## _name_obj == NULL) { \
@ -889,6 +874,7 @@ GEN_CONSTRUCTOR(sha224)
GEN_CONSTRUCTOR(sha256)
GEN_CONSTRUCTOR(sha384)
GEN_CONSTRUCTOR(sha512)
GEN_CONSTRUCTOR(blake2b256)
/* List of functions exported by this module */
@ -905,6 +891,7 @@ static struct PyMethodDef EVP_functions[] = {
CONSTRUCTOR_METH_DEF(sha256),
CONSTRUCTOR_METH_DEF(sha384),
CONSTRUCTOR_METH_DEF(sha512),
CONSTRUCTOR_METH_DEF(blake2b256),
{NULL, NULL} /* Sentinel */
};
@ -923,8 +910,8 @@ static struct PyModuleDef _hashlibmodule = {
PyMODINIT_FUNC
PyInit__hashlib(void)
{
PyObject *m, *openssl_md_meth_names;
/* TODO build EVP_functions openssl_* entries dynamically based
PyObject *m, *mbedtls_md_meth_names;
/* TODO build EVP_functions mbedtls_* entries dynamically based
* on what hashes are supported rather than listing many
* but having some be unsupported. Only init appropriate
* constants. */
@ -934,12 +921,12 @@ PyInit__hashlib(void)
m = PyModule_Create(&_hashlibmodule);
if (m == NULL)
return NULL;
openssl_md_meth_names = generate_hash_name_list();
if (openssl_md_meth_names == NULL) {
mbedtls_md_meth_names = generate_hash_name_list();
if (mbedtls_md_meth_names == NULL) {
Py_DECREF(m);
return NULL;
}
if (PyModule_AddObject(m, "openssl_md_meth_names", openssl_md_meth_names)) {
if (PyModule_AddObject(m, "mbedtls_md_meth_names", mbedtls_md_meth_names)) {
Py_DECREF(m);
return NULL;
}
@ -952,5 +939,11 @@ PyInit__hashlib(void)
INIT_CONSTRUCTOR_CONSTANTS(sha256)
INIT_CONSTRUCTOR_CONSTANTS(sha384)
INIT_CONSTRUCTOR_CONSTANTS(sha512)
INIT_CONSTRUCTOR_CONSTANTS(blake2b256)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__hashlib = {
"_hashlib",
PyInit__hashlib,
};

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#include "libc/assert.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyerrors.h"
@ -683,4 +684,3 @@ PyInit__heapq(void)
PyModule_AddObject(m, "__about__", about);
return m;
}

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 "third_party/python/Include/abstract.h"
#include "third_party/python/Include/accu.h"
#include "third_party/python/Include/boolobject.h"
@ -1971,3 +1977,8 @@ PyInit__json(void)
Py_DECREF(m);
return NULL;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__json = {
"_json",
PyInit__json,
};

View file

@ -5,9 +5,11 @@
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "libc/unicode/langinfo.h"
#include "libc/unicode/locale.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"

View file

@ -5,6 +5,7 @@
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/frameobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -900,3 +901,8 @@ PyInit__lsprof(void)
initialized = 1;
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__lsprof = {
"_lsprof",
PyInit__lsprof,
};

View file

@ -224,3 +224,8 @@ PyInit__multiprocessing(void)
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__multiprocessing = {
"_multiprocessing",
PyInit__multiprocessing,
};

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/compile.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -92,3 +93,8 @@ PyInit__opcode(void)
{
return PyModule_Create(&opcodemodule);
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__opcode = {
"_opcode",
PyInit__opcode,
};

View file

@ -44,6 +44,8 @@ PYTHON_PROVIDE("_pickle.dumps");
PYTHON_PROVIDE("_pickle.load");
PYTHON_PROVIDE("_pickle.loads");
PYTHON_YOINK("encodings.ascii");
PyDoc_STRVAR(pickle_module_doc,
"Optimized C implementation for the Python pickle module.");
@ -7475,3 +7477,8 @@ PyInit__pickle(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__pickle = {
"_pickle",
PyInit__pickle,
};

View file

@ -724,3 +724,8 @@ PyInit__posixsubprocess(void)
{
return PyModule_Create(&_posixsubprocessmodule);
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__posixsubprocess = {
"_posixsubprocess",
PyInit__posixsubprocess,
};

View file

@ -6,6 +6,7 @@
*/
#include "libc/calls/calls.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -561,3 +562,8 @@ PyInit__random(void)
PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__random = {
"_random",
PyInit__random,
};

View file

@ -7,17 +7,33 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pystrhex.h"
#include "third_party/python/Include/yoink.h"
PYTHON_PROVIDE("_sha3");
PYTHON_PROVIDE("_sha3.__doc__");
PYTHON_PROVIDE("_sha3.__loader__");
PYTHON_PROVIDE("_sha3.__name__");
PYTHON_PROVIDE("_sha3.__package__");
PYTHON_PROVIDE("_sha3.__spec__");
PYTHON_PROVIDE("_sha3.implementation");
PYTHON_PROVIDE("_sha3.keccakopt");
PYTHON_PROVIDE("_sha3.sha3_224");
PYTHON_PROVIDE("_sha3.sha3_256");
PYTHON_PROVIDE("_sha3.sha3_384");
PYTHON_PROVIDE("_sha3.sha3_512");
PYTHON_PROVIDE("_sha3.shake_128");
PYTHON_PROVIDE("_sha3.shake_256");
/*
Ran preprocessor on working build, because spaghetti structure of
upstream Python 3.6 source code was unnaceptably incomprehensible
TODO(jart): Find SHA3 that isn't written in a laugh out loud way!
*/
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
@ -35,15 +51,15 @@ typedef struct {
unsigned char delimitedSuffix;
} Keccak_HashInstance;
static const uint64_t KeccakF1600RoundConstants[24] = {
0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL,
0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL,
0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL,
0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL,
0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL,
0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL,
0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL,
static const uint64_t kKeccakf[24] = {
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
};
static void _PySHA3_KeccakP1600_Initialize(void *state) {
@ -203,6 +219,8 @@ static void _PySHA3_KeccakP1600_OverwriteWithZeroes(void *state,
}
static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
uint64_t Ca, Ce, Ci, Co, Cu;
uint64_t Da, De, Di, Do, Du;
uint64_t Aba, Abe, Abi, Abo, Abu;
uint64_t Aga, Age, Agi, Ago, Agu;
uint64_t Aka, Ake, Aki, Ako, Aku;
@ -213,8 +231,6 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
uint64_t Bka, Bke, Bki, Bko, Bku;
uint64_t Bma, Bme, Bmi, Bmo, Bmu;
uint64_t Bsa, Bse, Bsi, Bso, Bsu;
uint64_t Ca, Ce, Ci, Co, Cu;
uint64_t Da, De, Di, Do, Du;
uint64_t Eba, Ebe, Ebi, Ebo, Ebu;
uint64_t Ega, Ege, Egi, Ego, Egu;
uint64_t Eka, Eke, Eki, Eko, Eku;
@ -267,7 +283,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[0];
Eba ^= kKeccakf[0];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -373,7 +389,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[1];
Aba ^= kKeccakf[1];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -479,7 +495,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[2];
Eba ^= kKeccakf[2];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -585,7 +601,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[3];
Aba ^= kKeccakf[3];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -691,7 +707,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[4];
Eba ^= kKeccakf[4];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -797,7 +813,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[5];
Aba ^= kKeccakf[5];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -903,7 +919,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[6];
Eba ^= kKeccakf[6];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -1009,7 +1025,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[7];
Aba ^= kKeccakf[7];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -1115,7 +1131,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[8];
Eba ^= kKeccakf[8];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -1221,7 +1237,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[9];
Aba ^= kKeccakf[9];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -1327,7 +1343,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[10];
Eba ^= kKeccakf[10];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -1433,7 +1449,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[11];
Aba ^= kKeccakf[11];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -1539,7 +1555,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[12];
Eba ^= kKeccakf[12];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -1645,7 +1661,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[13];
Aba ^= kKeccakf[13];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -1751,7 +1767,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[14];
Eba ^= kKeccakf[14];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -1857,7 +1873,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[15];
Aba ^= kKeccakf[15];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -1963,7 +1979,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[16];
Eba ^= kKeccakf[16];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -2069,7 +2085,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[17];
Aba ^= kKeccakf[17];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -2175,7 +2191,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[18];
Eba ^= kKeccakf[18];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -2281,7 +2297,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[19];
Aba ^= kKeccakf[19];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -2387,7 +2403,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[20];
Eba ^= kKeccakf[20];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -2493,7 +2509,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[21];
Aba ^= kKeccakf[21];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -2599,7 +2615,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[22];
Eba ^= kKeccakf[22];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -2705,7 +2721,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[23];
Aba ^= kKeccakf[23];
Abe = Bbe ^ ((~Bbi) | Bbo);
Abi = Bbi ^ (Bbo & Bbu);
Abo = Bbo ^ (Bbu | Bba);
@ -2862,7 +2878,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[12];
Eba ^= kKeccakf[12];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -2968,7 +2984,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[13];
Aba ^= kKeccakf[13];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -3074,7 +3090,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[14];
Eba ^= kKeccakf[14];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -3180,7 +3196,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[15];
Aba ^= kKeccakf[15];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -3286,7 +3302,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[16];
Eba ^= kKeccakf[16];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -3392,7 +3408,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[17];
Aba ^= kKeccakf[17];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -3498,7 +3514,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[18];
Eba ^= kKeccakf[18];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -3604,7 +3620,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[19];
Aba ^= kKeccakf[19];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -3710,7 +3726,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[20];
Eba ^= kKeccakf[20];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -3816,7 +3832,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[21];
Aba ^= kKeccakf[21];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -3922,7 +3938,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[22];
Eba ^= kKeccakf[22];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -4028,7 +4044,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) {
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[23];
Aba ^= kKeccakf[23];
Abe = Bbe ^ ((~Bbi) | Bbo);
Abi = Bbi ^ (Bbo & Bbu);
Abo = Bbo ^ (Bbu | Bba);
@ -4423,7 +4439,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[0];
Eba ^= kKeccakf[0];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -4529,7 +4545,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[1];
Aba ^= kKeccakf[1];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -4635,7 +4651,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[2];
Eba ^= kKeccakf[2];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -4741,7 +4757,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[3];
Aba ^= kKeccakf[3];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -4847,7 +4863,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[4];
Eba ^= kKeccakf[4];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -4953,7 +4969,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[5];
Aba ^= kKeccakf[5];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -5059,7 +5075,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[6];
Eba ^= kKeccakf[6];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -5165,7 +5181,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[7];
Aba ^= kKeccakf[7];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -5271,7 +5287,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[8];
Eba ^= kKeccakf[8];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -5377,7 +5393,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[9];
Aba ^= kKeccakf[9];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -5483,7 +5499,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[10];
Eba ^= kKeccakf[10];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -5589,7 +5605,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[11];
Aba ^= kKeccakf[11];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -5695,7 +5711,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[12];
Eba ^= kKeccakf[12];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -5801,7 +5817,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[13];
Aba ^= kKeccakf[13];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -5907,7 +5923,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[14];
Eba ^= kKeccakf[14];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -6013,7 +6029,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[15];
Aba ^= kKeccakf[15];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -6119,7 +6135,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[16];
Eba ^= kKeccakf[16];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -6225,7 +6241,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[17];
Aba ^= kKeccakf[17];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -6331,7 +6347,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[18];
Eba ^= kKeccakf[18];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -6437,7 +6453,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[19];
Aba ^= kKeccakf[19];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -6543,7 +6559,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[20];
Eba ^= kKeccakf[20];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -6649,7 +6665,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[21];
Aba ^= kKeccakf[21];
Ca = Aba;
Abe = Bbe ^ ((~Bbi) | Bbo);
Ce = Abe;
@ -6755,7 +6771,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Asu ^= Du;
Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14)));
Eba = Bba ^ (Bbe | Bbi);
Eba ^= KeccakF1600RoundConstants[22];
Eba ^= kKeccakf[22];
Ca = Eba;
Ebe = Bbe ^ ((~Bbi) | Bbo);
Ce = Ebe;
@ -6861,7 +6877,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state,
Esu ^= Du;
Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14)));
Aba = Bba ^ (Bbe | Bbi);
Aba ^= KeccakF1600RoundConstants[23];
Aba ^= kKeccakf[23];
Abe = Bbe ^ ((~Bbi) | Bbo);
Abi = Bbi ^ (Bbo & Bbu);
Abo = Bbo ^ (Bbu | Bba);
@ -7968,3 +7984,8 @@ error:
} while (0);
return 0;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha3 = {
"_sha3",
PyInit__sha3,
};

View file

@ -491,3 +491,8 @@ error:
}
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sqlite3 = {
"_sqlite3",
PyInit__sqlite3,
};

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,7 @@
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/s.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/methodobject.h"
#include "third_party/python/Include/modsupport.h"
@ -626,3 +627,8 @@ PyInit__stat(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__stat = {
"_stat",
PyInit__stat,
};

View file

@ -12,6 +12,7 @@
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -2398,3 +2399,8 @@ PyInit__struct(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__struct = {
"_struct",
PyInit__struct,
};

View file

@ -230,6 +230,9 @@ PYTHON_PROVIDE("_testcapi.unicode_legacy_string");
PYTHON_PROVIDE("_testcapi.unicode_transformdecimaltoascii");
PYTHON_PROVIDE("_testcapi.with_tp_del");
PYTHON_YOINK("encodings.ascii");
PYTHON_YOINK("encodings.latin_1");
/*
* C Extension module to test Python interpreter C APIs.
*
@ -5216,3 +5219,8 @@ PyInit__testcapi(void)
PyModule_AddObject(m, "error", TestError);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__testcapi = {
"_testcapi",
PyInit__testcapi,
};

View file

@ -10,6 +10,7 @@
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/frameobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
@ -1861,3 +1862,8 @@ PyObject*
return traceback_to_pyobject(traceback, NULL);
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__tracemalloc = {
"_tracemalloc",
PyInit__tracemalloc,
};

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"

File diff suppressed because it is too large Load diff

View file

@ -3057,3 +3057,8 @@ PyInit_array(void)
{
return PyModuleDef_Init(&arraymodule);
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_array = {
"array",
PyInit_array,
};

View file

@ -5,6 +5,7 @@
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/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/moduleobject.h"
@ -371,3 +372,8 @@ PyInit_atexit(void)
_Py_PyAtExit(atexit_callfuncs);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_atexit = {
"atexit",
PyInit_atexit,
};

View file

@ -8,6 +8,7 @@
#include "libc/math.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -1963,3 +1964,8 @@ PyInit_audioop(void)
PyDict_SetItemString(d,"error",AudioopError);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_audioop = {
"audioop",
PyInit_audioop,
};

View file

@ -8,6 +8,7 @@
#include "libc/assert.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyctype.h"
@ -1474,3 +1475,8 @@ PyInit_binascii(void)
}
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_binascii = {
"binascii",
PyInit_binascii,
};

View file

@ -4,6 +4,7 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_cn.inc"
@ -477,3 +478,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(cn)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_cn = {
"_codecs_cn",
PyInit__codecs_cn,
};

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#define USING_IMPORTED_MAPS
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_hk.inc"
@ -202,3 +203,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(hk)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_hk = {
"_codecs_hk",
PyInit__codecs_hk,
};

View file

@ -22,6 +22,7 @@
#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/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc"
PYTHON_PROVIDE("_codecs_iso2022");
@ -1153,3 +1154,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(iso2022)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_iso2022 = {
"_codecs_iso2022",
PyInit__codecs_iso2022,
};

View file

@ -19,6 +19,7 @@
#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/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc"
PYTHON_PROVIDE("_codecs_jp");
@ -780,3 +781,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(jp)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_jp = {
"_codecs_jp",
PyInit__codecs_jp,
};

View file

@ -14,6 +14,7 @@
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_kr.inc"
PYTHON_PROVIDE("_codecs_kr");
@ -481,3 +482,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(kr)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_kr = {
"_codecs_kr",
PyInit__codecs_kr,
};

View file

@ -7,6 +7,7 @@
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_tw.inc"
PYTHON_PROVIDE("_codecs_tw");
@ -148,3 +149,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(tw)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_tw = {
"_codecs_tw",
PyInit__codecs_tw,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/codecs.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -1952,3 +1953,8 @@ PyInit__multibytecodec(void)
}
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__multibytecodec = {
"_multibytecodec",
PyInit__multibytecodec,
};

View file

@ -73,13 +73,13 @@ PyDoc_STRVAR(_winapi_CloseHandle__doc__,
{"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__},
static PyObject *
_winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
_winapi_CloseHandle_impl(PyObject *module, int64_t handle);
static PyObject *
_winapi_CloseHandle(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
HANDLE handle;
int64_t handle;
if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
goto exit;
@ -99,7 +99,7 @@ PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__,
{"ConnectNamedPipe", (PyCFunction)_winapi_ConnectNamedPipe, METH_FASTCALL, _winapi_ConnectNamedPipe__doc__},
static PyObject *
_winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
_winapi_ConnectNamedPipe_impl(PyObject *module, int64_t handle,
int use_overlapped);
static PyObject *
@ -108,7 +108,7 @@ _winapi_ConnectNamedPipe(PyObject *module, PyObject **args, Py_ssize_t nargs, Py
PyObject *return_value = NULL;
static const char * const _keywords[] = {"handle", "overlapped", NULL};
static _PyArg_Parser _parser = {"" F_HANDLE "|i:ConnectNamedPipe", _keywords, 0};
HANDLE handle;
int64_t handle;
int use_overlapped = 0;
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
@ -131,35 +131,35 @@ PyDoc_STRVAR(_winapi_CreateFile__doc__,
#define _WINAPI_CREATEFILE_METHODDEF \
{"CreateFile", (PyCFunction)_winapi_CreateFile, METH_VARARGS, _winapi_CreateFile__doc__},
static HANDLE
_winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
DWORD desired_access, DWORD share_mode,
LPSECURITY_ATTRIBUTES security_attributes,
DWORD creation_disposition,
DWORD flags_and_attributes, HANDLE template_file);
static int64_t
_winapi_CreateFile_impl(PyObject *module, const char16_t *file_name,
uint32_t desired_access, uint32_t share_mode,
struct NtSecurityAttributes *security_attributes,
uint32_t creation_disposition,
uint32_t flags_and_attributes, int64_t template_file);
static PyObject *
_winapi_CreateFile(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
LPCTSTR file_name;
DWORD desired_access;
DWORD share_mode;
LPSECURITY_ATTRIBUTES security_attributes;
DWORD creation_disposition;
DWORD flags_and_attributes;
HANDLE template_file;
HANDLE _return_value;
const char16_t *file_name;
uint32_t desired_access;
uint32_t share_mode;
struct NtSecurityAttributes *security_attributes;
uint32_t creation_disposition;
uint32_t flags_and_attributes;
int64_t template_file;
int64_t _return_value;
if (!PyArg_ParseTuple(args, "skk" F_POINTER "kk" F_HANDLE ":CreateFile",
&file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) {
goto exit;
}
_return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -177,15 +177,15 @@ PyDoc_STRVAR(_winapi_CreateJunction__doc__,
{"CreateJunction", (PyCFunction)_winapi_CreateJunction, METH_VARARGS, _winapi_CreateJunction__doc__},
static PyObject *
_winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path,
LPWSTR dst_path);
_winapi_CreateJunction_impl(PyObject *module, char16_t *src_path,
char16_t *dst_path);
static PyObject *
_winapi_CreateJunction(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
LPWSTR src_path;
LPWSTR dst_path;
char16_t *src_path;
char16_t *dst_path;
if (!PyArg_ParseTuple(args, "uu:CreateJunction",
&src_path, &dst_path)) {
@ -207,36 +207,36 @@ PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
#define _WINAPI_CREATENAMEDPIPE_METHODDEF \
{"CreateNamedPipe", (PyCFunction)_winapi_CreateNamedPipe, METH_VARARGS, _winapi_CreateNamedPipe__doc__},
static HANDLE
_winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode,
DWORD pipe_mode, DWORD max_instances,
DWORD out_buffer_size, DWORD in_buffer_size,
DWORD default_timeout,
LPSECURITY_ATTRIBUTES security_attributes);
static int64_t
_winapi_CreateNamedPipe_impl(PyObject *module, const char16_t *name, uint32_t open_mode,
uint32_t pipe_mode, uint32_t max_instances,
uint32_t out_buffer_size, uint32_t in_buffer_size,
uint32_t default_timeout,
struct NtSecurityAttributes *security_attributes);
static PyObject *
_winapi_CreateNamedPipe(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
LPCTSTR name;
DWORD open_mode;
DWORD pipe_mode;
DWORD max_instances;
DWORD out_buffer_size;
DWORD in_buffer_size;
DWORD default_timeout;
LPSECURITY_ATTRIBUTES security_attributes;
HANDLE _return_value;
const char16_t *name;
uint32_t open_mode;
uint32_t pipe_mode;
uint32_t max_instances;
uint32_t out_buffer_size;
uint32_t in_buffer_size;
uint32_t default_timeout;
struct NtSecurityAttributes *security_attributes;
int64_t _return_value;
if (!PyArg_ParseTuple(args, "skkkkkk" F_POINTER ":CreateNamedPipe",
&name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
goto exit;
}
_return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -260,14 +260,14 @@ PyDoc_STRVAR(_winapi_CreatePipe__doc__,
{"CreatePipe", (PyCFunction)_winapi_CreatePipe, METH_VARARGS, _winapi_CreatePipe__doc__},
static PyObject *
_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, uint32_t size);
static PyObject *
_winapi_CreatePipe(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *pipe_attrs;
DWORD size;
uint32_t size;
if (!PyArg_ParseTuple(args, "Ok:CreatePipe",
&pipe_attrs, &size)) {
@ -301,8 +301,8 @@ PyDoc_STRVAR(_winapi_CreateProcess__doc__,
static PyObject *
_winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name,
Py_UNICODE *command_line, PyObject *proc_attrs,
PyObject *thread_attrs, BOOL inherit_handles,
DWORD creation_flags, PyObject *env_mapping,
PyObject *thread_attrs, bool32 inherit_handles,
uint32_t creation_flags, PyObject *env_mapping,
Py_UNICODE *current_directory,
PyObject *startup_info);
@ -314,8 +314,8 @@ _winapi_CreateProcess(PyObject *module, PyObject *args)
Py_UNICODE *command_line;
PyObject *proc_attrs;
PyObject *thread_attrs;
BOOL inherit_handles;
DWORD creation_flags;
bool32 inherit_handles;
uint32_t creation_flags;
PyObject *env_mapping;
Py_UNICODE *current_directory;
PyObject *startup_info;
@ -345,34 +345,34 @@ PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
#define _WINAPI_DUPLICATEHANDLE_METHODDEF \
{"DuplicateHandle", (PyCFunction)_winapi_DuplicateHandle, METH_VARARGS, _winapi_DuplicateHandle__doc__},
static HANDLE
_winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
HANDLE source_handle,
HANDLE target_process_handle,
DWORD desired_access, BOOL inherit_handle,
DWORD options);
static int64_t
_winapi_DuplicateHandle_impl(PyObject *module, int64_t source_process_handle,
int64_t source_handle,
int64_t target_process_handle,
uint32_t desired_access, bool32 inherit_handle,
uint32_t options);
static PyObject *
_winapi_DuplicateHandle(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
HANDLE source_process_handle;
HANDLE source_handle;
HANDLE target_process_handle;
DWORD desired_access;
BOOL inherit_handle;
DWORD options = 0;
HANDLE _return_value;
int64_t source_process_handle;
int64_t source_handle;
int64_t target_process_handle;
uint32_t desired_access;
bool32 inherit_handle;
uint32_t options = 0;
int64_t _return_value;
if (!PyArg_ParseTuple(args, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
&source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
goto exit;
}
_return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -390,13 +390,13 @@ PyDoc_STRVAR(_winapi_ExitProcess__doc__,
{"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
static PyObject *
_winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
_winapi_ExitProcess_impl(PyObject *module, unsigned ExitCode);
static PyObject *
_winapi_ExitProcess(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
UINT ExitCode;
unsigned ExitCode;
if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
goto exit;
@ -416,20 +416,20 @@ PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
#define _WINAPI_GETCURRENTPROCESS_METHODDEF \
{"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
static HANDLE
static int64_t
_winapi_GetCurrentProcess_impl(PyObject *module);
static PyObject *
_winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
HANDLE _return_value;
int64_t _return_value;
_return_value = _winapi_GetCurrentProcess_impl(module);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -447,21 +447,21 @@ PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
#define _WINAPI_GETEXITCODEPROCESS_METHODDEF \
{"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
static DWORD
_winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
static uint32_t
_winapi_GetExitCodeProcess_impl(PyObject *module, int64_t process);
static PyObject *
_winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
HANDLE process;
DWORD _return_value;
int64_t process;
uint32_t _return_value;
if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
goto exit;
}
_return_value = _winapi_GetExitCodeProcess_impl(module, process);
if ((_return_value == DWORD_MAX) && PyErr_Occurred()) {
if ((_return_value == UINT_MAX) && PyErr_Occurred()) {
goto exit;
}
return_value = Py_BuildValue("k", _return_value);
@ -478,17 +478,17 @@ PyDoc_STRVAR(_winapi_GetLastError__doc__,
#define _WINAPI_GETLASTERROR_METHODDEF \
{"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
static DWORD
static uint32_t
_winapi_GetLastError_impl(PyObject *module);
static PyObject *
_winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
DWORD _return_value;
uint32_t _return_value;
_return_value = _winapi_GetLastError_impl(module);
if ((_return_value == DWORD_MAX) && PyErr_Occurred()) {
if ((_return_value == UINT_MAX) && PyErr_Occurred()) {
goto exit;
}
return_value = Py_BuildValue("k", _return_value);
@ -514,19 +514,17 @@ PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
{"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
static PyObject *
_winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
_winapi_GetModuleFileName_impl(PyObject *module, int64_t module_handle);
static PyObject *
_winapi_GetModuleFileName(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
HMODULE module_handle;
int64_t module_handle;
if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
goto exit;
}
return_value = _winapi_GetModuleFileName_impl(module, module_handle);
exit:
return return_value;
}
@ -538,31 +536,31 @@ PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
"Return a handle to the specified standard device.\n"
"\n"
" std_handle\n"
" One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
" One of STD_INPUT_int64_t, STD_OUTPUT_int64_t, or STD_ERROR_int64_t.\n"
"\n"
"The integer associated with the handle object is returned.");
#define _WINAPI_GETSTDHANDLE_METHODDEF \
{"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
static HANDLE
_winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
static int64_t
_winapi_GetStdHandle_impl(PyObject *module, uint32_t std_handle);
static PyObject *
_winapi_GetStdHandle(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
DWORD std_handle;
HANDLE _return_value;
uint32_t std_handle;
int64_t _return_value;
if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
goto exit;
}
_return_value = _winapi_GetStdHandle_impl(module, std_handle);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -607,28 +605,28 @@ PyDoc_STRVAR(_winapi_OpenProcess__doc__,
#define _WINAPI_OPENPROCESS_METHODDEF \
{"OpenProcess", (PyCFunction)_winapi_OpenProcess, METH_VARARGS, _winapi_OpenProcess__doc__},
static HANDLE
_winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
BOOL inherit_handle, DWORD process_id);
static int64_t
_winapi_OpenProcess_impl(PyObject *module, uint32_t desired_access,
bool32 inherit_handle, uint32_t process_id);
static PyObject *
_winapi_OpenProcess(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
DWORD desired_access;
BOOL inherit_handle;
DWORD process_id;
HANDLE _return_value;
uint32_t desired_access;
bool32 inherit_handle;
uint32_t process_id;
int64_t _return_value;
if (!PyArg_ParseTuple(args, "kik:OpenProcess",
&desired_access, &inherit_handle, &process_id)) {
goto exit;
}
_return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) {
goto exit;
}
if (_return_value == NULL) {
if (!_return_value) {
Py_RETURN_NONE;
}
return_value = HANDLE_TO_PYNUM(_return_value);
@ -646,13 +644,13 @@ PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
{"PeekNamedPipe", (PyCFunction)_winapi_PeekNamedPipe, METH_VARARGS, _winapi_PeekNamedPipe__doc__},
static PyObject *
_winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
_winapi_PeekNamedPipe_impl(PyObject *module, int64_t handle, int size);
static PyObject *
_winapi_PeekNamedPipe(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
HANDLE handle;
int64_t handle;
int size = 0;
if (!PyArg_ParseTuple(args, "" F_HANDLE "|i:PeekNamedPipe",
@ -674,7 +672,7 @@ PyDoc_STRVAR(_winapi_ReadFile__doc__,
{"ReadFile", (PyCFunction)_winapi_ReadFile, METH_FASTCALL, _winapi_ReadFile__doc__},
static PyObject *
_winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
_winapi_ReadFile_impl(PyObject *module, int64_t handle, uint32_t size,
int use_overlapped);
static PyObject *
@ -683,8 +681,8 @@ _winapi_ReadFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *
PyObject *return_value = NULL;
static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
static _PyArg_Parser _parser = {"" F_HANDLE "k|i:ReadFile", _keywords, 0};
HANDLE handle;
DWORD size;
int64_t handle;
uint32_t size;
int use_overlapped = 0;
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
@ -707,7 +705,7 @@ PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
{"SetNamedPipeHandleState", (PyCFunction)_winapi_SetNamedPipeHandleState, METH_VARARGS, _winapi_SetNamedPipeHandleState__doc__},
static PyObject *
_winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
_winapi_SetNamedPipeHandleState_impl(PyObject *module, int64_t named_pipe,
PyObject *mode,
PyObject *max_collection_count,
PyObject *collect_data_timeout);
@ -716,7 +714,7 @@ static PyObject *
_winapi_SetNamedPipeHandleState(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
HANDLE named_pipe;
int64_t named_pipe;
PyObject *mode;
PyObject *max_collection_count;
PyObject *collect_data_timeout;
@ -741,15 +739,15 @@ PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
{"TerminateProcess", (PyCFunction)_winapi_TerminateProcess, METH_VARARGS, _winapi_TerminateProcess__doc__},
static PyObject *
_winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
UINT exit_code);
_winapi_TerminateProcess_impl(PyObject *module, int64_t handle,
unsigned exit_code);
static PyObject *
_winapi_TerminateProcess(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
HANDLE handle;
UINT exit_code;
int64_t handle;
unsigned exit_code;
if (!PyArg_ParseTuple(args, "" F_HANDLE "I:TerminateProcess",
&handle, &exit_code)) {
@ -770,14 +768,14 @@ PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
{"WaitNamedPipe", (PyCFunction)_winapi_WaitNamedPipe, METH_VARARGS, _winapi_WaitNamedPipe__doc__},
static PyObject *
_winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout);
_winapi_WaitNamedPipe_impl(PyObject *module, const char *name, uint32_t timeout);
static PyObject *
_winapi_WaitNamedPipe(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
LPCTSTR name;
DWORD timeout;
const char *name;
uint32_t timeout;
if (!PyArg_ParseTuple(args, "sk:WaitNamedPipe",
&name, &timeout)) {
@ -800,15 +798,15 @@ PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
static PyObject *
_winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
BOOL wait_flag, DWORD milliseconds);
bool32 wait_flag, uint32_t milliseconds);
static PyObject *
_winapi_WaitForMultipleObjects(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *handle_seq;
BOOL wait_flag;
DWORD milliseconds = INFINITE;
bool32 wait_flag;
uint32_t milliseconds = -1;
if (!PyArg_ParseTuple(args, "Oi|k:WaitForMultipleObjects",
&handle_seq, &wait_flag, &milliseconds)) {
@ -834,15 +832,15 @@ PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
{"WaitForSingleObject", (PyCFunction)_winapi_WaitForSingleObject, METH_VARARGS, _winapi_WaitForSingleObject__doc__},
static long
_winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
DWORD milliseconds);
_winapi_WaitForSingleObject_impl(PyObject *module, int64_t handle,
uint32_t milliseconds);
static PyObject *
_winapi_WaitForSingleObject(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
HANDLE handle;
DWORD milliseconds;
int64_t handle;
uint32_t milliseconds;
long _return_value;
if (!PyArg_ParseTuple(args, "" F_HANDLE "k:WaitForSingleObject",
@ -868,7 +866,7 @@ PyDoc_STRVAR(_winapi_WriteFile__doc__,
{"WriteFile", (PyCFunction)_winapi_WriteFile, METH_FASTCALL, _winapi_WriteFile__doc__},
static PyObject *
_winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
_winapi_WriteFile_impl(PyObject *module, int64_t handle, PyObject *buffer,
int use_overlapped);
static PyObject *
@ -877,7 +875,7 @@ _winapi_WriteFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject
PyObject *return_value = NULL;
static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
static _PyArg_Parser _parser = {"" F_HANDLE "O|i:WriteFile", _keywords, 0};
HANDLE handle;
int64_t handle;
PyObject *buffer;
int use_overlapped = 0;

View file

@ -11,6 +11,7 @@
#include "third_party/python/Include/complexobject.h"
#include "third_party/python/Include/dtoa.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
@ -1456,3 +1457,8 @@ PyInit_cmath(void)
})
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_cmath = {
"cmath",
PyInit_cmath,
};

View file

@ -4,216 +4,111 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/cosmo.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/pyport.h"
/* clang-format off */
/* Generated automatically from ./Modules/config.c.in by makesetup. */
/* -*- C -*- ***********************************************
Copyright (c) 2000, BeOpen.com.
Copyright (c) 1995-2000, Corporation for National Research Initiatives.
Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
All rights reserved.
See the file "Misc/COPYRIGHT" for information on usage and
redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
******************************************************************/
/* Module configuration */
/* !!! !!! !!! This file is edited by the makesetup script !!! !!! !!! */
/* This file contains the table of built-in modules.
See create_builtin() in import.c. */
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/pyport.h"
#include "third_party/python/Include/Python.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/cosmo.h"
PyObject* PyInit__decimal(void);
PyObject* PyInit_audioop(void);
PyObject* PyInit_posix(void);
PyObject* PyInit_errno(void);
PyObject* PyInit_pwd(void);
PyObject* PyInit__sre(void);
PyObject* PyInit__codecs(void);
PyObject* PyInit__functools(void);
PyObject* PyInit__operator(void);
PyObject* PyInit__collections(void);
PyObject* PyInit_itertools(void);
PyObject* PyInit_atexit(void);
PyObject* PyInit__signal(void);
PyObject* PyInit__stat(void);
PyObject* PyInit_time(void);
PyObject* PyInit__locale(void);
PyObject* PyInit__io(void);
PyObject* PyInit_zipimport(void);
PyObject* PyInit_faulthandler(void);
PyObject* PyInit__hashlib(void);
#ifdef MODE_DBG
PyObject* PyInit__tracemalloc(void);
#endif
PyObject* PyInit__symtable(void);
PyObject* PyInit_array(void);
PyObject* PyInit_cmath(void);
PyObject* PyInit_math(void);
PyObject* PyInit__struct(void);
PyObject* PyInit__weakref(void);
PyObject* PyInit__testcapi(void);
PyObject* PyInit__random(void);
PyObject* PyInit__elementtree(void);
PyObject* PyInit__pickle(void);
PyObject* PyInit__datetime(void);
PyObject* PyInit__bisect(void);
PyObject* PyInit__heapq(void);
PyObject* PyInit_unicodedata(void);
PyObject* PyInit_fcntl(void);
PyObject* PyInit__bz2(void);
PyObject* PyInit_grp(void);
PyObject* PyInit_select(void);
PyObject* PyInit_mmap(void);
PyObject* PyInit__csv(void);
PyObject* PyInit__socket(void);
PyObject* PyInit_resource(void);
PyObject* PyInit__posixsubprocess(void);
PyObject* PyInit__multiprocessing(void);
PyObject* PyInit__md5(void);
PyObject* PyInit__sha1(void);
PyObject* PyInit__sha256(void);
PyObject* PyInit__sha512(void);
PyObject* PyInit__sha3(void);
PyObject* PyInit_syslog(void);
PyObject* PyInit_binascii(void);
PyObject* PyInit_parser(void);
PyObject* PyInit_fpectl(void);
PyObject* PyInit_zlib(void);
PyObject* PyInit_pyexpat(void);
PyObject* PyInit__multibytecodec(void);
PyObject* PyInit__codecs_cn(void);
PyObject* PyInit__codecs_hk(void);
PyObject* PyInit__codecs_iso2022(void);
PyObject* PyInit__codecs_jp(void);
PyObject* PyInit__codecs_kr(void);
PyObject* PyInit__codecs_tw(void);
PyObject* PyInit__json(void);
PyObject* PyInit__lsprof(void);
PyObject* PyInit__opcode(void);
PyObject* PyInit_termios(void);
PyObject *PyInit__ast(void);
PyObject *PyInit__bisect(void);
PyObject *PyInit__bz2(void);
PyObject *PyInit__codecs(void);
PyObject *PyInit__codecs_cn(void);
PyObject *PyInit__codecs_hk(void);
PyObject *PyInit__codecs_iso2022(void);
PyObject *PyInit__codecs_jp(void);
PyObject *PyInit__codecs_kr(void);
PyObject *PyInit__codecs_tw(void);
PyObject *PyInit__collections(void);
PyObject *PyInit__csv(void);
PyObject *PyInit__datetime(void);
PyObject *PyInit__decimal(void);
PyObject *PyInit__elementtree(void);
PyObject *PyInit__functools(void);
PyObject *PyInit__hashlib(void);
PyObject *PyInit__heapq(void);
PyObject *PyInit__io(void);
PyObject *PyInit__json(void);
PyObject *PyInit__locale(void);
PyObject *PyInit__lsprof(void);
PyObject *PyInit__md5(void);
PyObject *PyInit__multibytecodec(void);
PyObject *PyInit__multiprocessing(void);
PyObject *PyInit__opcode(void);
PyObject *PyInit__operator(void);
PyObject *PyInit__pickle(void);
PyObject *PyInit__posixsubprocess(void);
PyObject *PyInit__random(void);
PyObject *PyInit__sha1(void);
PyObject *PyInit__sha256(void);
PyObject *PyInit__sha3(void);
PyObject *PyInit__sha512(void);
PyObject *PyInit__signal(void);
PyObject *PyInit__socket(void);
PyObject *PyInit__sqlite3(void);
PyObject *PyInit__sre(void);
PyObject *PyInit__stat(void);
PyObject *PyInit__string(void);
PyObject *PyInit__struct(void);
PyObject *PyInit__symtable(void);
PyObject *PyInit__testcapi(void);
PyObject *PyInit__tracemalloc(void);
PyObject *PyInit__weakref(void);
PyObject *PyInit_array(void);
PyObject *PyInit_atexit(void);
PyObject *PyInit_audioop(void);
PyObject *PyInit_binascii(void);
PyObject *PyInit_cmath(void);
PyObject *PyInit_cosmo(void);
PyObject *PyInit_errno(void);
PyObject *PyInit_faulthandler(void);
PyObject *PyInit_fcntl(void);
PyObject *PyInit_fpectl(void);
PyObject *PyInit_gc(void);
PyObject *PyInit_grp(void);
PyObject *PyInit_imp(void);
PyObject *PyInit_itertools(void);
PyObject *PyInit_math(void);
PyObject *PyInit_mmap(void);
PyObject *PyInit_parser(void);
PyObject *PyInit_posix(void);
PyObject *PyInit_pwd(void);
PyObject *PyInit_pyexpat(void);
PyObject *PyInit_resource(void);
PyObject *PyInit_select(void);
PyObject *PyInit_syslog(void);
PyObject *PyInit_termios(void);
PyObject *PyInit_time(void);
PyObject *PyInit_unicodedata(void);
PyObject *PyInit_zipimport(void);
PyObject *PyInit_zlib(void);
PyObject *PyMarshal_Init(void);
PyObject *_PyWarnings_Init(void);
/* -- ADDMODULE MARKER 1 -- */
PyObject* PyMarshal_Init(void);
PyObject* PyInit_imp(void);
PyObject* PyInit_cosmo(void);
PyObject* PyInit_gc(void);
PyObject* PyInit__ast(void);
PyObject* _PyWarnings_Init(void);
PyObject* PyInit__string(void);
struct _inittab _PyImport_Inittab[] = {
{"_decimal", PyInit__decimal},
_Alignas(16) _Section(".rodata.pytab.0") const struct _inittab _PyImport_Inittab[0];
_Alignas(16) _Section(".rodata.pytab.2") const struct _inittab _PyImport_Inittab2[] = {
{"posix", PyInit_posix},
{"errno", PyInit_errno},
{"pwd", PyInit_pwd},
{"_sre", PyInit__sre},
{"_codecs", PyInit__codecs},
{"_functools", PyInit__functools},
{"_operator", PyInit__operator},
{"_collections", PyInit__collections},
{"itertools", PyInit_itertools},
{"atexit", PyInit_atexit},
{"_signal", PyInit__signal},
{"_stat", PyInit__stat},
{"time", PyInit_time},
{"_locale", PyInit__locale},
{"_io", PyInit__io},
{"faulthandler", PyInit_faulthandler},
#ifdef USE_TRACEMALLOC
{"_tracemalloc", PyInit__tracemalloc},
#endif
{"_symtable", PyInit__symtable},
{"_hashlib", PyInit__hashlib},
{"_bz2module", PyInit__bz2},
{"array", PyInit_array},
{"cmath", PyInit_cmath},
{"math", PyInit_math},
{"_struct", PyInit__struct},
{"_weakref", PyInit__weakref},
{"_testcapi", PyInit__testcapi},
{"_random", PyInit__random},
{"_pickle", PyInit__pickle},
{"_datetime", PyInit__datetime},
{"_bisect", PyInit__bisect},
{"_heapq", PyInit__heapq},
{"unicodedata", PyInit_unicodedata},
{"fcntl", PyInit_fcntl},
{"grp", PyInit_grp},
{"select", PyInit_select},
{"mmap", PyInit_mmap},
{"_csv", PyInit__csv},
{"_socket", PyInit__socket},
{"resource", PyInit_resource},
{"_posixsubprocess", PyInit__posixsubprocess},
{"_multiprocessing", PyInit__multiprocessing},
{"_md5", PyInit__md5},
{"_sha1", PyInit__sha1},
{"_sha256", PyInit__sha256},
{"_sha512", PyInit__sha512},
{"_sha3", PyInit__sha3},
{"syslog", PyInit_syslog},
{"binascii", PyInit_binascii},
{"parser", PyInit_parser},
{"fpectl", PyInit_fpectl},
{"pyexpat", PyInit_pyexpat},
{"_multibytecodec", PyInit__multibytecodec},
{"_json", PyInit__json},
{"_opcode", PyInit__opcode},
{"termios", PyInit_termios},
#if !IsTiny()
{"zlib", PyInit_zlib},
{"sqlite3", PyInit__sqlite3},
{"zipimport", PyInit_zipimport},
{"_elementtree", PyInit__elementtree},
{"_codecs_cn", PyInit__codecs_cn},
{"_codecs_hk", PyInit__codecs_hk},
{"_codecs_iso2022", PyInit__codecs_iso2022},
{"_codecs_jp", PyInit__codecs_jp},
{"_codecs_kr", PyInit__codecs_kr},
{"_codecs_tw", PyInit__codecs_tw},
{"audioop", PyInit_audioop},
{"_lsprof", PyInit__lsprof},
#endif
/* -- ADDMODULE MARKER 2 -- */
/* This module lives in marshal.c */
{"marshal", PyMarshal_Init},
/* This lives in import.c */
{"_imp", PyInit_imp},
/* This lives in cosmomodule.c */
{"_cosmo", PyInit_cosmo},
/* This lives in Python/Python-ast.c */
{"_ast", PyInit__ast},
/* These entries are here for sys.builtin_module_names */
{"builtins", NULL},
{"sys", NULL},
/* This lives in gcmodule.c */
{"gc", PyInit_gc},
/* This lives in _warnings.c */
{"_warnings", _PyWarnings_Init},
/* This lives in Objects/unicodeobject.c */
{"_warnings", _PyWarnings_Init},
{"_string", PyInit__string},
/* Sentinel */
{0, 0}
};

View file

@ -8,6 +8,7 @@
#include "libc/errno.h"
#include "libc/nt/errors.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/methodobject.h"
#include "third_party/python/Include/modsupport.h"

View file

@ -1436,3 +1436,8 @@ void _PyFaulthandler_Fini(void)
}
#endif
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_faulthandler = {
"faulthandler",
PyInit_faulthandler,
};

View file

@ -16,6 +16,7 @@
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/fileobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -697,3 +698,8 @@ PyInit_fcntl(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_fcntl = {
"fcntl",
PyInit_fcntl,
};

View file

@ -6,6 +6,7 @@
*/
#include "libc/runtime/runtime.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/methodobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/moduleobject.h"
@ -275,3 +276,8 @@ PyMODINIT_FUNC PyInit_fpectl(void)
PyDict_SetItemString(d, "error", fpe_error);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_fpectl = {
"fpectl",
PyInit_fpectl,
};

View file

@ -8,6 +8,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/mem/alloca.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
@ -125,12 +126,12 @@ wchar_t *Py_GetProgramName(void);
#define LANDMARK L"os.py"
#endif
static const wchar_t limited_search_path[] = L"/zip/.python";
#define LIMITED_SEARCH_PATH L"/zip/.python"
static wchar_t *progpath;
static wchar_t *prefix = limited_search_path;
static wchar_t *exec_prefix = limited_search_path;
static wchar_t *module_search_path = limited_search_path;
static wchar_t *prefix = LIMITED_SEARCH_PATH;
static wchar_t *exec_prefix = LIMITED_SEARCH_PATH;
static wchar_t *module_search_path = LIMITED_SEARCH_PATH;
/* Get file status. Encode the path to the locale encoding. */
@ -667,3 +668,11 @@ Py_GetProgramFullPath(void)
}
return progpath;
}
void
Py_LimitedPath(void)
{
prefix = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH);
exec_prefix = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH);
module_search_path = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH);
}

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -276,3 +277,8 @@ PyInit_grp(void)
initialized = 1;
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_grp = {
"grp",
PyInit_grp,
};

View file

@ -9,6 +9,11 @@
#include "third_party/python/Modules/hashtable.h"
/* clang-format off */
asm(".ident\t\"\\n\\n\
cfuhash (bsd-3)\\n\
Copyright (c) 2005 Don Owens\"");
asm(".include \"libc/disclaimer.inc\"");
/* The implementation of the hash table (_Py_hashtable_t) is based on the
cfuhash project:
http://sourceforge.net/projects/libcfu/

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"

View file

@ -11,6 +11,7 @@
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/dtoa.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyerrors.h"
@ -2227,3 +2228,8 @@ PyInit_math(void)
finally:
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_math = {
"math",
PyInit_math,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -596,3 +597,8 @@ PyInit__md5(void)
PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__md5 = {
"_md5",
PyInit__md5,
};

View file

@ -18,6 +18,7 @@
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -1491,3 +1492,8 @@ PyInit_mmap(void)
setint(dict, "ACCESS_COPY", ACCESS_COPY);
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_mmap = {
"mmap",
PyInit_mmap,
};

View file

@ -1253,3 +1253,8 @@ PyInit_parser(void)
}
return module;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_parser = {
"parser",
PyInit_parser,
};

View file

@ -7,6 +7,7 @@
#define PY_SSIZE_T_CLEAN
#include "libc/alg/alg.h"
#include "libc/assert.h"
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/makedev.h"
@ -16,6 +17,7 @@
#include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/sw.h"
#include "libc/runtime/dlfcn.h"
@ -36,6 +38,7 @@
#include "libc/sysv/consts/st.h"
#include "libc/sysv/consts/w.h"
#include "libc/sysv/consts/waitid.h"
#include "libc/sysv/errfuns.h"
#include "libc/time/time.h"
#include "third_party/musl/passwd.h"
#include "third_party/python/Include/abstract.h"
@ -1816,6 +1819,7 @@ posix_do_stat(const char *function_name, path_t *path,
#endif /* HAVE_FSTATAT */
result = STAT(path->narrow, &st);
#endif /* MS_WINDOWS */
Py_END_ALLOW_THREADS
if (result != 0) {

View file

@ -6,6 +6,7 @@
*/
#include "third_party/musl/passwd.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -264,3 +265,8 @@ PyInit_pwd(void)
PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_pwd = {
"pwd",
PyInit_pwd,
};

View file

@ -11,6 +11,7 @@
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/frameobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -46,6 +47,9 @@ PYTHON_PROVIDE("pyexpat.model");
PYTHON_PROVIDE("pyexpat.native_encoding");
PYTHON_PROVIDE("pyexpat.version_info");
PYTHON_YOINK("encodings.ascii");
PYTHON_YOINK("encodings.utf_8");
/* Do not emit Clinic output to a file as that wreaks havoc with conditionally
included methods. */
/*[clinic input]
@ -2036,3 +2040,8 @@ static struct HandlerInfo handler_info[] = {
dump buffer
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_pyexpat = {
"pyexpat",
PyInit_pyexpat,
};

View file

@ -14,6 +14,7 @@
#include "libc/sysv/consts/rusage.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyerrors.h"
@ -416,3 +417,8 @@ PyInit_resource(void)
initialized = 1;
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_resource = {
"resource",
PyInit_resource,
};

View file

@ -21,6 +21,7 @@
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/fileobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -2604,3 +2605,8 @@ PyInit_select(void)
#endif /* HAVE_KQUEUE */
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_select = {
"select",
PyInit_select,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -579,3 +580,8 @@ PyInit__sha1(void)
PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha1 = {
"_sha1",
PyInit__sha1,
};

View file

@ -7,6 +7,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -744,3 +745,8 @@ PyInit__sha256(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha256 = {
"_sha256",
PyInit__sha256,
};

View file

@ -7,6 +7,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
@ -818,3 +819,8 @@ PyInit__sha512(void)
PyModule_AddObject(m, "SHA512Type", (PyObject *)&SHA512type);
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha512 = {
"_sha512",
PyInit__sha512,
};

View file

@ -40,6 +40,7 @@
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/fileutils.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -7196,3 +7197,8 @@ PyInit__socket(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__socket = {
"_socket",
PyInit__socket,
};

View file

@ -6,6 +6,7 @@
*/
#include "third_party/python/Include/Python-ast.h"
#include "third_party/python/Include/code.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
@ -133,3 +134,8 @@ PyInit__symtable(void)
}
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__symtable = {
"_symtable",
PyInit__symtable,
};

View file

@ -7,6 +7,7 @@
#include "libc/sock/syslog.h"
#include "libc/sysv/consts/log.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
@ -59,6 +60,12 @@ PYTHON_PROVIDE("syslog.openlog");
PYTHON_PROVIDE("syslog.setlogmask");
PYTHON_PROVIDE("syslog.syslog");
asm(".ident\t\"\\n\\n\
syslogmodule (mit)\\n\
Copyright 1994 by Lance Ellinghouse\\n\
Cathedral City, California Republic, United States of America\"");
asm(".include \"libc/disclaimer.inc\"");
/***********************************************************
Copyright 1994 by Lance Ellinghouse,
Cathedral City, California Republic, United States of America.
@ -396,3 +403,8 @@ PyInit_syslog(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_syslog = {
"syslog",
PyInit_syslog,
};

View file

@ -16,6 +16,7 @@
#include "libc/sysv/consts/termios.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/fileobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
@ -790,3 +791,8 @@ PyInit_termios(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_termios = {
"termios",
PyInit_termios,
};

View file

@ -68,6 +68,8 @@ PYTHON_PROVIDE("time.timezone");
PYTHON_PROVIDE("time.tzname");
PYTHON_PROVIDE("time.tzset");
PYTHON_YOINK("_strptime");
typedef int clockid_t;
#undef HAVE_CLOCK_SETTIME
@ -1477,3 +1479,8 @@ pysleep(_PyTime_t secs)
return 0;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_time = {
"time",
PyInit_time,
};

View file

@ -7,6 +7,7 @@
#define PY_SSIZE_T_CLEAN
#include "libc/fmt/fmt.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -1410,3 +1411,8 @@ c-basic-offset: 4
indent-tabs-mode: nil
End:
*/
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_unicodedata = {
"unicodedata",
PyInit_unicodedata,
};

View file

@ -1,55 +1,14 @@
#ifndef Py_WINREPARSE_H
#define Py_WINREPARSE_H
/* clang-format off */
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_
#include "libc/nt/struct/reparsedatabuffer.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef MS_WINDOWS
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
/* The following structure was copied from
http://msdn.microsoft.com/en-us/library/ff552012.aspx as the required
include km\ntifs.h isn't present in the Windows SDK (at least as included
with Visual Studio Express). Use unique names to avoid conflicting with
the structure as defined by Min GW. */
typedef struct {
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union {
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} _Py_REPARSE_DATA_BUFFER, *_Py_PREPARSE_DATA_BUFFER;
#define _Py_REPARSE_DATA_BUFFER struct NtReparseDataBuffer
#define _Py_PREPARSE_DATA_BUFFER struct NtReparseDataBuffer*
#define _Py_REPARSE_DATA_BUFFER_HEADER_SIZE \
FIELD_OFFSET(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer)
#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
offsetof(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer)
#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024)
#ifdef __cplusplus
}
#endif
#endif /* MS_WINDOWS */
#endif /* !Py_WINREPARSE_H */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_ */

View file

@ -40,6 +40,10 @@ PYTHON_PROVIDE("zipimport.ZipImportError");
PYTHON_PROVIDE("zipimport._zip_directory_cache");
PYTHON_PROVIDE("zipimport.zipimporter");
PYTHON_YOINK("encodings.ascii");
PYTHON_YOINK("encodings.cp437");
PYTHON_YOINK("encodings.utf_8");
#define IS_SOURCE 0x0
#define IS_BYTECODE 0x1
#define IS_PACKAGE 0x2
@ -1598,3 +1602,8 @@ PyInit_zipimport(void)
return NULL;
return mod;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_zipimport = {
"zipimport",
PyInit_zipimport,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -1454,3 +1455,8 @@ PyInit_zlib(void)
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_zlib = {
"zlib",
PyInit_zlib,
};

View file

@ -3281,11 +3281,6 @@ PyUnicode_Decode(const char *s,
|| strcmp(lower, "us_ascii") == 0) {
return PyUnicode_DecodeASCII(s, size, errors);
}
#ifdef MS_WINDOWS
else if (strcmp(lower, "mbcs") == 0) {
return PyUnicode_DecodeMBCS(s, size, errors);
}
#endif
else if (strcmp(lower, "latin1") == 0
|| strcmp(lower, "latin_1") == 0
|| strcmp(lower, "iso_8859_1") == 0
@ -7170,730 +7165,6 @@ PyUnicode_AsASCIIString(PyObject *unicode)
return _PyUnicode_AsASCIIString(unicode, NULL);
}
#ifdef MS_WINDOWS
/* --- MBCS codecs for Windows -------------------------------------------- */
#if SIZEOF_INT < SIZEOF_SIZE_T
#define NEED_RETRY
#endif
#ifndef WC_ERR_INVALID_CHARS
# define WC_ERR_INVALID_CHARS 0x0080
#endif
static const char*
code_page_name(UINT code_page, PyObject **obj)
{
*obj = NULL;
if (code_page == CP_ACP)
return "mbcs";
if (code_page == CP_UTF7)
return "CP_UTF7";
if (code_page == CP_UTF8)
return "CP_UTF8";
*obj = PyBytes_FromFormat("cp%u", code_page);
if (*obj == NULL)
return NULL;
return PyBytes_AS_STRING(*obj);
}
static DWORD
decode_code_page_flags(UINT code_page)
{
if (code_page == CP_UTF7) {
/* The CP_UTF7 decoder only supports flags=0 */
return 0;
}
else
return MB_ERR_INVALID_CHARS;
}
/*
* Decode a byte string from a Windows code page into unicode object in strict
* mode.
*
* Returns consumed size if succeed, returns -2 on decode error, or raise an
* OSError and returns -1 on other error.
*/
static int
decode_code_page_strict(UINT code_page,
PyObject **v,
const char *in,
int insize)
{
const DWORD flags = decode_code_page_flags(code_page);
wchar_t *out;
DWORD outsize;
/* First get the size of the result */
assert(insize > 0);
outsize = MultiByteToWideChar(code_page, flags, in, insize, NULL, 0);
if (outsize <= 0)
goto error;
if (*v == NULL) {
/* Create unicode object */
/* FIXME: don't use _PyUnicode_New(), but allocate a wchar_t* buffer */
*v = (PyObject*)_PyUnicode_New(outsize);
if (*v == NULL)
return -1;
out = PyUnicode_AS_UNICODE(*v);
}
else {
/* Extend unicode object */
Py_ssize_t n = PyUnicode_GET_SIZE(*v);
if (unicode_resize(v, n + outsize) < 0)
return -1;
out = PyUnicode_AS_UNICODE(*v) + n;
}
/* Do the conversion */
outsize = MultiByteToWideChar(code_page, flags, in, insize, out, outsize);
if (outsize <= 0)
goto error;
return insize;
error:
if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
return -2;
PyErr_SetFromWindowsErr(0);
return -1;
}
/*
* Decode a byte string from a code page into unicode object with an error
* handler.
*
* Returns consumed size if succeed, or raise an OSError or
* UnicodeDecodeError exception and returns -1 on error.
*/
static int
decode_code_page_errors(UINT code_page,
PyObject **v,
const char *in, const int size,
const char *errors, int final)
{
const char *startin = in;
const char *endin = in + size;
const DWORD flags = decode_code_page_flags(code_page);
/* Ideally, we should get reason from FormatMessage. This is the Windows
2000 English version of the message. */
const char *reason = "No mapping for the Unicode character exists "
"in the target code page.";
/* each step cannot decode more than 1 character, but a character can be
represented as a surrogate pair */
wchar_t buffer[2], *out;
int insize;
Py_ssize_t outsize;
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
PyObject *encoding_obj = NULL;
const char *encoding;
DWORD err;
int ret = -1;
assert(size > 0);
encoding = code_page_name(code_page, &encoding_obj);
if (encoding == NULL)
return -1;
if ((errors == NULL || strcmp(errors, "strict") == 0) && final) {
/* The last error was ERROR_NO_UNICODE_TRANSLATION, then we raise a
UnicodeDecodeError. */
make_decode_exception(&exc, encoding, in, size, 0, 0, reason);
if (exc != NULL) {
PyCodec_StrictErrors(exc);
Py_CLEAR(exc);
}
goto error;
}
if (*v == NULL) {
/* Create unicode object */
if (size > PY_SSIZE_T_MAX / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) {
PyErr_NoMemory();
goto error;
}
/* FIXME: don't use _PyUnicode_New(), but allocate a wchar_t* buffer */
*v = (PyObject*)_PyUnicode_New(size * Py_ARRAY_LENGTH(buffer));
if (*v == NULL)
goto error;
out = PyUnicode_AS_UNICODE(*v);
}
else {
/* Extend unicode object */
Py_ssize_t n = PyUnicode_GET_SIZE(*v);
if (size > (PY_SSIZE_T_MAX - n) / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) {
PyErr_NoMemory();
goto error;
}
if (unicode_resize(v, n + size * Py_ARRAY_LENGTH(buffer)) < 0)
goto error;
out = PyUnicode_AS_UNICODE(*v) + n;
}
/* Decode the byte string character per character */
while (in < endin)
{
/* Decode a character */
insize = 1;
do
{
outsize = MultiByteToWideChar(code_page, flags,
in, insize,
buffer, Py_ARRAY_LENGTH(buffer));
if (outsize > 0)
break;
err = GetLastError();
if (err != ERROR_NO_UNICODE_TRANSLATION
&& err != ERROR_INSUFFICIENT_BUFFER)
{
PyErr_SetFromWindowsErr(0);
goto error;
}
insize++;
}
/* 4=maximum length of a UTF-8 sequence */
while (insize <= 4 && (in + insize) <= endin);
if (outsize <= 0) {
Py_ssize_t startinpos, endinpos, outpos;
/* last character in partial decode? */
if (in + insize >= endin && !final)
break;
startinpos = in - startin;
endinpos = startinpos + 1;
outpos = out - PyUnicode_AS_UNICODE(*v);
if (unicode_decode_call_errorhandler_wchar(
errors, &errorHandler,
encoding, reason,
&startin, &endin, &startinpos, &endinpos, &exc, &in,
v, &outpos))
{
goto error;
}
out = PyUnicode_AS_UNICODE(*v) + outpos;
}
else {
in += insize;
memcpy(out, buffer, outsize * sizeof(wchar_t));
out += outsize;
}
}
/* write a NUL character at the end */
*out = 0;
/* Extend unicode object */
outsize = out - PyUnicode_AS_UNICODE(*v);
assert(outsize <= PyUnicode_WSTR_LENGTH(*v));
if (unicode_resize(v, outsize) < 0)
goto error;
/* (in - startin) <= size and size is an int */
ret = Py_SAFE_DOWNCAST(in - startin, Py_ssize_t, int);
error:
Py_XDECREF(encoding_obj);
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
return ret;
}
static PyObject *
decode_code_page_stateful(int code_page,
const char *s, Py_ssize_t size,
const char *errors, Py_ssize_t *consumed)
{
PyObject *v = NULL;
int chunk_size, final, converted, done;
if (code_page < 0) {
PyErr_SetString(PyExc_ValueError, "invalid code page number");
return NULL;
}
if (size < 0) {
PyErr_BadInternalCall();
return NULL;
}
if (consumed)
*consumed = 0;
do
{
#ifdef NEED_RETRY
if (size > INT_MAX) {
chunk_size = INT_MAX;
final = 0;
done = 0;
}
else
#endif
{
chunk_size = (int)size;
final = (consumed == NULL);
done = 1;
}
if (chunk_size == 0 && done) {
if (v != NULL)
break;
_Py_RETURN_UNICODE_EMPTY();
}
converted = decode_code_page_strict(code_page, &v,
s, chunk_size);
if (converted == -2)
converted = decode_code_page_errors(code_page, &v,
s, chunk_size,
errors, final);
assert(converted != 0 || done);
if (converted < 0) {
Py_XDECREF(v);
return NULL;
}
if (consumed)
*consumed += converted;
s += converted;
size -= converted;
} while (!done);
return unicode_result(v);
}
PyObject *
PyUnicode_DecodeCodePageStateful(int code_page,
const char *s,
Py_ssize_t size,
const char *errors,
Py_ssize_t *consumed)
{
return decode_code_page_stateful(code_page, s, size, errors, consumed);
}
PyObject *
PyUnicode_DecodeMBCSStateful(const char *s,
Py_ssize_t size,
const char *errors,
Py_ssize_t *consumed)
{
return decode_code_page_stateful(CP_ACP, s, size, errors, consumed);
}
PyObject *
PyUnicode_DecodeMBCS(const char *s,
Py_ssize_t size,
const char *errors)
{
return PyUnicode_DecodeMBCSStateful(s, size, errors, NULL);
}
static DWORD
encode_code_page_flags(UINT code_page, const char *errors)
{
if (code_page == CP_UTF8) {
return WC_ERR_INVALID_CHARS;
}
else if (code_page == CP_UTF7) {
/* CP_UTF7 only supports flags=0 */
return 0;
}
else {
if (errors != NULL && strcmp(errors, "replace") == 0)
return 0;
else
return WC_NO_BEST_FIT_CHARS;
}
}
/*
* Encode a Unicode string to a Windows code page into a byte string in strict
* mode.
*
* Returns consumed characters if succeed, returns -2 on encode error, or raise
* an OSError and returns -1 on other error.
*/
static int
encode_code_page_strict(UINT code_page, PyObject **outbytes,
PyObject *unicode, Py_ssize_t offset, int len,
const char* errors)
{
BOOL usedDefaultChar = FALSE;
BOOL *pusedDefaultChar = &usedDefaultChar;
int outsize;
wchar_t *p;
Py_ssize_t size;
const DWORD flags = encode_code_page_flags(code_page, NULL);
char *out;
/* Create a substring so that we can get the UTF-16 representation
of just the slice under consideration. */
PyObject *substring;
assert(len > 0);
if (code_page != CP_UTF8 && code_page != CP_UTF7)
pusedDefaultChar = &usedDefaultChar;
else
pusedDefaultChar = NULL;
substring = PyUnicode_Substring(unicode, offset, offset+len);
if (substring == NULL)
return -1;
p = PyUnicode_AsUnicodeAndSize(substring, &size);
if (p == NULL) {
Py_DECREF(substring);
return -1;
}
assert(size <= INT_MAX);
/* First get the size of the result */
outsize = WideCharToMultiByte(code_page, flags,
p, (int)size,
NULL, 0,
NULL, pusedDefaultChar);
if (outsize <= 0)
goto error;
/* If we used a default char, then we failed! */
if (pusedDefaultChar && *pusedDefaultChar) {
Py_DECREF(substring);
return -2;
}
if (*outbytes == NULL) {
/* Create string object */
*outbytes = PyBytes_FromStringAndSize(NULL, outsize);
if (*outbytes == NULL) {
Py_DECREF(substring);
return -1;
}
out = PyBytes_AS_STRING(*outbytes);
}
else {
/* Extend string object */
const Py_ssize_t n = PyBytes_Size(*outbytes);
if (outsize > PY_SSIZE_T_MAX - n) {
PyErr_NoMemory();
Py_DECREF(substring);
return -1;
}
if (_PyBytes_Resize(outbytes, n + outsize) < 0) {
Py_DECREF(substring);
return -1;
}
out = PyBytes_AS_STRING(*outbytes) + n;
}
/* Do the conversion */
outsize = WideCharToMultiByte(code_page, flags,
p, (int)size,
out, outsize,
NULL, pusedDefaultChar);
Py_CLEAR(substring);
if (outsize <= 0)
goto error;
if (pusedDefaultChar && *pusedDefaultChar)
return -2;
return 0;
error:
Py_XDECREF(substring);
if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
return -2;
PyErr_SetFromWindowsErr(0);
return -1;
}
/*
* Encode a Unicode string to a Windows code page into a byte string using an
* error handler.
*
* Returns consumed characters if succeed, or raise an OSError and returns
* -1 on other error.
*/
static int
encode_code_page_errors(UINT code_page, PyObject **outbytes,
PyObject *unicode, Py_ssize_t unicode_offset,
Py_ssize_t insize, const char* errors)
{
const DWORD flags = encode_code_page_flags(code_page, errors);
Py_ssize_t pos = unicode_offset;
Py_ssize_t endin = unicode_offset + insize;
/* Ideally, we should get reason from FormatMessage. This is the Windows
2000 English version of the message. */
const char *reason = "invalid character";
/* 4=maximum length of a UTF-8 sequence */
char buffer[4];
BOOL usedDefaultChar = FALSE, *pusedDefaultChar;
Py_ssize_t outsize;
char *out;
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
PyObject *encoding_obj = NULL;
const char *encoding;
Py_ssize_t newpos, newoutsize;
PyObject *rep;
int ret = -1;
assert(insize > 0);
encoding = code_page_name(code_page, &encoding_obj);
if (encoding == NULL)
return -1;
if (errors == NULL || strcmp(errors, "strict") == 0) {
/* The last error was ERROR_NO_UNICODE_TRANSLATION,
then we raise a UnicodeEncodeError. */
make_encode_exception(&exc, encoding, unicode, 0, 0, reason);
if (exc != NULL) {
PyCodec_StrictErrors(exc);
Py_DECREF(exc);
}
Py_XDECREF(encoding_obj);
return -1;
}
if (code_page != CP_UTF8 && code_page != CP_UTF7)
pusedDefaultChar = &usedDefaultChar;
else
pusedDefaultChar = NULL;
if (Py_ARRAY_LENGTH(buffer) > PY_SSIZE_T_MAX / insize) {
PyErr_NoMemory();
goto error;
}
outsize = insize * Py_ARRAY_LENGTH(buffer);
if (*outbytes == NULL) {
/* Create string object */
*outbytes = PyBytes_FromStringAndSize(NULL, outsize);
if (*outbytes == NULL)
goto error;
out = PyBytes_AS_STRING(*outbytes);
}
else {
/* Extend string object */
Py_ssize_t n = PyBytes_Size(*outbytes);
if (n > PY_SSIZE_T_MAX - outsize) {
PyErr_NoMemory();
goto error;
}
if (_PyBytes_Resize(outbytes, n + outsize) < 0)
goto error;
out = PyBytes_AS_STRING(*outbytes) + n;
}
/* Encode the string character per character */
while (pos < endin)
{
Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, pos);
wchar_t chars[2];
int charsize;
if (ch < 0x10000) {
chars[0] = (wchar_t)ch;
charsize = 1;
}
else {
chars[0] = Py_UNICODE_HIGH_SURROGATE(ch);
chars[1] = Py_UNICODE_LOW_SURROGATE(ch);
charsize = 2;
}
outsize = WideCharToMultiByte(code_page, flags,
chars, charsize,
buffer, Py_ARRAY_LENGTH(buffer),
NULL, pusedDefaultChar);
if (outsize > 0) {
if (pusedDefaultChar == NULL || !(*pusedDefaultChar))
{
pos++;
memcpy(out, buffer, outsize);
out += outsize;
continue;
}
}
else if (GetLastError() != ERROR_NO_UNICODE_TRANSLATION) {
PyErr_SetFromWindowsErr(0);
goto error;
}
rep = unicode_encode_call_errorhandler(
errors, &errorHandler, encoding, reason,
unicode, &exc,
pos, pos + 1, &newpos);
if (rep == NULL)
goto error;
pos = newpos;
if (PyBytes_Check(rep)) {
outsize = PyBytes_GET_SIZE(rep);
if (outsize != 1) {
Py_ssize_t offset = out - PyBytes_AS_STRING(*outbytes);
newoutsize = PyBytes_GET_SIZE(*outbytes) + (outsize - 1);
if (_PyBytes_Resize(outbytes, newoutsize) < 0) {
Py_DECREF(rep);
goto error;
}
out = PyBytes_AS_STRING(*outbytes) + offset;
}
memcpy(out, PyBytes_AS_STRING(rep), outsize);
out += outsize;
}
else {
Py_ssize_t i;
enum PyUnicode_Kind kind;
void *data;
if (PyUnicode_READY(rep) == -1) {
Py_DECREF(rep);
goto error;
}
outsize = PyUnicode_GET_LENGTH(rep);
if (outsize != 1) {
Py_ssize_t offset = out - PyBytes_AS_STRING(*outbytes);
newoutsize = PyBytes_GET_SIZE(*outbytes) + (outsize - 1);
if (_PyBytes_Resize(outbytes, newoutsize) < 0) {
Py_DECREF(rep);
goto error;
}
out = PyBytes_AS_STRING(*outbytes) + offset;
}
kind = PyUnicode_KIND(rep);
data = PyUnicode_DATA(rep);
for (i=0; i < outsize; i++) {
Py_UCS4 ch = PyUnicode_READ(kind, data, i);
if (ch > 127) {
raise_encode_exception(&exc,
encoding, unicode,
pos, pos + 1,
"unable to encode error handler result to ASCII");
Py_DECREF(rep);
goto error;
}
*out = (unsigned char)ch;
out++;
}
}
Py_DECREF(rep);
}
/* write a NUL byte */
*out = 0;
outsize = out - PyBytes_AS_STRING(*outbytes);
assert(outsize <= PyBytes_GET_SIZE(*outbytes));
if (_PyBytes_Resize(outbytes, outsize) < 0)
goto error;
ret = 0;
error:
Py_XDECREF(encoding_obj);
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
return ret;
}
static PyObject *
encode_code_page(int code_page,
PyObject *unicode,
const char *errors)
{
Py_ssize_t len;
PyObject *outbytes = NULL;
Py_ssize_t offset;
int chunk_len, ret, done;
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(unicode) == -1)
return NULL;
len = PyUnicode_GET_LENGTH(unicode);
if (code_page < 0) {
PyErr_SetString(PyExc_ValueError, "invalid code page number");
return NULL;
}
if (len == 0)
return PyBytes_FromStringAndSize(NULL, 0);
offset = 0;
do
{
#ifdef NEED_RETRY
/* UTF-16 encoding may double the size, so use only INT_MAX/2
chunks. */
if (len > INT_MAX/2) {
chunk_len = INT_MAX/2;
done = 0;
}
else
#endif
{
chunk_len = (int)len;
done = 1;
}
ret = encode_code_page_strict(code_page, &outbytes,
unicode, offset, chunk_len,
errors);
if (ret == -2)
ret = encode_code_page_errors(code_page, &outbytes,
unicode, offset,
chunk_len, errors);
if (ret < 0) {
Py_XDECREF(outbytes);
return NULL;
}
offset += chunk_len;
len -= chunk_len;
} while (!done);
return outbytes;
}
PyObject *
PyUnicode_EncodeMBCS(const Py_UNICODE *p,
Py_ssize_t size,
const char *errors)
{
PyObject *unicode, *res;
unicode = PyUnicode_FromUnicode(p, size);
if (unicode == NULL)
return NULL;
res = encode_code_page(CP_ACP, unicode, errors);
Py_DECREF(unicode);
return res;
}
PyObject *
PyUnicode_EncodeCodePage(int code_page,
PyObject *unicode,
const char *errors)
{
return encode_code_page(code_page, unicode, errors);
}
PyObject *
PyUnicode_AsMBCSString(PyObject *unicode)
{
return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL);
}
#undef NEED_RETRY
#endif /* MS_WINDOWS */
/* --- Character Mapping Codec -------------------------------------------- */
static int

2
third_party/python/Programs/hello.c vendored Normal file
View file

@ -0,0 +1,2 @@
#define LAUNCH "hello"
#include "third_party/python/Programs/launch.c"

View file

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

143
third_party/python/Programs/launch.c vendored Normal file
View file

@ -0,0 +1,143 @@
/*-*- 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/bits/safemacros.internal.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/nexgen32e/rdtsc.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 "libc/zip.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/modsupport.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/sysmodule.h"
#include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */
#define _L(x) L##x
#define L(x) _L(x)
PYTHON_YOINK(LAUNCH);
PYTHON_YOINK("_bootlocale");
PYTHON_YOINK("_locale");
PYTHON_YOINK("encodings.aliases");
PYTHON_YOINK("encodings.latin_1");
PYTHON_YOINK("encodings.utf_8");
PYTHON_YOINK("launchpy");
const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
static int LaunchModule(wchar_t *modname)
{
PyObject *module, *runpy, *runmodule, *runargs, *result;
runpy = PyImport_ImportModule("launchpy");
if (runpy == NULL) {
fprintf(stderr, "Could not import launchpy module\n");
PyErr_Print();
return -1;
}
runmodule = PyObject_GetAttrString(runpy, "run_module_as_main");
if (runmodule == NULL) {
fprintf(stderr, "Could not access launchpy.run_module_as_main\n");
PyErr_Print();
Py_DECREF(runpy);
return -1;
}
module = PyUnicode_FromWideChar(modname, wcslen(modname));
if (module == NULL) {
fprintf(stderr, "Could not convert module name to unicode\n");
PyErr_Print();
Py_DECREF(runpy);
Py_DECREF(runmodule);
return -1;
}
runargs = Py_BuildValue("(O)", module);
if (runargs == NULL) {
fprintf(stderr,
"Could not create arguments for runpy._run_module_as_main\n");
PyErr_Print();
Py_DECREF(runpy);
Py_DECREF(runmodule);
Py_DECREF(module);
return -1;
}
result = PyObject_Call(runmodule, runargs, NULL);
if (result == NULL) {
PyErr_Print();
}
Py_DECREF(runpy);
Py_DECREF(runmodule);
Py_DECREF(module);
Py_DECREF(runargs);
if (result == NULL) {
return -1;
}
Py_DECREF(result);
return 0;
}
int
main(int argc, char **argv)
{
int i, res;
char *oldloc;
wchar_t **argv_copy;
wchar_t **argv_copy2;
_PyMem_SetupAllocators("malloc");
argv_copy = gc(malloc(sizeof(wchar_t*) * (argc+1)));
argv_copy2 = gc(malloc(sizeof(wchar_t*) * (argc+1)));
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
argv_copy2[i] = argv_copy[i] = gc(utf8toutf32(argv[i], -1, 0));
}
argv_copy2[argc] = argv_copy[argc] = NULL;
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
_PyRandom_Init();
Py_FrozenFlag++;
Py_NoSiteFlag++;
/* Py_VerboseFlag++; */
Py_NoUserSiteDirectory++;
Py_IgnoreEnvironmentFlag++;
Py_DontWriteBytecodeFlag++;
Py_Initialize();
Py_LimitedPath();
PySys_SetArgvEx(argc, argv_copy, 0);
res = LaunchModule(L(LAUNCH)) != 0;
_PyMem_SetupAllocators("malloc");
return res;
}

View file

@ -131,20 +131,15 @@ PYTHON_YOINK("weakref");
PYTHON_YOINK("webbrowser");
PYTHON_YOINK("xdrlib");
#if !IsTiny()
PYTHON_YOINK("aifc");
PYTHON_YOINK("wave");
PYTHON_YOINK("sunau");
#endif
#if !IsTiny()
PYTHON_YOINK("dis");
PYTHON_YOINK("codeop");
PYTHON_YOINK("compileall");
PYTHON_YOINK("py_compile");
#endif
#if !IsTiny()
PYTHON_YOINK("cgi");
PYTHON_YOINK("pdb");
PYTHON_YOINK("cgitb");
@ -154,9 +149,7 @@ PYTHON_YOINK("profile");
PYTHON_YOINK("inspect");
PYTHON_YOINK("cProfile");
PYTHON_YOINK("tracemalloc");
#endif
#if !IsTiny()
PYTHON_YOINK("bz2");
PYTHON_YOINK("ssl");
PYTHON_YOINK("gzip");
@ -169,7 +162,6 @@ PYTHON_YOINK("zipfile");
PYTHON_YOINK("telnetlib");
PYTHON_YOINK("antigravity");
PYTHON_YOINK("rlcompleter");
#endif
PYTHON_YOINK("collections");
PYTHON_YOINK("collections.abc");
@ -246,20 +238,15 @@ PYTHON_YOINK("wsgiref.simple_server");
PYTHON_YOINK("wsgiref.util");
PYTHON_YOINK("wsgiref.validate");
#if !IsTiny()
PYTHON_YOINK("sqlite3");
PYTHON_YOINK("sqlite3.dbapi2");
PYTHON_YOINK("sqlite3.dump");
#endif
#if !IsTiny()
PYTHON_YOINK("dbm");
PYTHON_YOINK("dbm.dumb");
PYTHON_YOINK("dbm.gnu");
PYTHON_YOINK("dbm.ndbm");
#endif
#if !IsTiny()
PYTHON_YOINK("xml");
PYTHON_YOINK("xml.dom.NodeFilter");
PYTHON_YOINK("xml.dom");
@ -285,9 +272,7 @@ PYTHON_YOINK("xml.sax.xmlreader");
PYTHON_YOINK("xmlrpc");
PYTHON_YOINK("xmlrpc.client");
PYTHON_YOINK("xmlrpc.server");
#endif
#if !IsTiny()
PYTHON_YOINK("multiprocessing");
PYTHON_YOINK("multiprocessing.connection");
PYTHON_YOINK("multiprocessing.context");
@ -310,9 +295,7 @@ PYTHON_YOINK("multiprocessing.sharedctypes");
PYTHON_YOINK("multiprocessing.spawn");
PYTHON_YOINK("multiprocessing.synchronize");
PYTHON_YOINK("multiprocessing.util");
#endif
#if !IsTiny()
PYTHON_YOINK("unittest");
PYTHON_YOINK("unittest.__main__");
PYTHON_YOINK("unittest.case");
@ -324,9 +307,7 @@ PYTHON_YOINK("unittest.runner");
PYTHON_YOINK("unittest.signals");
PYTHON_YOINK("unittest.suite");
PYTHON_YOINK("unittest.util");
#endif
#if !IsTiny()
PYTHON_YOINK("venv");
PYTHON_YOINK("venv.__main__");
STATIC_YOINK(".python/venv/scripts/common/activate");
@ -441,7 +422,6 @@ PYTHON_YOINK("msilib");
PYTHON_YOINK("msilib.schema");
PYTHON_YOINK("msilib.sequence");
PYTHON_YOINK("msilib.text");
#endif
PYTHON_YOINK("encodings");
PYTHON_YOINK("encodings.aliases");
@ -464,7 +444,6 @@ PYTHON_YOINK("encodings.base64_codec");
PYTHON_YOINK("encodings.unicode_escape");
PYTHON_YOINK("encodings.unicode_internal");
PYTHON_YOINK("encodings.raw_unicode_escape");
#if !IsTiny()
PYTHON_YOINK("encodings.zlib_codec");
PYTHON_YOINK("encodings.big5");
PYTHON_YOINK("encodings.big5hkscs");
@ -569,9 +548,7 @@ PYTHON_YOINK("encodings.shift_jis_2004");
PYTHON_YOINK("encodings.shift_jisx0213");
PYTHON_YOINK("encodings.tis_620");
PYTHON_YOINK("encodings.utf_7");
#endif
#if !IsTiny()
PYTHON_YOINK("smtpd");
PYTHON_YOINK("poplib");
PYTHON_YOINK("imaplib");
@ -579,7 +556,6 @@ PYTHON_YOINK("mailbox");
PYTHON_YOINK("mailcap");
PYTHON_YOINK("smtplib");
PYTHON_YOINK("nntplib");
#endif
#ifdef WITH_THREAD
PYTHON_YOINK("asynchat");

View file

@ -2289,7 +2289,7 @@ const unsigned char _Py_M__importlib_external[] = {
0,0,0,0,0,0,0,3,0,0,0,3,0,0,0,67,
0,0,0,115,38,0,0,0,116,0,116,1,106,2,131,0,
102,2,125,0,116,3,116,4,102,2,125,1,116,5,116,6,
102,2,125,2,124,0,124,2,124,1,103,3,83,0,41,1,
102,2,125,2,124,2,124,0,124,1,103,3,83,0,41,1,
122,95,82,101,116,117,114,110,115,32,97,32,108,105,115,116,
32,111,102,32,102,105,108,101,45,98,97,115,101,100,32,109,
111,100,117,108,101,32,108,111,97,100,101,114,115,46,10,10,

View file

@ -320,20 +320,19 @@ import_init(PyInterpreterState *interp, PyObject *sysmod)
}
Py_DECREF(value);
Py_DECREF(impmod);
/* just add /zip/.python/ to sys.path */
/* _PyImportZip_Init(); */
PyImport_ImportModule("_codecs");
PyImport_ImportModule("_collections");
PyImport_ImportModule("_functools");
PyImport_ImportModule("_heapq");
PyImport_ImportModule("_locale");
PyImport_ImportModule("_operator");
PyImport_ImportModule("_signal");
PyImport_ImportModule("_sre");
PyImport_ImportModule("_stat");
PyImport_ImportModule("errno");
PyImport_ImportModule("itertools");
/* PyImport_ImportModule("_codecs"); */
/* PyImport_ImportModule("_collections"); */
/* PyImport_ImportModule("_functools"); */
/* PyImport_ImportModule("_heapq"); */
/* PyImport_ImportModule("_locale"); */
/* PyImport_ImportModule("_operator"); */
/* PyImport_ImportModule("_signal"); */
/* PyImport_ImportModule("_sre"); */
/* PyImport_ImportModule("_stat"); */
/* PyImport_ImportModule("errno"); */
/* PyImport_ImportModule("itertools"); */
}

View file

@ -38,6 +38,8 @@
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/ucnhash.h"
#include "third_party/python/Include/yoink.h"
#include "tool/build/lib/stripcomponents.h"
/* clang-format off */
@ -120,6 +122,7 @@ main(int argc, char *argv[])
Py_NoSiteFlag++;
Py_IgnoreEnvironmentFlag++;
Py_FrozenFlag++;
/* Py_VerboseFlag++; */
Py_SetProgramName(gc(utf8toutf32(argv[0], -1, 0)));
_Py_InitializeEx_Private(1, 0);
name = gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3)));

View file

@ -1132,5 +1132,8 @@
#define SELECT_USES_HEAP 1
#define OPENSSL_NO_SCRYPT
#define OPENSSL_NO_COMP
#define HAVE_LANGINFO_H
#endif /*Py_PYCONFIG_H*/

View file

@ -75,8 +75,10 @@ FLAGS\n\
-h help\n\
\n"
const char *const kIgnoredModules[] = /* sorted */ {
/* const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; */
/* struct _inittab *PyImport_Inittab = _PyImport_Inittab; */
const char *const kIgnoredModules[] = /* sorted */ {
"__main__", /* todo? */
"_dummy_threading", /* evil code */
"_dummy_threading.Thread",
@ -200,7 +202,6 @@ const char *const kIgnoredModules[] = /* sorted */ {
"test.libregrtest.main",
"xml.dom",
"xml.sax",
};
static bool binonly;

View file

@ -27,6 +27,7 @@ THIRD_PARTY_PYTHON_COMS = \
o/$(MODE)/third_party/python/pyobj.com \
o/$(MODE)/third_party/python/pycomp.com \
o/$(MODE)/third_party/python/repl.com \
o/$(MODE)/third_party/python/hello.com \
o/$(MODE)/third_party/python/httpserver.com \
o/$(MODE)/third_party/python/pythontester.com
@ -298,6 +299,7 @@ THIRD_PARTY_PYTHON_INCS = \
third_party/python/Modules/clinic/pwdmodule.inc \
third_party/python/Modules/clinic/audioop.inc \
third_party/python/Modules/clinic/sha256module.inc \
third_party/python/Modules/clinic/_hashmbedtls.inc \
third_party/python/Modules/unicodedata_db.inc
THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
@ -401,10 +403,12 @@ THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
third_party/python/Python/symtable.c \
third_party/python/Parser/listnode.c \
third_party/python/Python/sysmodule.c \
third_party/python/Modules/unicodedata.c \
third_party/python/Objects/unicodetonumeric.c \
third_party/python/Python/traceback.c
THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \
third_party/python/Modules/_hashopenssl.c \
third_party/python/Modules/_hashmbedtls.c \
third_party/python/Objects/fromfd.c \
third_party/python/Modules/_bisectmodule.c \
third_party/python/Modules/_bz2module.c \
@ -511,11 +515,9 @@ THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \
third_party/python/Modules/syslogmodule.c \
third_party/python/Modules/termios.c \
third_party/python/Modules/timemodule.c \
third_party/python/Modules/unicodedata.c \
third_party/python/Modules/zipimport.c \
third_party/python/Modules/zlibmodule.c \
third_party/python/Objects/accu.c \
third_party/python/Objects/unicodetonumeric.c \
third_party/python/Objects/weakrefobject.c \
third_party/python/Parser/bitset.c \
third_party/python/Parser/firstsets.c \
@ -1208,12 +1210,14 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \
third_party/python/Lib/re.py \
third_party/python/Lib/reprlib.py \
third_party/python/Lib/runpy.py \
third_party/python/Lib/launchpy.py \
third_party/python/Lib/sched.py \
third_party/python/Lib/secrets.py \
third_party/python/Lib/selectors.py \
third_party/python/Lib/shelve.py \
third_party/python/Lib/shlex.py \
third_party/python/Lib/shutil.py \
third_party/python/Lib/hello.py \
third_party/python/Lib/signal.py \
third_party/python/Lib/site.py \
third_party/python/Lib/smtpd.py \
@ -1922,6 +1926,16 @@ o/$(MODE)/third_party/python/httpserver.com.dbg: \
$(APE)
@$(APELINK)
o/$(MODE)/third_party/python/hello.com.dbg: \
$(THIRD_PARTY_PYTHON_STAGE1) \
$(THIRD_PARTY_PYTHON_STAGE1_A).pkg \
$(THIRD_PARTY_PYTHON_STAGE2) \
$(THIRD_PARTY_PYTHON_STAGE2_A).pkg \
o/$(MODE)/third_party/python/Programs/hello.o \
$(CRT) \
$(APE)
@$(APELINK)
o/$(MODE)/third_party/python/pythontester.com.dbg: \
$(THIRD_PARTY_PYTHON_STAGE1) \
$(THIRD_PARTY_PYTHON_STAGE1_A).pkg \
@ -2035,8 +2049,12 @@ THIRD_PARTY_PYTHON_SRCS = \
$(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_SRCS)) \
third_party/python/pyobj.c \
third_party/python/pycomp.c \
third_party/python/Programs/repl.c \
third_party/python/Programs/hello.c \
third_party/python/Programs/launch.c \
third_party/python/Programs/freeze.c \
third_party/python/Programs/python.c \
third_party/python/Programs/httpserver.c \
third_party/python/Programs/pythontester.c
#$(THIRD_PARTY_PYTHON_OBJS): \