mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Make numerous improvements
- Python static hello world now 1.8mb - Python static fully loaded now 10mb - Python HTTPS client now uses MbedTLS - Python REPL now completes import stmts - Increase stack size for Python for now - Begin synthesizing posixpath and ntpath - Restore Python \N{UNICODE NAME} support - Restore Python NFKD symbol normalization - Add optimized code path for Intel SHA-NI - Get more Python unit tests passing faster - Get Python help() pagination working on NT - Python hashlib now supports MbedTLS PBKDF2 - Make memcpy/memmove/memcmp/bcmp/etc. faster - Add Mersenne Twister and Vigna to LIBC_RAND - Provide privileged __printf() for error code - Fix zipos opendir() so that it reports ENOTDIR - Add basic chmod() implementation for Windows NT - Add Cosmo's best functions to Python cosmo module - Pin function trace indent depth to that of caller - Show memory diagram on invalid access in MODE=dbg - Differentiate stack overflow on crash in MODE=dbg - Add stb_truetype and tools for analyzing font files - Upgrade to UNICODE 13 and reduce its binary footprint - COMPILE.COM now logs resource usage of build commands - Start implementing basic poll() support on bare metal - Set getauxval(AT_EXECFN) to GetModuleFileName() on NT - Add descriptions to strerror() in non-TINY build modes - Add COUNTBRANCH() macro to help with micro-optimizations - Make error / backtrace / asan / memory code more unbreakable - Add fast perfect C implementation of μ-Law and a-Law audio codecs - Make strtol() functions consistent with other libc implementations - Improve Linenoise implementation (see also github.com/jart/bestline) - COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
parent
fa7b4f5bd1
commit
39bf41f4eb
806 changed files with 77494 additions and 63859 deletions
|
@ -442,22 +442,126 @@ TEST(wcstol, testBase36) {
|
|||
EXPECT_EQ(29234652, wcstol(L"HELLO", 0, 36));
|
||||
}
|
||||
|
||||
BENCH(atoi, bench) {
|
||||
EZBENCH2("atoi", donothing, EXPROPRIATE(atoi(VEIL("r", "123456789"))));
|
||||
EZBENCH2("strtol", donothing,
|
||||
EXPROPRIATE(strtol(VEIL("r", "123456789"), 0, 10)));
|
||||
EZBENCH2("strtoul", donothing,
|
||||
EXPROPRIATE(strtol(VEIL("r", "123456789"), 0, 10)));
|
||||
EZBENCH2("wcstol", donothing,
|
||||
EXPROPRIATE(wcstol(VEIL("r", L"123456789"), 0, 10)));
|
||||
EZBENCH2("wcstoul", donothing,
|
||||
EXPROPRIATE(wcstol(VEIL("r", L"123456789"), 0, 10)));
|
||||
EZBENCH2("strtoimax", donothing,
|
||||
EXPROPRIATE(strtoimax(VEIL("r", "123456789"), 0, 10)));
|
||||
EZBENCH2("strtoumax", donothing,
|
||||
EXPROPRIATE(strtoimax(VEIL("r", "123456789"), 0, 10)));
|
||||
EZBENCH2("wcstoimax", donothing,
|
||||
EXPROPRIATE(wcstoimax(VEIL("r", L"123456789"), 0, 10)));
|
||||
EZBENCH2("wcstoumax", donothing,
|
||||
EXPROPRIATE(wcstoimax(VEIL("r", L"123456789"), 0, 10)));
|
||||
TEST(strtol, testWormsMeat) {
|
||||
ASSERT_EQ(0x4e00, strtol("0x4e00", 0, 0));
|
||||
}
|
||||
|
||||
TEST(strtol, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtol("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtol("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtol("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(strtoul, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtoul("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtoul("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtoul("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(strtoll, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtoll("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtoll("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtoll("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(strtoull, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtoull("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtoull("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtoull("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(strtoimax, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtoimax("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtoimax("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtoimax("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(strtoumax, testIBM) {
|
||||
char *e;
|
||||
ASSERT_EQ(1, strtoumax("1e-", &e, 10));
|
||||
ASSERT_STREQ("e-", e);
|
||||
ASSERT_EQ(0, strtoumax("-", &e, 10));
|
||||
ASSERT_STREQ("-", e);
|
||||
ASSERT_EQ(0, strtoumax("0f", &e, 10));
|
||||
ASSERT_STREQ("f", e);
|
||||
}
|
||||
|
||||
TEST(wcstol, testIBM) {
|
||||
wchar_t *e;
|
||||
ASSERT_EQ(1, wcstol(L"1e-", &e, 10));
|
||||
ASSERT_STREQ(L"e-", e);
|
||||
ASSERT_EQ(0, wcstol(L"-", &e, 10));
|
||||
ASSERT_STREQ(L"-", e);
|
||||
ASSERT_EQ(0, wcstol(L"0f", &e, 10));
|
||||
ASSERT_STREQ(L"f", e);
|
||||
}
|
||||
|
||||
TEST(wcstoul, testIBM) {
|
||||
wchar_t *e;
|
||||
ASSERT_EQ(1, wcstoul(L"1e-", &e, 10));
|
||||
ASSERT_STREQ(L"e-", e);
|
||||
ASSERT_EQ(0, wcstoul(L"-", &e, 10));
|
||||
ASSERT_STREQ(L"-", e);
|
||||
ASSERT_EQ(0, wcstoul(L"0f", &e, 10));
|
||||
ASSERT_STREQ(L"f", e);
|
||||
}
|
||||
|
||||
TEST(wcstoimax, testIBM) {
|
||||
wchar_t *e;
|
||||
ASSERT_EQ(1, wcstoimax(L"1e-", &e, 10));
|
||||
ASSERT_STREQ(L"e-", e);
|
||||
ASSERT_EQ(0, wcstoimax(L"-", &e, 10));
|
||||
ASSERT_STREQ(L"-", e);
|
||||
ASSERT_EQ(0, wcstoimax(L"0f", &e, 10));
|
||||
ASSERT_STREQ(L"f", e);
|
||||
}
|
||||
|
||||
TEST(wcstoumax, testIBM) {
|
||||
wchar_t *e;
|
||||
ASSERT_EQ(1, wcstoumax(L"1e-", &e, 10));
|
||||
ASSERT_STREQ(L"e-", e);
|
||||
ASSERT_EQ(0, wcstoumax(L"-", &e, 10));
|
||||
ASSERT_STREQ(L"-", e);
|
||||
ASSERT_EQ(0, wcstoumax(L"0f", &e, 10));
|
||||
ASSERT_STREQ(L"f", e);
|
||||
}
|
||||
|
||||
BENCH(atoi, bench) {
|
||||
EZBENCH2("atoi 10⁸", donothing, EXPROPRIATE(atoi(VEIL("r", "100000000"))));
|
||||
EZBENCH2("strtol 10⁸", donothing,
|
||||
EXPROPRIATE(strtol(VEIL("r", "100000000"), 0, 10)));
|
||||
EZBENCH2("strtoul 10⁸", donothing,
|
||||
EXPROPRIATE(strtol(VEIL("r", "100000000"), 0, 10)));
|
||||
EZBENCH2("wcstol 10⁸", donothing,
|
||||
EXPROPRIATE(wcstol(VEIL("r", L"100000000"), 0, 10)));
|
||||
EZBENCH2("wcstoul 10⁸", donothing,
|
||||
EXPROPRIATE(wcstol(VEIL("r", L"100000000"), 0, 10)));
|
||||
EZBENCH2("strtoimax 10⁸", donothing,
|
||||
EXPROPRIATE(strtoimax(VEIL("r", "100000000"), 0, 10)));
|
||||
EZBENCH2("strtoumax 10⁸", donothing,
|
||||
EXPROPRIATE(strtoimax(VEIL("r", "100000000"), 0, 10)));
|
||||
EZBENCH2("wcstoimax 10⁸", donothing,
|
||||
EXPROPRIATE(wcstoimax(VEIL("r", L"100000000"), 0, 10)));
|
||||
EZBENCH2("wcstoumax 10⁸", donothing,
|
||||
EXPROPRIATE(wcstoimax(VEIL("r", L"100000000"), 0, 10)));
|
||||
}
|
||||
|
|
83
test/libc/fmt/formatint64thousands_test.c
Normal file
83
test/libc/fmt/formatint64thousands_test.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(FormatUint64Thousands, test) {
|
||||
char s[27];
|
||||
EXPECT_EQ(s + 1, FormatUint64Thousands(s, 0));
|
||||
EXPECT_STREQ("0", s);
|
||||
EXPECT_EQ(s + 1, FormatUint64Thousands(s, 1));
|
||||
EXPECT_STREQ("1", s);
|
||||
EXPECT_EQ(s + 3, FormatUint64Thousands(s, 999));
|
||||
EXPECT_STREQ("999", s);
|
||||
EXPECT_EQ(s + 5, FormatUint64Thousands(s, 1000));
|
||||
EXPECT_STREQ("1,000", s);
|
||||
EXPECT_EQ(s + 7, FormatUint64Thousands(s, 999999));
|
||||
EXPECT_STREQ("999,999", s);
|
||||
EXPECT_EQ(s + 9, FormatUint64Thousands(s, 1000000));
|
||||
EXPECT_STREQ("1,000,000", s);
|
||||
EXPECT_EQ(s + 7, FormatUint64Thousands(s, 104040));
|
||||
EXPECT_STREQ("104,040", s);
|
||||
}
|
||||
|
||||
TEST(FormatInt64Thousands, testPositive) {
|
||||
char s[27];
|
||||
EXPECT_EQ(s + 1, FormatInt64Thousands(s, 0));
|
||||
EXPECT_STREQ("0", s);
|
||||
EXPECT_EQ(s + 1, FormatInt64Thousands(s, 1));
|
||||
EXPECT_STREQ("1", s);
|
||||
EXPECT_EQ(s + 3, FormatInt64Thousands(s, 999));
|
||||
EXPECT_STREQ("999", s);
|
||||
EXPECT_EQ(s + 5, FormatInt64Thousands(s, 1000));
|
||||
EXPECT_STREQ("1,000", s);
|
||||
EXPECT_EQ(s + 7, FormatInt64Thousands(s, 999999));
|
||||
EXPECT_STREQ("999,999", s);
|
||||
EXPECT_EQ(s + 9, FormatInt64Thousands(s, 1000000));
|
||||
EXPECT_STREQ("1,000,000", s);
|
||||
}
|
||||
|
||||
TEST(FormatInt64Thousands, testNegative) {
|
||||
char s[27];
|
||||
EXPECT_EQ(s + 2, FormatInt64Thousands(s, -1));
|
||||
EXPECT_STREQ("-1", s);
|
||||
EXPECT_EQ(s + 4, FormatInt64Thousands(s, -999));
|
||||
EXPECT_STREQ("-999", s);
|
||||
EXPECT_EQ(s + 6, FormatInt64Thousands(s, -1000));
|
||||
EXPECT_STREQ("-1,000", s);
|
||||
EXPECT_EQ(s + 8, FormatInt64Thousands(s, -999999));
|
||||
EXPECT_STREQ("-999,999", s);
|
||||
EXPECT_EQ(s + 10, FormatInt64Thousands(s, -1000000));
|
||||
EXPECT_STREQ("-1,000,000", s);
|
||||
}
|
||||
|
||||
BENCH(FormatInt64Thousands, bench) {
|
||||
char s[27];
|
||||
EZBENCH2("int64toarray_radix10(MAX)", donothing,
|
||||
int64toarray_radix10(INT64_MAX, s));
|
||||
EZBENCH2("FormatInt64Thousands(MAX)", donothing,
|
||||
FormatInt64Thousands(s, INT64_MAX));
|
||||
EZBENCH2("FormatInt64Thousands(MIN)", donothing,
|
||||
FormatInt64Thousands(s, INT64_MIN));
|
||||
EZBENCH2("FormatUint64Thousands(MIN)", donothing,
|
||||
FormatUint64Thousands(s, UINT64_MAX));
|
||||
}
|
|
@ -30,26 +30,55 @@
|
|||
*/
|
||||
|
||||
TEST(strerror, e2big) {
|
||||
EXPECT_STARTSWITH("E2BIG", strerror(E2BIG));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("E2BIG", strerror(E2BIG));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("E2BIG[Arg list too long]", strerror(E2BIG));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strerror, enosys) {
|
||||
EXPECT_STARTSWITH("ENOSYS", strerror(ENOSYS));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("ENOSYS", strerror(ENOSYS));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("ENOSYS[Function not implemented]", strerror(ENOSYS));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strerror, einval) {
|
||||
EXPECT_STARTSWITH("EINVAL", strerror(EINVAL));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("EINVAL", strerror(EINVAL));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("EINVAL[Invalid argument]", strerror(EINVAL));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strerror, symbolizingTheseNumbersAsErrorsIsHeresyInUnixStyle) {
|
||||
EXPECT_STARTSWITH("EUNKNOWN", strerror(0));
|
||||
EXPECT_STARTSWITH("EUNKNOWN", strerror(-1));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("EUNKNOWN", strerror(0));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("EUNKNOWN[No error information]", strerror(0));
|
||||
}
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("EUNKNOWN", strerror(-1));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("EUNKNOWN[No error information]", strerror(-1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strerror, enotconn_orLinkerIsntUsingLocaleC_orCodeIsOutOfSync) {
|
||||
EXPECT_STARTSWITH("ENOTCONN", strerror(ENOTCONN));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("ENOTCONN", strerror(ENOTCONN));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("ENOTCONN[Transport endpoint is not connected]",
|
||||
strerror(ENOTCONN));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strerror, exfull_orLinkerIsntUsingLocaleC_orCodeIsOutOfSync) {
|
||||
EXPECT_STARTSWITH("ETXTBSY", strerror(ETXTBSY));
|
||||
if (IsTiny()) {
|
||||
EXPECT_STARTSWITH("ETXTBSY", strerror(ETXTBSY));
|
||||
} else {
|
||||
EXPECT_STARTSWITH("ETXTBSY[Text file busy]", strerror(ETXTBSY));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue