Add MODE=optlinux build mode (#141)

This commit is contained in:
Justine Tunney 2021-10-14 19:36:49 -07:00
parent 226aaf3547
commit 67b5200a0b
111 changed files with 934 additions and 854 deletions

View file

@ -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):

View file

@ -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))

View file

@ -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

Binary file not shown.

View 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()

View file

@ -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")],
""),

View file

@ -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);

View file

@ -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);

View file

@ -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.

View file

@ -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);
}

View file

@ -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 \