Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -20,7 +20,7 @@
------------------------------------------------------------------ */
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "third_party/bzip2/bzlib_private.inc"

View file

@ -4,8 +4,9 @@
#include "libc/calls/struct/stat.macros.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"

View file

@ -20,7 +20,7 @@
------------------------------------------------------------------ */
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "third_party/bzip2/bzlib_private.inc"

View file

@ -16,17 +16,17 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/intrin/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/def.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/popcnt.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
@ -34,6 +34,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/file.h"
#include "third_party/gdtoa/gdtoa.h"
#include "tool/build/lib/elfwriter.h"
@ -479,11 +480,11 @@ static void ReadFlags(struct As *a, int argc, char *argv[]) {
for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-o")) {
a->outpath = StrDup(a, argv[++i]);
} else if (startswith(argv[i], "-o")) {
} else if (_startswith(argv[i], "-o")) {
a->outpath = StrDup(a, argv[i] + 2);
} else if (!strcmp(argv[i], "-I")) {
SaveString(&a->incpaths, strdup(argv[++i]));
} else if (startswith(argv[i], "-I")) {
} else if (_startswith(argv[i], "-I")) {
SaveString(&a->incpaths, strdup(argv[i] + 2));
} else if (!strcmp(argv[i], "-Z")) {
a->inhibiterr = true;
@ -1667,13 +1668,13 @@ static int GrabSection(struct As *a, int name, int flags, int type, int group,
static void OnSection(struct As *a, struct Slice s) {
int name, flags, type, group = -1, comdat = -1;
name = SliceDup(a, GetSlice(a));
if (startswith(a->strings.p[name], ".text")) {
if (_startswith(a->strings.p[name], ".text")) {
flags = SHF_ALLOC | SHF_EXECINSTR;
type = SHT_PROGBITS;
} else if (startswith(a->strings.p[name], ".data")) {
} else if (_startswith(a->strings.p[name], ".data")) {
flags = SHF_ALLOC | SHF_WRITE;
type = SHT_PROGBITS;
} else if (startswith(a->strings.p[name], ".bss")) {
} else if (_startswith(a->strings.p[name], ".bss")) {
flags = SHF_ALLOC | SHF_WRITE;
type = SHT_NOBITS;
} else {
@ -2025,7 +2026,7 @@ static int ParseModrm(struct As *a, int *disp) {
if (((reg & 070) >> 3) == 2) modrm |= HASASZ; // asz
if (IsComma(a)) {
++a->i;
modrm |= (bsr(GetInt(a)) & 3) << 6;
modrm |= (_bsr(GetInt(a)) & 3) << 6;
}
}
ConsumePunct(a, ')');
@ -2607,8 +2608,8 @@ static bool HasXmmOnLine(struct As *a) {
int i;
for (i = 0; !IsPunct(a, a->i + i, ';'); ++i) {
if (IsSlice(a, a->i + i) && a->slices.p[a->things.p[a->i + i].i].n >= 4 &&
(startswith(a->slices.p[a->things.p[a->i + i].i].p, "xmm") ||
startswith(a->slices.p[a->things.p[a->i + i].i].p, "%xmm"))) {
(_startswith(a->slices.p[a->things.p[a->i + i].i].p, "xmm") ||
_startswith(a->slices.p[a->things.p[a->i + i].i].p, "%xmm"))) {
return true;
}
}

View file

@ -16,6 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bsf.h"
#include "libc/intrin/bsr.h"
#include "third_party/chibicc/chibicc.h"
#define PRECIOUS 0b1111000000101000 // bx,bp,r12-r15
@ -299,7 +301,7 @@ static void PickAsmRegisters(Asm *a) {
if (!(m = a->ops[i].regmask)) break;
if (popcnt(m) != j) break;
if (!(m &= regset)) CouldNotAllocateRegister(&a->ops[i], "rm");
pick = 1 << (a->ops[i].reg = bsf(m));
pick = 1 << (a->ops[i].reg = _bsf(m));
if (pick & PRECIOUS) a->regclob |= pick;
regset &= ~pick;
a->ops[i].regmask = 0;
@ -307,14 +309,14 @@ static void PickAsmRegisters(Asm *a) {
case kAsmXmm:
if (!(m = a->ops[i].regmask)) break;
if (!(m &= xmmset)) CouldNotAllocateRegister(&a->ops[i], "xmm");
xmmset &= ~(1 << (a->ops[i].reg = bsf(m)));
xmmset &= ~(1 << (a->ops[i].reg = _bsf(m)));
a->ops[i].regmask = 0;
break;
case kAsmFpu:
if (!(m = a->ops[i].x87mask)) break;
if (popcnt(m) != j) break;
if (!(m &= x87sts)) CouldNotAllocateRegister(&a->ops[i], "fpu");
x87sts &= ~(1 << (a->ops[i].reg = bsf(m)));
x87sts &= ~(1 << (a->ops[i].reg = _bsf(m)));
a->ops[i].x87mask = 0;
break;
default:
@ -368,7 +370,7 @@ static Token *ParseAsmClobbers(Asm *a, Token *tok) {
a->flagclob = true;
} else if ((i = GetIndexOfRegisterName(s)) != -1) {
a->regclob |= 1 << i;
} else if (startswith(s, "xmm") && isdigit(s[3]) &&
} else if (_startswith(s, "xmm") && isdigit(s[3]) &&
(!s[4] || isdigit(s[4]))) {
i = s[3] - '0';
if (s[4]) {
@ -379,7 +381,7 @@ static Token *ParseAsmClobbers(Asm *a, Token *tok) {
a->xmmclob |= 1 << i;
} else if (!strcmp(s, "st")) {
a->x87clob |= 1;
} else if (startswith(s, "st(") && isdigit(s[3]) && s[4] == ')') {
} else if (_startswith(s, "st(") && isdigit(s[3]) && s[4] == ')') {
i = s[3] - '0';
i &= 7;
a->x87clob |= 1 << i;
@ -538,7 +540,7 @@ static char *HandleAsmSpecifier(Asm *a, char *p) {
if ((i = c - '0') >= a->n) {
error_tok(a->tok, "bad asm reference at offset %d", p - a->str);
}
z = bsr(a->ops[i].node->ty->size);
z = _bsr(a->ops[i].node->ty->size);
if (z > 3 && a->ops[i].type == kAsmReg) {
error_tok(a->tok, "bad asm op size");
}
@ -677,7 +679,7 @@ static void StoreAsmOutputs(Asm *a) {
println("\tset%s\t(%%rax)", a->ops[i].str + a->ops[i].predicate);
break;
case kAsmReg:
z = bsr(a->ops[i].node->ty->size);
z = _bsr(a->ops[i].node->ty->size);
if (a->ops[i].reg) {
gen_addr(a->ops[i].node);
if (z > 3) error_tok(a->tok, "bad asm out size");
@ -732,7 +734,7 @@ static void StoreAsmOutputs(Asm *a) {
static void PushClobbers(Asm *a) {
int i, regs = a->regclob & PRECIOUS;
while (regs) {
i = bsf(regs);
i = _bsf(regs);
pushreg(kGreg[3][i]);
regs &= ~(1 << i);
}
@ -741,7 +743,7 @@ static void PushClobbers(Asm *a) {
static void PopClobbers(Asm *a) {
int i, regs = a->regclob & PRECIOUS;
while (regs) {
i = bsr(regs);
i = _bsr(regs);
popreg(kGreg[3][i]);
regs &= ~(1 << i);
}

View file

@ -1,9 +1,11 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/x/x.h"
#include "libc/sysv/consts/sig.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
asm(".ident\t\"\\n\\n\
@ -215,7 +217,7 @@ static void parse_args(int argc, char **argv) {
atexit(PrintMemoryUsage);
} else if (!strcmp(argv[i], "-o")) {
opt_o = argv[++i];
} else if (startswith(argv[i], "-o")) {
} else if (_startswith(argv[i], "-o")) {
opt_o = argv[i] + 2;
} else if (!strcmp(argv[i], "-S")) {
opt_S = true;
@ -239,19 +241,19 @@ static void parse_args(int argc, char **argv) {
opt_P = true;
} else if (!strcmp(argv[i], "-I")) {
strarray_push(&include_paths, argv[++i]);
} else if (startswith(argv[i], "-I")) {
} else if (_startswith(argv[i], "-I")) {
strarray_push(&include_paths, argv[i] + 2);
} else if (!strcmp(argv[i], "-iquote")) {
strarray_push(&include_paths, argv[++i]);
} else if (startswith(argv[i], "-iquote")) {
} else if (_startswith(argv[i], "-iquote")) {
strarray_push(&include_paths, argv[i] + strlen("-iquote"));
} else if (!strcmp(argv[i], "-isystem")) {
strarray_push(&include_paths, argv[++i]);
} else if (startswith(argv[i], "-isystem")) {
} else if (_startswith(argv[i], "-isystem")) {
strarray_push(&include_paths, argv[i] + strlen("-isystem"));
} else if (!strcmp(argv[i], "-D")) {
define(argv[++i]);
} else if (startswith(argv[i], "-D")) {
} else if (_startswith(argv[i], "-D")) {
define(argv[i] + 2);
} else if (!strcmp(argv[i], "-U")) {
undef_macro(argv[++i]);
@ -263,9 +265,9 @@ static void parse_args(int argc, char **argv) {
opt_x = parse_opt_x(argv[++i]);
} else if (!strncmp(argv[i], "-x", 2)) {
opt_x = parse_opt_x(argv[i] + 2);
} else if (startswith(argv[i], "-Wa")) {
} else if (_startswith(argv[i], "-Wa")) {
strarray_push_comma(&as_extra_args, argv[i] + 3);
} else if (startswith(argv[i], "-Wl")) {
} else if (_startswith(argv[i], "-Wl")) {
strarray_push_comma(&ld_extra_args, argv[i] + 3);
} else if (!strcmp(argv[i], "-Xassembler")) {
strarray_push(&as_extra_args, argv[++i]);
@ -333,7 +335,7 @@ static void parse_args(int argc, char **argv) {
} else if (!strcmp(argv[i], "-L")) {
strarray_push(&ld_extra_args, "-L");
strarray_push(&ld_extra_args, argv[++i]);
} else if (startswith(argv[i], "-L")) {
} else if (_startswith(argv[i], "-L")) {
strarray_push(&ld_extra_args, "-L");
strarray_push(&ld_extra_args, argv[i] + 2);
} else {
@ -560,11 +562,11 @@ static Token *append_tokens(Token *tok1, Token *tok2) {
static FileType get_file_type(const char *filename) {
if (opt_x != FILE_NONE) return opt_x;
if (endswith(filename, ".a")) return FILE_AR;
if (endswith(filename, ".o")) return FILE_OBJ;
if (endswith(filename, ".c")) return FILE_C;
if (endswith(filename, ".s")) return FILE_ASM;
if (endswith(filename, ".S")) return FILE_ASM_CPP;
if (_endswith(filename, ".a")) return FILE_AR;
if (_endswith(filename, ".o")) return FILE_OBJ;
if (_endswith(filename, ".c")) return FILE_C;
if (_endswith(filename, ".s")) return FILE_ASM;
if (_endswith(filename, ".S")) return FILE_ASM_CPP;
error("<command line>: unknown file extension: %s", filename);
}

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_CHIBICC_CHIBICC_H_
#define COSMOPOLITAN_THIRD_PARTY_CHIBICC_CHIBICC_H_
#include "libc/assert.h"
#include "libc/intrin/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/weirdtypes.h"
@ -9,21 +8,20 @@
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/popcnt.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/str/unicode.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h"
#include "libc/str/unicode.h"
#include "libc/x/x.h"
#include "third_party/gdtoa/gdtoa.h"
#include "tool/build/lib/javadown.h"

View file

@ -1,3 +1,4 @@
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
#define GP_MAX 6
@ -984,7 +985,7 @@ static bool gen_builtin_funcall(Node *node, const char *name) {
char regprefix;
gen_expr(node->args);
emitlin("\tor\t$-1,%edi");
regprefix = endswith(name, "l") ? 'r' : 'e';
regprefix = _endswith(name, "l") ? 'r' : 'e';
println("\tbsf\t%%%cax,%%%cax", regprefix, regprefix);
emitlin("\tcmovz\t%edi,%eax");
emitlin("\tinc\t%eax");
@ -1432,7 +1433,7 @@ void gen_expr(Node *node) {
case ND_FUNCALL: {
const char *funcname = NULL;
if (node->lhs->kind == ND_VAR) {
if (startswith(nameof(node->lhs->var), "__builtin_")) {
if (_startswith(nameof(node->lhs->var), "__builtin_")) {
funcname = nameof(node->lhs->var) + 10;
if (gen_builtin_funcall(node, funcname)) {
return;

View file

@ -16,10 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
#include "tool/build/lib/asmdown.h"
@ -107,15 +108,15 @@ static char *DescribeType(struct Type *ty) {
case TY_LDOUBLE:
return DescribeScalar(ty, "long double");
case TY_FUNC:
return xasprintf("%s(*)()", gc(DescribeType(ty->return_ty)));
return xasprintf("%s(*)()", _gc(DescribeType(ty->return_ty)));
case TY_PTR:
if (ty->base->kind == TY_FUNC) {
return DescribeType(ty->base);
} else {
return xasprintf("%s*", gc(DescribeType(ty->base)));
return xasprintf("%s*", _gc(DescribeType(ty->base)));
}
case TY_ARRAY:
return xasprintf("%s[%d]", gc(DescribeType(ty->base)), ty->array_len);
return xasprintf("%s[%d]", _gc(DescribeType(ty->base)), ty->array_len);
case TY_ENUM:
if (ty->name) {
return xasprintf("enum %.*s", ty->name->len, ty->name->loc);
@ -283,7 +284,7 @@ static void LoadPublicDefinitions(struct DoxWriter *dox, Obj *prog) {
if (!obj->javadown) {
if (*obj->name == '_') continue;
if (strchr(obj->name, '$')) continue;
if (startswith(obj->name, "__gdtoa_")) continue;
if (_startswith(obj->name, "__gdtoa_")) continue;
if (obj->visibility && !strcmp(obj->visibility, "hidden")) continue;
if (!obj->is_definition && (!obj->is_function || !obj->params ||
!obj->params->name || !*obj->params->name)) {
@ -292,7 +293,7 @@ static void LoadPublicDefinitions(struct DoxWriter *dox, Obj *prog) {
}
if (obj->is_static) continue;
if (obj->is_string_literal) continue;
if (obj->section && startswith(obj->section, ".init_array")) continue;
if (obj->section && _startswith(obj->section, ".init_array")) continue;
APPEND(dox->objects);
dox->objects.p[dox->objects.n - 1] = obj;
}

View file

@ -16,11 +16,12 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/intrin/bits.h"
#include "libc/mem/alg.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
#define APPEND(L) L.p = realloc(L.p, ++L.n * sizeof(*L.p))
@ -282,7 +283,7 @@ static int CompareDoxIndexEntry(const void *p1, const void *p2, void *arg) {
static void IndexDox(struct Dox *dox) {
size_t i, j, n;
dox->names.n = roundup2pow(dox->objects.n + dox->macros.n) << 1;
dox->names.n = _roundup2pow(dox->objects.n + dox->macros.n) << 1;
dox->names.p = calloc(dox->names.n, sizeof(*dox->names.p));
n = 0;
for (i = 0; i < dox->objects.n; ++i) {
@ -773,7 +774,7 @@ document.addEventListener('DOMContentLoaded', function () {\n\
prefix = xasprintf("%s ", o->params.p[j].name);
for (k = 0; k < o->javadown->tags.n; ++k) {
if (!strcmp(o->javadown->tags.p[k].tag, "param") &&
startswith(o->javadown->tags.p[k].text, prefix)) {
_startswith(o->javadown->tags.p[k].text, prefix)) {
fprintf(f, "<dd>");
PrintText(f, o->javadown->tags.p[k].text + strlen(prefix));
fprintf(f, "\n");
@ -907,7 +908,7 @@ document.addEventListener('DOMContentLoaded', function () {\n\
prefix = xasprintf("%s ", m->params.p[j].name);
for (k = 0; k < m->javadown->tags.n; ++k) {
if (!strcmp(m->javadown->tags.p[k].tag, "param") &&
startswith(m->javadown->tags.p[k].text, prefix)) {
_startswith(m->javadown->tags.p[k].text, prefix)) {
fprintf(f, "<dd>");
PrintText(f, m->javadown->tags.p[k].text + strlen(prefix));
fprintf(f, "\n");

View file

@ -1,3 +1,4 @@
#include "libc/intrin/bsf.h"
#include "third_party/chibicc/chibicc.h"
// Slurps contents of file.
@ -66,7 +67,7 @@ void canonicalize_newline(char *p) {
p += 16;
q += 16;
} else {
m = bsf(m);
m = _bsf(m);
memmove(q, p, m);
p += m;
q += m;
@ -125,7 +126,7 @@ void remove_backslash_newline(char *p) {
i += 16;
j += 16;
} else {
m = bsf(m);
m = _bsf(m);
memmove(p + j, p + i, m);
i += m;
j += m;

View file

@ -23,6 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/ffs.h"
#include "libc/testlib/testlib.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
#include "third_party/chibicc/kw.h"

View file

@ -26,6 +26,7 @@
#include "libc/mem/arena.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
#include "third_party/chibicc/kw.h"

View file

@ -16,14 +16,14 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/log/libfatal.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/chibicc.h"
static void AppendStringLiteral(char **b, const char *s, const char *indent) {
@ -537,7 +537,7 @@ const struct _inittab _PyImport_Inittab_%s = {\n\
};\n\
",
module, module,
tok->file->javadown ? gc(xasprintf("pb_%s_doc", module)) : "0",
tok->file->javadown ? _gc(xasprintf("pb_%s_doc", module)) : "0",
module, module, module, module, module, module);
CHECK_NE(-1, (fd = creat(path, 0644)));
CHECK_NE(-1, xwrite(fd, b, appendz(b).i));

View file

@ -1,5 +1,5 @@
#include "libc/intrin/bsf.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/chibicc/chibicc.h"
@ -679,7 +679,7 @@ static void convert_universal_chars(char *p) {
p += 16;
q += 16;
} else {
m = bsf(m);
m = _bsf(m);
memmove(q, p, m);
p += m;
q += m;

View file

@ -2,11 +2,11 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/weaken.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
@ -696,8 +696,8 @@ void* dlmalloc(size_t bytes) {
mem = sys_alloc(gm, nb);
POSTACTION(gm);
if (mem == MAP_FAILED && weaken(__oom_hook)) {
weaken(__oom_hook)(bytes);
if (mem == MAP_FAILED && _weaken(__oom_hook)) {
_weaken(__oom_hook)(bytes);
}
return mem;
@ -919,7 +919,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
alignment = MIN_CHUNK_SIZE;
/* alignment is 32+ bytes rounded up to nearest two power */
alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
alignment = 2ul << _bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
if (bytes >= MAX_REQUEST - alignment) {
if (m != 0) { /* Test isn't needed but avoids compiler warning */
MALLOC_FAILURE_ACTION;

View file

@ -49,12 +49,15 @@ $(THIRD_PARTY_DLMALLOC_A).pkg: \
$(THIRD_PARTY_DLMALLOC_A_OBJS) \
$(foreach x,$(THIRD_PARTY_DLMALLOC_A_DIRECTDEPS),$($(x)_A).pkg)
ifneq ($(MODE),tiny)
ifneq ($(MODE),tinylinux)
# README file recommends -O3
# It does double performance in default mode
o//third_party/dlmalloc/dlmalloc.o \
o/rel/third_party/dlmalloc/dlmalloc.o: private \
o/$(MODE)/third_party/dlmalloc/dlmalloc.o: private \
OVERRIDE_CFLAGS += \
-O3
endif
endif
# we can't use address sanitizer because:
# address sanitizer depends on dlmalloc

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/weaken.h"
#include "libc/calls/calls.h"
#include "libc/intrin/weaken.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -26,6 +26,6 @@
void dlmalloc_abort(void) {
write(2, MESSAGE, strlen(MESSAGE));
if (weaken(__die)) weaken(__die)();
if (_weaken(__die)) _weaken(__die)();
_Exit(44);
}

View file

@ -1,5 +1,8 @@
// clang-format off
#include "third_party/nsync/mu.h"
#include "libc/atomic.h"
#include "libc/intrin/atomic.h"
#include "libc/calls/calls.h"
#include "libc/thread/tls.h"
/* --------------------------- Lock preliminaries ------------------------ */
@ -32,12 +35,40 @@
*/
static int malloc_lock(atomic_int *lk) {
if (!__threaded) return 0;
while (atomic_exchange_explicit(lk, 1, memory_order_acquire)) {
sched_yield();
}
return 0;
}
static int malloc_trylock(atomic_int *lk) {
if (!__threaded) return 1;
return !atomic_exchange_explicit(lk, 1, memory_order_acquire);
}
static inline int malloc_unlock(atomic_int *lk) {
atomic_store_explicit(lk, 0, memory_order_release);
return 0;
}
#if !USE_LOCKS
#define USE_LOCK_BIT (0U)
#define INITIAL_LOCK(l) (0)
#define DESTROY_LOCK(l) (0)
#define ACQUIRE_MALLOC_GLOBAL_LOCK()
#define RELEASE_MALLOC_GLOBAL_LOCK()
#elif defined(TINY)
#define MLOCK_T atomic_int
#define ACQUIRE_LOCK(lk) malloc_lock(lk)
#define RELEASE_LOCK(lk) malloc_unlock(lk)
#define TRY_LOCK(lk) malloc_trylock(lk)
#define INITIAL_LOCK(lk) (*lk = 0, 0)
#define DESTROY_LOCK(lk)
#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex);
#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex);
static MLOCK_T malloc_global_mutex;
#else
#define MLOCK_T nsync_mu
#define ACQUIRE_LOCK(lk) (__threaded && (nsync_mu_lock(lk), 0))

View file

@ -208,8 +208,8 @@ void* mspace_malloc(mspace msp, size_t bytes) {
mem = sys_alloc(ms, nb);
POSTACTION(ms);
if (mem == MAP_FAILED && weaken(__oom_hook)) {
weaken(__oom_hook)(bytes);
if (mem == MAP_FAILED && _weaken(__oom_hook)) {
_weaken(__oom_hook)(bytes);
}
return mem;

View file

@ -124,12 +124,9 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "libc/mem/alg.h"
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/sig.internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/termios.h"
@ -139,21 +136,25 @@
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/tpenc.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/nt/version.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "libc/str/unicode.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
@ -164,7 +165,6 @@
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.h"
#include "libc/str/unicode.h"
#include "net/http/escape.h"
#include "third_party/linenoise/linenoise.h"
#include "tool/build/lib/case.h"
@ -368,7 +368,7 @@ static wint_t Capitalize(wint_t c) {
static struct rune DecodeUtf8(int c) {
struct rune r;
if (c < 252) {
r.n = bsr(255 & ~c);
r.n = _bsr(255 & ~c);
r.c = c & (((1 << r.n) - 1) | 3);
r.n = 6 - r.n;
} else {
@ -644,7 +644,7 @@ static void abAppendw(struct abuf *a, unsigned long long w) {
p[5] = (0x0000ff0000000000 & w) >> 050;
p[6] = (0x00ff000000000000 & w) >> 060;
p[7] = (0xff00000000000000 & w) >> 070;
a->len += w ? (bsrll(w) >> 3) + 1 : 1;
a->len += w ? (_bsrll(w) >> 3) + 1 : 1;
p[8] = 0;
}
@ -1221,7 +1221,7 @@ StartOver:
} else {
flipit = hasflip && (i == flip[0] || i == flip[1]);
if (flipit) abAppendw(&ab, READ32LE("\e[1m"));
abAppendw(&ab, tpenc(rune.c));
abAppendw(&ab, _tpenc(rune.c));
if (flipit) abAppendw(&ab, READ64LE("\e[22m\0\0"));
}
t = wcwidth(rune.c);
@ -1470,7 +1470,7 @@ static void linenoiseEditXlatWord(struct linenoiseState *l,
r = GetUtf8(l->buf + j, l->len - j);
if (iswseparator(r.c)) break;
if ((c = xlat(r.c)) != r.c) {
abAppendw(&ab, tpenc(c));
abAppendw(&ab, _tpenc(c));
} else { /* avoid canonicalization */
abAppend(&ab, l->buf + j, r.n);
}
@ -1634,7 +1634,7 @@ static size_t linenoiseEscape(char *d, const char *s, size_t n) {
break;
}
WRITE32LE(p, w);
p += (bsr(w) >> 3) + 1;
p += (_bsr(w) >> 3) + 1;
l = w;
}
return p - d;
@ -1724,7 +1724,7 @@ static void linenoiseEditBarf(struct linenoiseState *l) {
/* now move the text */
r = GetUtf8(l->buf + end, l->len - end);
memmove(l->buf + pos + r.n, l->buf + pos, end - pos);
w = tpenc(r.c);
w = _tpenc(r.c);
for (i = 0; i < r.n; ++i) {
l->buf[pos + i] = w;
w >>= 8;
@ -2238,7 +2238,7 @@ ssize_t linenoiseEdit(struct linenoiseState *l, const char *prompt, char **obuf,
uint64_t w;
struct rune rune;
rune = GetUtf8(seq, rc);
w = tpenc(xlatCallback(rune.c));
w = _tpenc(xlatCallback(rune.c));
rc = 0;
do {
seq[rc++] = w;
@ -2383,7 +2383,7 @@ char *linenoiseGetHistoryPath(const char *prog) {
if (*a) {
abAppends(&path, a);
abAppends(&path, b);
if (!endswith(path.b, "/") && !endswith(path.b, "\\")) {
if (!_endswith(path.b, "/") && !_endswith(path.b, "\\")) {
abAppendw(&path, '/');
}
}

View file

@ -29,7 +29,7 @@
#define LUA_CORE
#include "libc/intrin/weaken.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -153,9 +153,8 @@ l_noret luaD_throw (lua_State *L, int errcode) {
lua_unlock(L);
g->panic(L); /* call panic function (last chance to jump out) */
}
if (weaken(__die)) weaken(__die)();
__restorewintty();
_Exit(41);
if (_weaken(__die)) _weaken(__die)();
_Exitr(41);
}
}
}

View file

@ -1,7 +1,7 @@
#ifndef lobject_h
#define lobject_h
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "third_party/lua/llimits.h"
#include "third_party/lua/lua.h"
@ -786,7 +786,7 @@ LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);
** Computes ceil(log2(x))
*/
static inline int luaO_ceillog2 (unsigned int x) {
return --x ? bsr(x) + 1 : 0;
return --x ? _bsr(x) + 1 : 0;
}
#endif

View file

@ -26,20 +26,20 @@
*/
#define lua_c
#include "libc/mem/alg.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/errno.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/thread/thread.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#include "libc/thread/thread.h"
#include "third_party/linenoise/linenoise.h"
#include "third_party/lua/cosmo.h"
#include "third_party/lua/lauxlib.h"
@ -148,7 +148,7 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) {
while (lua_next(L, -2)) {
if (lua_type(L, -2) == LUA_TSTRING) {
name = lua_tolstring(L, -2, &n);
if (startswithi(name, a) && (s = malloc(a - p + n + 1))) {
if (_startswithi(name, a) && (s = malloc(a - p + n + 1))) {
memcpy(s, p, a - p);
memcpy(s + (a - p), name, n + 1);
lua_readline_addcompletion(c, s);
@ -161,7 +161,7 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) {
lua_pop(L, 1); // pop table
for (i = 0; i < ARRAYLEN(kKeywordHints); ++i) {
if (startswithi(kKeywordHints[i], p)) {
if (_startswithi(kKeywordHints[i], p)) {
if ((s = strdup(kKeywordHints[i]))) {
lua_readline_addcompletion(c, s);
}

View file

@ -31,7 +31,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/runtime/stack.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"

View file

@ -23,9 +23,9 @@
#include "libc/log/log.h"
#include "libc/log/rop.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/stack.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/strlist.internal.h"
#include "libc/str/str.h"
#include "net/http/escape.h"

View file

@ -23,7 +23,7 @@
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/stack.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/strlist.internal.h"
#include "libc/str/str.h"
#include "libc/x/x.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "third_party/lua/cosmo.h"
#include "third_party/lua/lauxlib.h"

View file

@ -21,13 +21,13 @@
#include "libc/calls/ioctl.h"
#include "libc/calls/makedev.h"
#include "libc/calls/pledge.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/bpf.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/flock.h"
#include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/stat.h"
@ -43,6 +43,7 @@
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/fmt.h"
@ -56,9 +57,8 @@
#include "libc/sock/struct/linger.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/sock/syslog.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/path.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"
@ -2585,11 +2585,11 @@ static int LuaUnixErrnoWinerr(lua_State *L) {
}
static int LuaUnixErrnoName(lua_State *L) {
return ReturnString(L, strerrno(GetUnixErrno(L)->errno_));
return ReturnString(L, _strerrno(GetUnixErrno(L)->errno_));
}
static int LuaUnixErrnoDoc(lua_State *L) {
return ReturnString(L, strerdoc(GetUnixErrno(L)->errno_));
return ReturnString(L, _strerdoc(GetUnixErrno(L)->errno_));
}
static int LuaUnixErrnoCall(lua_State *L) {
@ -2604,7 +2604,7 @@ static int LuaUnixErrnoToString(lua_State *L) {
strerror_wr(e->errno_, e->winerr, msg, sizeof(msg));
lua_pushfstring(L, "%s() failed: %s", e->call, msg);
} else {
lua_pushstring(L, strerrno(e->errno_));
lua_pushstring(L, _strerrno(e->errno_));
}
return 1;
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/log/rop.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "third_party/lua/cosmo.h"
#include "third_party/lua/lua.h"

View file

@ -18,9 +18,9 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
/**/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/likely.h"
#include "libc/log/check.h"
#include "libc/nexgen32e/bsr.h"
#include "third_party/make/hash.h"
/* clang-format off */
@ -322,7 +322,7 @@ static unsigned long
round_up_2 (unsigned long n)
{
if (UNLIKELY(!n)) return 1;
return 2ul << bsrl(n);
return 2ul << _bsrl(n);
}
#define rol32(v, n) \

View file

@ -386,7 +386,7 @@ parse_bool (const char *s)
++s;
if (isdigit (*s))
return !! atoi (s);
return startswithi (s, "true");
return _startswithi (s, "true");
}
const char *

View file

@ -20,7 +20,6 @@
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/x86feature.h"
#include "third_party/mbedtls/bignum.h"
#include "third_party/mbedtls/bignum_internal.h"

View file

@ -22,7 +22,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/intrin/bsf.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"

View file

@ -16,7 +16,7 @@
limitations under the License.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "third_party/mbedtls/common.h"

View file

@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"

View file

@ -19,7 +19,7 @@
#include "libc/assert.h"
#include "libc/log/check.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/mbedtls/bignum_internal.h"

View file

@ -20,7 +20,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/log/check.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/mbedtls/bignum_internal.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "third_party/mbedtls/iana.h"
/**

View file

@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "third_party/mbedtls/common.h"

View file

@ -31,14 +31,14 @@
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/nr.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/mbedtls/config.h"
#include "third_party/mbedtls/endian.h"
#include "third_party/mbedtls/error.h"

View file

@ -1,8 +1,9 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TEST_LIB_H_
#define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_TEST_LIB_H_
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/mbedtls/config.h"
#include "third_party/mbedtls/platform.h"

View file

@ -29,7 +29,7 @@
#include "libc/limits.h"
#include "libc/literal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "third_party/musl/crypt.internal.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"

View file

@ -17,9 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/atomic.h"
#include "libc/calls/extend.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/extend.internal.h"
#include "libc/macros.internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "third_party/nsync/common.internal.h"
#include "third_party/nsync/malloc.internal.h"
// clang-format off
@ -40,10 +41,11 @@ void *nsync_malloc_ (size_t size) {
while (atomic_exchange (&nsync_malloc_lock_, 1)) nsync_yield_ ();
offset = nsync_malloc_total_;
nsync_malloc_total_ += size;
start = (char *) 0x6fc000040000;
start = (char *) kMemtrackNsyncStart;
if (!nsync_malloc_endptr_) nsync_malloc_endptr_ = start;
nsync_malloc_endptr_ = _extend (start, nsync_malloc_total_,
nsync_malloc_endptr_, 0x6fcfffff0000);
nsync_malloc_endptr_ =
_extend (start, nsync_malloc_total_, nsync_malloc_endptr_,
kMemtrackNsyncStart + kMemtrackNsyncSize);
atomic_store_explicit (&nsync_malloc_lock_, 0, memory_order_relaxed);
return start + offset;
}

View file

@ -50,6 +50,7 @@ struct nsync_dll_element_s_;
*/
typedef struct nsync_mu_s_ {
nsync_atomic_uint32_ word; /* internal use only */
int _zero; /* c pthread_mutex_t */
struct nsync_dll_element_s_ *waiters; /* internal use only */
} nsync_mu;

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "third_party/nsync/common.internal.h"
// clang-format off

View file

@ -28,7 +28,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "third_party/python/Modules/_decimal/libmpdec/bits.h"
#include "third_party/python/Modules/_decimal/libmpdec/constants.h"
#include "third_party/python/Modules/_decimal/libmpdec/mpdecimal.h"

View file

@ -11,7 +11,7 @@
#include "libc/log/log.h"
#include "libc/mem/alloca.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/auxv.h"

View file

@ -11,6 +11,7 @@
#include "libc/calls/makedev.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/stat.macros.h"
#include "libc/calls/struct/statvfs.h"
@ -25,9 +26,9 @@
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/weaken.h"
#include "libc/log/log.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/nt/createfile.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/creationdisposition.h"
@ -36,7 +37,6 @@
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/dlfcn.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/pathconf.h"
#include "libc/runtime/sysconf.h"
#include "libc/sock/sendfile.internal.h"

View file

@ -9,7 +9,7 @@
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/nt/efi.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/sock/epoll.h"
#include "libc/sock/select.h"
#include "libc/sock/sock.h"

View file

@ -20,7 +20,7 @@
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "net/https/https.h"
#include "third_party/mbedtls/ctr_drbg.h"

View file

@ -5,8 +5,8 @@
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "libc/intrin/bits.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/bits.h"
#include "libc/nexgen32e/kompressor.h"
#include "third_party/python/Include/floatobject.h"
#include "third_party/python/Include/import.h"
@ -405,7 +405,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
/* high byte is number of hex bytes (usually one or two), low byte
is prefix code (from*/
count = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8;
count = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8;
/* XXX: could allocate the PyString up front instead
(strlen(prefix) + 5 * count + 1 bytes) */
@ -413,7 +413,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
/* Based on how index is calculated above and _PyUnicode_Decomp is
generated from Tools/unicode/makeunicodedata.py, it should not be
possible to overflow _PyUnicode_DecompPrefix. */
prefix_index = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255;
prefix_index = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255;
assert(prefix_index < Py_ARRAY_LENGTH(_PyUnicode_DecompPrefix));
/* copy prefix */
@ -425,8 +425,8 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
decomp[i++] = ' ';
assert(i < sizeof(decomp));
PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X",
bextra(_PyUnicode_Decomp, ++index,
_PyUnicode_DecompBits));
_bextra(_PyUnicode_Decomp, ++index,
_PyUnicode_DecompBits));
i += strlen(decomp + i);
}
return PyUnicode_FromStringAndSize(decomp, i);

View file

@ -4,8 +4,8 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/intrin/bits.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/bits.h"
#include "third_party/python/Include/pyctype.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pymacro.h"
@ -174,7 +174,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code,
details */
h = (unsigned int)_gethash(name, namelen, _PyUnicode_CodeMagic);
i = ~h & mask;
v = bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits);
v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits);
if (!v)
return 0;
if (_cmpname(self, v, name, namelen))
@ -184,7 +184,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code,
incr = mask;
for (;;) {
i = (i + incr) & mask;
v = bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits);
v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits);
if (!v)
return 0;
if (_cmpname(self, v, name, namelen))
@ -247,10 +247,10 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen,
}
/* get offset into phrasebook */
offset = _PyUnicode_PhrasebookOffset1[(code>>_PyUnicode_PhrasebookShift)];
offset = bextra(_PyUnicode_PhrasebookOffset2,
(offset << _PyUnicode_PhrasebookShift) +
(code & ((1 << _PyUnicode_PhrasebookShift) - 1)),
_PyUnicode_PhrasebookOffset2Bits);
offset = _bextra(_PyUnicode_PhrasebookOffset2,
(offset << _PyUnicode_PhrasebookShift) +
(code & ((1 << _PyUnicode_PhrasebookShift) - 1)),
_PyUnicode_PhrasebookOffset2Bits);
if (!offset)
return 0;
i = 0;
@ -271,8 +271,8 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen,
word has bit 7 set. the last word in a string ends with
0x80 */
w = (_PyUnicode_Lexicon +
bextra(_PyUnicode_LexiconOffset, word,
_PyUnicode_LexiconOffsetBits));
_bextra(_PyUnicode_LexiconOffset, word,
_PyUnicode_LexiconOffsetBits));
while (*w < 128) {
if (i >= buflen)
return 0; /* buffer overflow */

View file

@ -31,7 +31,7 @@ _PyUnicode_GetDecompRecord(PyObject *self,
}
/* high byte is number of hex bytes (usually one or two), low byte
is prefix code (from*/
decomp = bextra(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits);
decomp = _bextra(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits);
*count = decomp >> 8;
*prefix = decomp & 255;
(*index)++;

View file

@ -115,10 +115,10 @@ _PyUnicode_NfcNfkc(PyObject *self, PyObject *input, int k)
}
index = f * UNIDATA_TOTAL_LAST + l;
index1 = _PyUnicode_CompIndex[index >> _PyUnicode_CompShift];
code = bextra(_PyUnicode_CompData,
(index1 << _PyUnicode_CompShift)+
(index & ((1 << _PyUnicode_CompShift) - 1)),
_PyUnicode_CompDataBits);
code = _bextra(_PyUnicode_CompData,
(index1 << _PyUnicode_CompShift)+
(index & ((1 << _PyUnicode_CompShift) - 1)),
_PyUnicode_CompDataBits);
if (code == 0)
goto not_combinable;
/* Replace the original character. */

View file

@ -97,9 +97,9 @@ _PyUnicode_NfdNfkd(PyObject *self, PyObject *input, int k)
/* Copy decomposition onto the stack, in reverse
order. */
while(count) {
code = bextra(_PyUnicode_Decomp,
index + (--count),
_PyUnicode_DecompBits);
code = _bextra(_PyUnicode_Decomp,
index + (--count),
_PyUnicode_DecompBits);
stack[stackptr++] = code;
}
}

View file

@ -6,7 +6,7 @@
*/
#include "libc/assert.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/accu.h"
#include "third_party/python/Include/boolobject.h"

View file

@ -6,10 +6,10 @@
*/
#define PY_SSIZE_T_CLEAN
#include "libc/assert.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/weaken.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/weaken.h"
#include "libc/log/countbranch.h"
#include "libc/str/str.h"
#include "third_party/python/Include/abstract.h"
@ -6029,7 +6029,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
/* \N{name} */
case 'N':
if (!weaken(_PyUnicode_GetCode)) {
if (!_weaken(_PyUnicode_GetCode)) {
PyErr_SetString(
PyExc_UnicodeError,
"\\N escapes not supported "
@ -6049,7 +6049,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
s++;
ch = 0xffffffff; /* in case 'getcode' messes up */
if (namelen <= INT_MAX &&
weaken(_PyUnicode_GetCode)(NULL, start, (int)namelen, &ch, 0)) {
_weaken(_PyUnicode_GetCode)(NULL, start, (int)namelen, &ch, 0)) {
assert(ch <= MAX_UNICODE);
WRITE_CHAR(ch);
continue;

View file

@ -5,7 +5,7 @@
https://docs.python.org/3/license.html │
*/
#include "libc/assert.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "third_party/python/Include/errcode.h"
#include "third_party/python/Include/node.h"
#include "third_party/python/Include/objimpl.h"
@ -32,7 +32,7 @@ fancy_roundup(int x)
/* Round up to the closest power of 2 >= n. */
int r;
assert(x > 128);
r = 1u << (bsr(x - 1) + 1); /* hacker's delight */
r = 1u << (_bsr(x - 1) + 1); /* hacker's delight */
return r > 0 ? r : -1;
}

View file

@ -1009,14 +1009,14 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
return NULL;
for (i = start, ressize = 0; i < end; ++i) {
/* object is guaranteed to be "ready" */
if (!weaken(_PyUnicode_GetUcName)) {
if (!_weaken(_PyUnicode_GetUcName)) {
PyErr_SetString(
PyExc_UnicodeError,
"_PyUnicode_GetUcName() not available");
return NULL;
}
c = PyUnicode_READ_CHAR(object, i);
if (weaken(_PyUnicode_GetUcName)(NULL, c, buffer, sizeof(buffer), 1)) {
if (_weaken(_PyUnicode_GetUcName)(NULL, c, buffer, sizeof(buffer), 1)) {
replsize = 1+1+1+(int)strlen(buffer)+1;
}
else if (c >= 0x10000) {

View file

@ -6,6 +6,7 @@
*/
#include "libc/intrin/weaken.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/pyerrors.h"
@ -159,6 +160,6 @@ exit:
#if defined(MS_WINDOWS) && defined(_DEBUG)
DebugBreak();
#endif
if (weaken(__die)) weaken(__die)();
if (_weaken(__die)) _weaken(__die)();
abort();
}

View file

@ -4,9 +4,9 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/intrin/weaken.h"
#include "libc/intrin/cmpxchg.h"
#include "libc/stdio/append.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "third_party/python/Include/pylifecycle.h"
/* clang-format off */
@ -32,7 +32,7 @@ Py_GetCopyright(void)
static char *res;
if (_cmpxchg(&once, 0, 1)) {
appends(&res, "");
for (p = *weaken(kLegalNotices); *p; p += strlen(p) + 1) {
for (p = *_weaken(kLegalNotices); *p; p += strlen(p) + 1) {
appends(&res, p);
}
}

View file

@ -4,15 +4,15 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/mem/alg.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/stat.macros.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
@ -887,7 +887,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co,
// cpathobj != NULL means cpathname != NULL
size_t cpathlen = strlen(cpathname);
char *pathname2 = _gc(strdup(cpathname));
if (endswith(pathname2, ".pyc"))
if (_endswith(pathname2, ".pyc"))
{
pathname2[cpathlen-2] = '\0'; // so now ends with .py
if(!stat(pathname2, &stinfo) && (stinfo.st_mode & S_IFMT) == S_IFREG)
@ -2370,7 +2370,7 @@ static PyObject *_imp_source_from_cache(PyObject *module, PyObject *arg) {
Py_ssize_t pathlen = 0;
if (!PyArg_Parse(PyOS_FSPath(arg), "z#:source_from_cache", &path, &pathlen))
return NULL;
if (!path || !endswith(path, ".pyc")) {
if (!path || !_endswith(path, ".pyc")) {
PyErr_Format(PyExc_ValueError, "%s does not end in .pyc", path);
return NULL;
}
@ -2666,7 +2666,7 @@ static PyObject *SFLObject_is_package(SourcelessFileLoader *self,
self->name, name);
return NULL;
}
if (startswith(basename(self->path), "__init__")) {
if (_startswith(basename(self->path), "__init__")) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;

View file

@ -9,7 +9,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/code.h"

View file

@ -9,7 +9,7 @@
#include "libc/mem/mem.h"
#include "libc/nt/dll.h"
#include "libc/nt/version.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/locale.h"

View file

@ -21,7 +21,7 @@
#include "libc/log/check.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/x/x.h"
#include "third_party/zlib/zlib.h"

View file

@ -24,10 +24,11 @@
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/o.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/getopt/getopt.h"
#include "third_party/python/Include/bytesobject.h"
#include "third_party/python/Include/compile.h"
@ -119,15 +120,15 @@ main(int argc, char *argv[])
GetOpts(argc, argv);
marshalled = 0;
if (stat(inpath, &st) == -1) perror(inpath), exit(1);
CHECK_NOTNULL((p = gc(xslurp(inpath, &n))));
CHECK_NOTNULL((p = _gc(xslurp(inpath, &n))));
Py_NoUserSiteDirectory++;
Py_NoSiteFlag++;
Py_IgnoreEnvironmentFlag++;
Py_FrozenFlag++;
/* Py_VerboseFlag++; */
Py_SetProgramName(gc(utf8to32(argv[0], -1, 0)));
Py_SetProgramName(_gc(utf8to32(argv[0], -1, 0)));
_Py_InitializeEx_Private(1, 0);
name = gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3)));
name = _gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3)));
code = Py_CompileStringExFlags(p, name, Py_file_input, NULL, optimize);
if (!code) goto error;
marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);

View file

@ -17,19 +17,19 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/def.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/o.h"
@ -354,7 +354,7 @@ GetModName(bool *ispkg)
{
char *mod;
mod = Dotify(xstripexts(StripComponents(pyfile, strip_components)));
if ((*ispkg = endswith(mod, ".__init__"))) {
if ((*ispkg = _endswith(mod, ".__init__"))) {
mod[strlen(mod) - strlen(".__init__")] = 0;
}
return mod;
@ -385,7 +385,7 @@ GetParent2(void)
{
char *p, *mod;
mod = Dotify(xstripexts(StripComponents(pyfile, strip_components)));
if (endswith(mod, ".__init__")) mod[strlen(mod) - strlen(".__init__")] = 0;
if (_endswith(mod, ".__init__")) mod[strlen(mod) - strlen(".__init__")] = 0;
if ((p = strrchr(mod, '.'))) *p = 0;
return mod;
}

View file

@ -18,8 +18,8 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
@ -30,6 +30,7 @@
#include "libc/sysv/consts/sig.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/linenoise/linenoise.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
@ -95,7 +96,7 @@ CompleteModule(const char *s, const char *p, linenoiseCompletions *c)
PyObject *m, *f, *g, *i, *v, *n;
plen = strlen(p);
for (it = PyImport_Inittab; it->name; ++it) {
if (startswithi(it->name, p)) {
if (_startswithi(it->name, p)) {
AddCompletion(c, xasprintf("%s%s", s, it->name + plen));
}
}
@ -169,7 +170,7 @@ Complete(const char *p, linenoiseCompletions *c)
{
PyObject *o, *t, *i;
const char *q, *s, *b;
if (startswith(p, "import ")) {
if (_startswith(p, "import ")) {
for (q = p + 7; *q; ++q) {
if (!isalnum(*q) && *q != '_') {
return;
@ -279,7 +280,7 @@ RunPythonModule(int argc, char **argv)
int i, res;
char *oldloc;
if (argc == 1 && weaken(kLaunchPythonModuleName)) {
if (argc == 1 && _weaken(kLaunchPythonModuleName)) {
launchargs[0] = argv[0];
launchargs[1] = strdup("-m");
launchargs[2] = strdup(kLaunchPythonModuleName);

View file

@ -24,7 +24,7 @@
*/
#include "libc/assert.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "third_party/quickjs/internal.h"

View file

@ -23,13 +23,15 @@
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
#include "third_party/quickjs/cutils.h"
@ -477,7 +479,7 @@ int main(int argc, char **argv)
{
int c, i, verbose;
const char *out_filename, *cname;
char *cfilename = gc(malloc(1024));
char *cfilename = _gc(malloc(1024));
FILE *fo;
JSRuntime *rt;
JSContext *ctx;

View file

@ -47,6 +47,7 @@
#include "third_party/quickjs/internal.h"
#include "libc/str/str.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "third_party/quickjs/libbf.h"
asm(".ident\t\"\\n\\n\

View file

@ -22,13 +22,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/weirdtypes.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/mem/alg.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/clock.h"
#include "libc/time/time.h"

View file

@ -47,7 +47,7 @@
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/utime.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/time/time.h"
#include "libc/str/str.h"

View file

@ -58,7 +58,7 @@
#include "libc/sysv/consts/sio.h"
#include "libc/sysv/consts/termios.h"
#include "libc/str/unicode.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/calls/calls.h"
#include "libc/str/str.h"

View file

@ -28,7 +28,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -17,9 +17,9 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/limits.h"
#include "libc/log/gdb.h"
#include "libc/log/log.h"
@ -2113,8 +2113,8 @@ static unsigned char *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y,
}
static dontinline void *stbi__jpeg_load(stbi__context *s, int *x, int *y,
int *comp, int req_comp,
stbi__result_info *ri) {
int *comp, int req_comp,
stbi__result_info *ri) {
unsigned char *result;
stbi__jpeg *j = (stbi__jpeg *)malloc(sizeof(stbi__jpeg));
j->s = s;
@ -2178,19 +2178,11 @@ typedef struct {
uint16_t value[288];
} stbi__zhuffman;
forceinline int stbi__bitreverse16(int n) {
n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4);
n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8);
return n;
}
forceinline int stbi__bit_reverse(int v, int bits) {
assert(bits <= 16);
// to bit reverse n bits, reverse 16 and shift
// e.g. 11 bits, bit reverse and shift away 5
return stbi__bitreverse16(v) >> (16 - bits);
return _bitreverse16(v) >> (16 - bits);
}
static int stbi__zbuild_huffman(stbi__zhuffman *z,
@ -3414,8 +3406,8 @@ static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp,
}
static dontinline void *stbi__png_load(stbi__context *s, int *x, int *y,
int *comp, int req_comp,
stbi__result_info *ri) {
int *comp, int req_comp,
stbi__result_info *ri) {
stbi__png p;
p.s = s;
return stbi__do_png(&p, x, y, comp, req_comp, ri);
@ -3917,8 +3909,8 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
}
static dontinline void *stbi__gif_load(stbi__context *s, int *x, int *y,
int *comp, int req_comp,
stbi__result_info *ri) {
int *comp, int req_comp,
stbi__result_info *ri) {
unsigned char *u = 0;
stbi__gif *g;
g = calloc(1, sizeof(stbi__gif));
@ -3970,8 +3962,8 @@ static int stbi__pnm_test(stbi__context *s) {
}
static dontinline void *stbi__pnm_load(stbi__context *s, int *x, int *y,
int *comp, int req_comp,
stbi__result_info *ri) {
int *comp, int req_comp,
stbi__result_info *ri) {
unsigned char *out;
if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y,
(int *)&s->img_n)) {

View file

@ -32,13 +32,13 @@
// manxorist@github saga musix github:infatum
// Timur Gagiev Maxwell Koo
//
#include "libc/mem/alg.h"
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/limits.h"
#include "libc/math.h"
#include "libc/mem/alg.h"
#include "libc/mem/alloca.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
@ -649,7 +649,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) {
res = available[z];
assert(z >= 0 && z < 32);
available[z] = 0;
add_entry(c, bitreverse32(res), i, m++, len[i], values);
add_entry(c, _bitreverse32(res), i, m++, len[i], values);
// propagate availability up the tree
if (z != len[i]) {
assert(len[i] >= 0 && len[i] < 32);
@ -675,7 +675,7 @@ static void compute_accelerated_huffman(Codebook *c) {
for (i = 0; i < len; ++i) {
if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) {
uint32 z =
c->sparse ? bitreverse32(c->sorted_codewords[i]) : c->codewords[i];
c->sparse ? _bitreverse32(c->sorted_codewords[i]) : c->codewords[i];
// set table entries for all bit combinations in the higher bits
while (z < FAST_HUFFMAN_TABLE_SIZE) {
c->fast_huffman[z] = i;
@ -720,11 +720,11 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths,
int k = 0;
for (i = 0; i < c->entries; ++i)
if (include_in_sort(c, lengths[i]))
c->sorted_codewords[k++] = bitreverse32(c->codewords[i]);
c->sorted_codewords[k++] = _bitreverse32(c->codewords[i]);
assert(k == c->sorted_entries);
} else {
for (i = 0; i < c->sorted_entries; ++i)
c->sorted_codewords[i] = bitreverse32(c->codewords[i]);
c->sorted_codewords[i] = _bitreverse32(c->codewords[i]);
}
qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]),
@ -740,7 +740,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths,
for (i = 0; i < len; ++i) {
int huff_len = c->sparse ? lengths[values[i]] : lengths[i];
if (include_in_sort(c, huff_len)) {
uint32 code = bitreverse32(c->codewords[i]);
uint32 code = _bitreverse32(c->codewords[i]);
int x = 0, n = c->sorted_entries;
while (n > 1) {
// invariant: sc[x] <= code < sc[x+n]
@ -808,7 +808,7 @@ static void compute_window(int n, float *window) {
static void compute_bitreverse(int n, uint16 *rev) {
int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
int i, n8 = n >> 3;
for (i = 0; i < n8; ++i) rev[i] = (bitreverse32(i) >> (32 - ld + 3)) << 2;
for (i = 0; i < n8; ++i) rev[i] = (_bitreverse32(i) >> (32 - ld + 3)) << 2;
}
static int init_blocksize(vorb *f, int b, int n) {
@ -1182,7 +1182,7 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) {
// sorted_codewords && c->entries > 8
if (c->entries > 8 ? c->sorted_codewords != NULL : !c->codewords) {
// binary search
uint32 code = bitreverse32(f->acc);
uint32 code = _bitreverse32(f->acc);
int x = 0, n = c->sorted_entries, len;
while (n > 1) {
@ -2560,7 +2560,7 @@ void inverse_mdct_naive(float *buffer, int n)
// step 4
for (i=0; i < n8; ++i) {
int j = bitreverse32(i) >> (32-ld+3);
int j = _bitreverse32(i) >> (32-ld+3);
assert(j < n8);
if (i == j) {
// paper bug: original code probably swapped in place; if copying,

View file

@ -16,7 +16,7 @@
#include "libc/assert.h"
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "third_party/tidy/tags.h"

View file

@ -71,7 +71,7 @@
#include "third_party/unzip/crypt.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "third_party/unzip/unzvers.h"
#include "third_party/unzip/globals.h"

View file

@ -17,10 +17,10 @@
limitations under the License.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/xed/avx.h"
@ -775,7 +775,7 @@ privileged static void xed_evex_scanner(struct XedDecodedInst *d) {
}
privileged static uint64_t xed_read_number(uint8_t *p, size_t n, bool s) {
switch (s << 2 | bsr(n)) {
switch (s << 2 | _bsr(n)) {
case 0b000:
return *p;
case 0b100:

View file

@ -38,6 +38,7 @@
#include "libc/str/str.h"
#include "libc/calls/struct/stat.h"
#include "libc/runtime/runtime.h"
#include "third_party/zip/osdep.h"

View file

@ -5,8 +5,8 @@
Use of this source code is governed by the BSD-style licenses that can
be found in the third_party/zlib/LICENSE file.
*/
#include "libc/intrin/weaken.h"
#include "libc/dce.h"
#include "libc/intrin/weaken.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
#include "third_party/zlib/deflate.internal.h"
@ -19,22 +19,22 @@ Copyright 1995-2017 Jean-loup Gailly and Mark Adler\"");
asm(".include \"libc/disclaimer.inc\"");
void crc_reset(struct DeflateState *const s) {
if (X86_HAVE(PCLMUL) && weaken(crc_fold_init)) {
weaken(crc_fold_init)(s);
if (X86_HAVE(PCLMUL) && _weaken(crc_fold_init)) {
_weaken(crc_fold_init)(s);
return;
}
s->strm->adler = crc32(0L, Z_NULL, 0);
}
void crc_finalize(struct DeflateState *const s) {
if (X86_HAVE(PCLMUL) && weaken(crc_fold_512to32)) {
s->strm->adler = weaken(crc_fold_512to32)(s);
if (X86_HAVE(PCLMUL) && _weaken(crc_fold_512to32)) {
s->strm->adler = _weaken(crc_fold_512to32)(s);
}
}
void copy_with_crc(z_streamp strm, Bytef *dst, long size) {
if (X86_HAVE(PCLMUL) && weaken(crc_fold_copy)) {
weaken(crc_fold_copy)(strm->state, dst, strm->next_in, size);
if (X86_HAVE(PCLMUL) && _weaken(crc_fold_copy)) {
_weaken(crc_fold_copy)(strm->state, dst, strm->next_in, size);
return;
}
memcpy(dst, strm->next_in, size);

View file

@ -21,9 +21,9 @@
#include "third_party/zlib/zutil.internal.h"
void *zcalloc(void *opaque, uInt items, uInt size) {
return weaken(malloc)(items * size);
return _weaken(malloc)(items * size);
}
void zcfree(void *opaque, void *ptr) {
weaken(free)(ptr);
_weaken(free)(ptr);
}

View file

@ -122,7 +122,7 @@ int z_verbose hidden = verbose;
void z_error(const char *file, int line, char *m) {
kprintf("%s:%d: zlib panic: %s\n", file, line, m);
if (weaken(__die)) weaken(__die)();
if (_weaken(__die)) _weaken(__die)();
_Exit(1);
}
#endif