mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 09:18:31 +00:00
Add MODE=optlinux build mode (#141)
This commit is contained in:
parent
226aaf3547
commit
67b5200a0b
111 changed files with 934 additions and 854 deletions
5
third_party/infozip/zip/tailor.h
vendored
5
third_party/infozip/zip/tailor.h
vendored
|
@ -36,6 +36,7 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/infozip/zip/unix/osdep.h"
|
||||
|
||||
|
||||
|
@ -133,8 +134,8 @@
|
|||
* to_up is used to force upper case even on Unix (for dosify option).
|
||||
*/
|
||||
#ifdef USE_CASE_MAP
|
||||
# define case_map(c) upper[(c) & 0xff]
|
||||
# define to_up(c) upper[(c) & 0xff]
|
||||
# define case_map(c) kToUpper[(c) & 0xff]
|
||||
# define to_up(c) kToLower[(c) & 0xff]
|
||||
#else
|
||||
# define case_map(c) (c)
|
||||
# define to_up(c) ((c) >= 'a' && (c) <= 'z' ? (c)-'a'+'A' : (c))
|
||||
|
|
65
third_party/infozip/zip/util.c
vendored
65
third_party/infozip/zip/util.c
vendored
|
@ -597,71 +597,6 @@ int (*cmp) OF((ZCONST zvoid *, ZCONST zvoid far *)); /* comparison function */
|
|||
|
||||
#endif /* !UTIL */
|
||||
|
||||
#ifdef MSDOS16
|
||||
|
||||
local unsigned ident(unsigned chr)
|
||||
{
|
||||
return chr; /* in al */
|
||||
}
|
||||
|
||||
void init_upper()
|
||||
{
|
||||
static struct country {
|
||||
uch ignore[18];
|
||||
int (far *casemap)(int);
|
||||
uch filler[16];
|
||||
} country_info;
|
||||
|
||||
struct country far *info = &country_info;
|
||||
union REGS regs;
|
||||
struct SREGS sregs;
|
||||
unsigned int c;
|
||||
|
||||
regs.x.ax = 0x3800; /* get country info */
|
||||
regs.x.dx = FP_OFF(info);
|
||||
sregs.ds = FP_SEG(info);
|
||||
intdosx(®s, ®s, &sregs);
|
||||
for (c = 0; c < 128; c++) {
|
||||
upper[c] = (uch) toupper(c);
|
||||
lower[c] = (uch) c;
|
||||
}
|
||||
for (; c < sizeof(upper); c++) {
|
||||
upper[c] = (uch) (*country_info.casemap)(ident(c));
|
||||
/* ident() required because casemap takes its parameter in al */
|
||||
lower[c] = (uch) c;
|
||||
}
|
||||
for (c = 0; c < sizeof(upper); c++ ) {
|
||||
unsigned int u = upper[c];
|
||||
if (u != c && lower[u] == (uch) u) {
|
||||
lower[u] = (uch)c;
|
||||
}
|
||||
}
|
||||
for (c = 'A'; c <= 'Z'; c++) {
|
||||
lower[c] = (uch) (c - 'A' + 'a');
|
||||
}
|
||||
}
|
||||
#else /* !MSDOS16 */
|
||||
# ifndef OS2
|
||||
|
||||
void init_upper()
|
||||
{
|
||||
unsigned int c;
|
||||
#if defined(ATARI) || defined(CMS_MVS)
|
||||
/* this should be valid for all other platforms too. (HD 11/11/95) */
|
||||
for (c = 0; c< sizeof(upper); c++) {
|
||||
upper[c] = islower(c) ? toupper(c) : c;
|
||||
lower[c] = isupper(c) ? tolower(c) : c;
|
||||
}
|
||||
#else
|
||||
for (c = 0; c < sizeof(upper); c++) upper[c] = lower[c] = (uch)c;
|
||||
for (c = 'a'; c <= 'z'; c++) upper[c] = (uch)(c - 'a' + 'A');
|
||||
for (c = 'A'; c <= 'Z'; c++) lower[c] = (uch)(c - 'A' + 'a');
|
||||
#endif
|
||||
}
|
||||
# endif /* !OS2 */
|
||||
|
||||
#endif /* ?MSDOS16 */
|
||||
|
||||
int namecmp(string1, string2)
|
||||
ZCONST char *string1, *string2;
|
||||
/* Compare the two strings ignoring case, and correctly taking into
|
||||
|
|
2
third_party/infozip/zip/zip.c
vendored
2
third_party/infozip/zip/zip.c
vendored
|
@ -2489,8 +2489,6 @@ char **argv; /* command line tokens */
|
|||
mesg = (FILE *) stdout; /* cannot be made at link time for VMS */
|
||||
comment_stream = (FILE *)stdin;
|
||||
|
||||
init_upper(); /* build case map table */
|
||||
|
||||
#ifdef LARGE_FILE_SUPPORT
|
||||
/* test if we can support large files - 9/29/04 */
|
||||
if (sizeof(zoff_t) < 8) {
|
||||
|
|
2
third_party/infozip/zip/zipcloak.c
vendored
2
third_party/infozip/zip/zipcloak.c
vendored
|
@ -388,8 +388,6 @@ int main(argc, argv)
|
|||
/* Informational messages are written to stdout. */
|
||||
mesg = stdout;
|
||||
|
||||
init_upper(); /* build case map table */
|
||||
|
||||
#ifndef USE_ZLIB
|
||||
crc_32_tab = get_crc_table();
|
||||
/* initialize crc table for crypt */
|
||||
|
|
2
third_party/infozip/zip/zipnote.c
vendored
2
third_party/infozip/zip/zipnote.c
vendored
|
@ -454,8 +454,6 @@ char **argv; /* command line tokens */
|
|||
/* Direct info messages to stderr; stdout is used for data output. */
|
||||
mesg = stderr;
|
||||
|
||||
init_upper(); /* build case map table */
|
||||
|
||||
/* Go through args */
|
||||
zipfile = tempzip = NULL;
|
||||
tempzf = NULL;
|
||||
|
|
2
third_party/infozip/zip/zipsplit.c
vendored
2
third_party/infozip/zip/zipsplit.c
vendored
|
@ -586,8 +586,6 @@ char **argv; /* command line tokens */
|
|||
/* Informational messages are written to stdout. */
|
||||
mesg = stdout;
|
||||
|
||||
init_upper(); /* build case map table */
|
||||
|
||||
/* Go through args */
|
||||
signal(SIGINT, handler);
|
||||
#ifdef SIGTERM /* Amiga has no SIGTERM */
|
||||
|
|
2
third_party/mbedtls/ssl_cli.c
vendored
2
third_party/mbedtls/ssl_cli.c
vendored
|
@ -1655,7 +1655,7 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
/* If we got here, we no longer need our cached extension */
|
||||
/* If we goth here, we no longer need our cached extension */
|
||||
mbedtls_free( ssl->handshake->ecjpake_cache );
|
||||
ssl->handshake->ecjpake_cache = NULL;
|
||||
ssl->handshake->ecjpake_cache_len = 0;
|
||||
|
|
2
third_party/python/Lib/idlelib/config.py
vendored
2
third_party/python/Lib/idlelib/config.py
vendored
|
@ -839,7 +839,7 @@ class ConfigChanges(dict):
|
|||
if idleConf.defaultCfg[config_type].Get(section, item) == value:
|
||||
# The setting equals a default setting, remove it from user cfg.
|
||||
return idleConf.userCfg[config_type].RemoveOption(section, item)
|
||||
# If we got here, set the option.
|
||||
# If we goth here, set the option.
|
||||
return idleConf.userCfg[config_type].SetOption(section, item, value)
|
||||
|
||||
def save_all(self):
|
||||
|
|
4
third_party/python/Lib/ipaddress.py
vendored
4
third_party/python/Lib/ipaddress.py
vendored
|
@ -797,7 +797,7 @@ class _BaseNetwork(_IPAddressBase):
|
|||
yield s1
|
||||
s1, s2 = s2.subnets()
|
||||
else:
|
||||
# If we got here, there's a bug somewhere.
|
||||
# If we goth here, there's a bug somewhere.
|
||||
raise AssertionError('Error performing exclusion: '
|
||||
's1: %s s2: %s other: %s' %
|
||||
(s1, s2, other))
|
||||
|
@ -806,7 +806,7 @@ class _BaseNetwork(_IPAddressBase):
|
|||
elif s2 == other:
|
||||
yield s1
|
||||
else:
|
||||
# If we got here, there's a bug somewhere.
|
||||
# If we goth here, there's a bug somewhere.
|
||||
raise AssertionError('Error performing exclusion: '
|
||||
's1: %s s2: %s other: %s' %
|
||||
(s1, s2, other))
|
||||
|
|
2
third_party/python/Lib/smtplib.py
vendored
2
third_party/python/Lib/smtplib.py
vendored
|
@ -886,7 +886,7 @@ class SMTP:
|
|||
else:
|
||||
self._rset()
|
||||
raise SMTPDataError(code, resp)
|
||||
#if we got here then somebody got our mail
|
||||
#if we goth here then somebody got our mail
|
||||
return senderrs
|
||||
|
||||
def send_message(self, msg, from_addr=None, to_addrs=None,
|
||||
|
|
BIN
third_party/python/Lib/test/hello.com
vendored
Executable file
BIN
third_party/python/Lib/test/hello.com
vendored
Executable file
Binary file not shown.
22
third_party/python/Lib/test/test_cosmo.py
vendored
Normal file
22
third_party/python/Lib/test/test_cosmo.py
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import subprocess
|
||||
|
||||
|
||||
class SubprocessTest(unittest.TestCase):
|
||||
def test_execve(self):
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, tmp_dir)
|
||||
exe = os.path.join(tmp_dir, 'hello.com')
|
||||
shutil.copyfile('/zip/.python/test/hello.com', exe)
|
||||
os.chmod(exe, 0755)
|
||||
proc = subprocess.Popen([exe], stdout=subprocess.PIPE)
|
||||
stdout, stderr = proc.communicate()
|
||||
self.assertEqual(b'hello world\n', stdout)
|
||||
self.assertEqual(0, proc.wait())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -502,7 +502,7 @@ class TestUrlopen(unittest.TestCase):
|
|||
return handler
|
||||
|
||||
def test_redirection(self):
|
||||
expected_response = b"We got here..."
|
||||
expected_response = b"We goth here..."
|
||||
responses = [
|
||||
(302, [("Location", "http://localhost:%(port)s/somewhere_else")],
|
||||
""),
|
||||
|
|
9
third_party/python/Objects/dictobject.c
vendored
9
third_party/python/Objects/dictobject.c
vendored
|
@ -6,6 +6,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/countbranch.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
|
@ -1422,10 +1423,10 @@ PyDict_GetItem(PyObject *op, PyObject *key)
|
|||
PyThreadState *tstate;
|
||||
PyObject **value_addr;
|
||||
|
||||
if (!PyDict_Check(op))
|
||||
if (UNLIKELY(!PyDict_Check(op)))
|
||||
return NULL;
|
||||
if (!PyUnicode_CheckExact(key) ||
|
||||
(hash = ((PyASCIIObject *) key)->hash) == -1)
|
||||
if (UNLIKELY(!PyUnicode_CheckExact(key)) ||
|
||||
UNLIKELY((hash = ((PyASCIIObject *) key)->hash) == -1))
|
||||
{
|
||||
hash = PyObject_Hash(key);
|
||||
if (hash == -1) {
|
||||
|
@ -1440,7 +1441,7 @@ PyDict_GetItem(PyObject *op, PyObject *key)
|
|||
_PyThreadState_Current and not PyThreadState_GET() because in debug
|
||||
mode, the latter complains if tstate is NULL. */
|
||||
tstate = _PyThreadState_UncheckedGet();
|
||||
if (tstate != NULL && tstate->curexc_type != NULL) {
|
||||
if (UNLIKELY(tstate != NULL && tstate->curexc_type != NULL)) {
|
||||
/* preserve the existing exception */
|
||||
PyObject *err_type, *err_value, *err_tb;
|
||||
PyErr_Fetch(&err_type, &err_value, &err_tb);
|
||||
|
|
9
third_party/python/Objects/object.c
vendored
9
third_party/python/Objects/object.c
vendored
|
@ -4,6 +4,8 @@
|
|||
│ Python 3 │
|
||||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/log/countbranch.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
#include "third_party/python/Include/bytearrayobject.h"
|
||||
|
@ -1101,7 +1103,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
|||
Py_ssize_t dictoffset;
|
||||
PyObject **dictptr;
|
||||
|
||||
if (!PyUnicode_Check(name)){
|
||||
if (UNLIKELY(!PyUnicode_Check(name))){
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
|
@ -1109,7 +1111,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
|||
}
|
||||
Py_INCREF(name);
|
||||
|
||||
if (tp->tp_dict == NULL) {
|
||||
if (UNLIKELY(tp->tp_dict == NULL)) {
|
||||
if (PyType_Ready(tp) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
@ -1126,7 +1128,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
|||
}
|
||||
}
|
||||
|
||||
if (dict == NULL) {
|
||||
if (LIKELY(dict == NULL)) {
|
||||
/* Inline _PyObject_GetDictPtr */
|
||||
dictoffset = tp->tp_dictoffset;
|
||||
if (dictoffset != 0) {
|
||||
|
@ -1148,6 +1150,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
|||
dict = *dictptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (dict != NULL) {
|
||||
Py_INCREF(dict);
|
||||
res = PyDict_GetItem(dict, name);
|
||||
|
|
16
third_party/python/Objects/typeobject.c
vendored
16
third_party/python/Objects/typeobject.c
vendored
|
@ -5,7 +5,9 @@
|
|||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/countbranch.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
#include "third_party/python/Include/cellobject.h"
|
||||
|
@ -2940,12 +2942,12 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
|
|||
PyObject *mro, *res, *base, *dict;
|
||||
unsigned int h;
|
||||
|
||||
if (MCACHE_CACHEABLE_NAME(name) &&
|
||||
PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
|
||||
if (LIKELY(MCACHE_CACHEABLE_NAME(name)) &&
|
||||
LIKELY(PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))) {
|
||||
/* fast path */
|
||||
h = MCACHE_HASH_METHOD(type, name);
|
||||
if (method_cache[h].version == type->tp_version_tag &&
|
||||
method_cache[h].name == name) {
|
||||
if (LIKELY(method_cache[h].version == type->tp_version_tag) &&
|
||||
LIKELY(method_cache[h].name == name)) {
|
||||
#if MCACHE_STATS
|
||||
method_cache_hits++;
|
||||
#endif
|
||||
|
@ -2956,9 +2958,9 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
|
|||
/* Look in tp_dict of types in MRO */
|
||||
mro = type->tp_mro;
|
||||
|
||||
if (mro == NULL) {
|
||||
if ((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
|
||||
PyType_Ready(type) < 0) {
|
||||
if (UNLIKELY(mro == NULL)) {
|
||||
if (UNLIKELY((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
|
||||
PyType_Ready(type) < 0)) {
|
||||
/* It's not ideal to clear the error condition,
|
||||
but this function is documented as not setting
|
||||
an exception, and I don't want to change that.
|
||||
|
|
18
third_party/python/Objects/unicodeobject.c
vendored
18
third_party/python/Objects/unicodeobject.c
vendored
|
@ -10,6 +10,7 @@
|
|||
#include "libc/bits/weaken.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/countbranch.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
|
@ -3294,14 +3295,26 @@ PyUnicode_Decode(const char *s,
|
|||
Py_buffer info;
|
||||
char buflower[11]; /* strlen("iso-8859-1\0") == 11, longest shortcut */
|
||||
|
||||
if (encoding == NULL) {
|
||||
if (UNLIKELY(encoding == NULL)) {
|
||||
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
|
||||
}
|
||||
|
||||
/* [jart] faster path based on profiling */
|
||||
if (encoding[0] == 'l' &&
|
||||
encoding[1] == 'a' &&
|
||||
encoding[2] == 't' &&
|
||||
encoding[3] == 'i' &&
|
||||
encoding[4] == 'n' &&
|
||||
(encoding[5] == '1' ||
|
||||
((encoding[5] == '-' ||
|
||||
encoding[5] == '_') &&
|
||||
encoding[6] == '1'))) {
|
||||
return PyUnicode_DecodeLatin1(s, size, errors);
|
||||
}
|
||||
|
||||
/* Shortcuts for common default encodings */
|
||||
if (_Py_normalize_encoding(encoding, buflower, sizeof(buflower))) {
|
||||
char *lower = buflower;
|
||||
|
||||
/* Fast paths */
|
||||
if (lower[0] == 'u' && lower[1] == 't' && lower[2] == 'f') {
|
||||
lower += 3;
|
||||
|
@ -3309,7 +3322,6 @@ PyUnicode_Decode(const char *s,
|
|||
/* Match "utf8" and "utf_8" */
|
||||
lower++;
|
||||
}
|
||||
|
||||
if (lower[0] == '8' && lower[1] == 0) {
|
||||
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
|
||||
}
|
||||
|
|
10
third_party/python/python.mk
vendored
10
third_party/python/python.mk
vendored
|
@ -1319,6 +1319,7 @@ THIRD_PARTY_PYTHON_PYTEST_A_DATA = \
|
|||
third_party/python/Lib/venv/scripts/nt/deactivate.bat \
|
||||
third_party/python/Lib/venv/scripts/posix/activate.csh \
|
||||
third_party/python/Lib/venv/scripts/posix/activate.fish \
|
||||
third_party/python/Lib/test/hello.com \
|
||||
third_party/python/Lib/test/xmltestdata/ \
|
||||
third_party/python/Lib/test/xmltestdata/simple.xml \
|
||||
third_party/python/Lib/test/xmltestdata/simple-ns.xml \
|
||||
|
@ -1808,6 +1809,7 @@ THIRD_PARTY_PYTHON_PYTEST_PYMAINS = \
|
|||
third_party/python/Lib/test/test_mimetypes.py \
|
||||
third_party/python/Lib/test/test_hashlib.py \
|
||||
third_party/python/Lib/test/test_kdf.py \
|
||||
third_party/python/Lib/test/test_cosmo.py \
|
||||
third_party/python/Lib/test/test_scratch.py \
|
||||
third_party/python/Lib/test/test_complex.py \
|
||||
third_party/python/Lib/test/test_funcattrs.py \
|
||||
|
@ -2561,6 +2563,10 @@ o/$(MODE)/third_party/python/Lib/test/test_kdf.py.runs: \
|
|||
o/$(MODE)/third_party/python/pythontester.com
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_kdf $(PYTESTARGS)
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_cosmo.py.runs: \
|
||||
o/$(MODE)/third_party/python/pythontester.com
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_cosmo $(PYTESTARGS)
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_scratch.py.runs: \
|
||||
o/$(MODE)/third_party/python/pythontester.com
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_scratch $(PYTESTARGS)
|
||||
|
@ -3750,6 +3756,10 @@ o/$(MODE)/third_party/python/Lib/test/test_baseexception.o: PYFLAGS += -Y.python
|
|||
o/$(MODE)/third_party/python/Lib/test/test_cmath.o: PYFLAGS += -Y.python/test/ieee754.txt
|
||||
o/$(MODE)/third_party/python/Lib/test/test_difflib.o: PYFLAGS += -Y.python/test/test_difflib_expect.html
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_cosmo.o: \
|
||||
PYFLAGS += \
|
||||
-Y.python/test/hello.com
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_math.o: \
|
||||
PYFLAGS += \
|
||||
-Y.python/test/ieee754.txt \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue