Bring back gc() function

Renaming gc() to _gc() was a mistake since the better thing to do is put
it behind the _COSMO_SOURCE macro. We need this change because I haven't
wanted to use my amazing garbage collector ever since we renamed it. You
now need to define _COSMO_SOURCE yourself when using amalgamation header
and cosmocc users need to pass the -mcosmo flag to get the gc() function

Some other issues relating to cancelation have been fixed along the way.
We're also now putting cosmocc in a folder named `.cosmocc` so it can be
more safely excluded by grep --exclude-dir=.cosmocc --exclude-dir=o etc.
This commit is contained in:
Justine Tunney 2024-01-08 10:07:35 -08:00
parent 6cb0354e19
commit a4b455185b
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
280 changed files with 1362 additions and 1407 deletions

View file

@ -20,7 +20,7 @@
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -20,7 +20,7 @@
#include "libc/fmt/conv.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -41,7 +41,7 @@
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -32,7 +32,7 @@
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/serialize.h"
#include "libc/stdckdint.h"

View file

@ -87,8 +87,8 @@ static void MakeRelaSection(struct ElfWriter *elf, size_t section) {
elfwriter_align(elf, alignof(Elf64_Rela), sizeof(Elf64_Rela));
shdr = elfwriter_startsection(
elf,
_gc(xasprintf("%s%s", ".rela",
&elf->shstrtab->p[elf->shdrs->p[section].sh_name])),
gc(xasprintf("%s%s", ".rela",
&elf->shstrtab->p[elf->shdrs->p[section].sh_name])),
SHT_RELA, SHF_INFO_LINK);
elf->shdrs->p[shdr].sh_info = section;
elfwriter_reserve(elf, size);

View file

@ -19,15 +19,15 @@
#include "libc/dos.internal.h"
#include "libc/elf/def.h"
#include "libc/fmt/wintime.internal.h"
#include "libc/serialize.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/serialize.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
@ -203,9 +203,9 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
EmitZipLfileHdr(lfile, name, namesize, crc, era, gflags, method, mtime, mdate,
compsize, uncompsize);
elfwriter_commit(elf, lfilehdrsize + compsize);
lfilesym = elfwriter_appendsym(
elf, _gc(xasprintf("%s%s", "zip+lfile:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0, lfilehdrsize);
lfilesym = elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+lfile:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT),
STV_DEFAULT, 0, lfilehdrsize);
elfwriter_appendsym(elf, symbol, ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT),
STV_DEFAULT, lfilehdrsize, compsize);
elfwriter_finishsection(elf);
@ -217,7 +217,7 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
(cfile = elfwriter_reserve(elf, ZIP_CFILE_HDR_SIZE + namesize)), name,
namesize, crc, era, gflags, method, mtime, mdate, iattrs, dosmode, mode,
compsize, uncompsize, commentsize, mtim, atim, ctim);
elfwriter_appendsym(elf, _gc(xasprintf("%s%s", "zip+cdir:", name)),
elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+cdir:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0,
ZIP_CFILE_HDR_SIZE + namesize);
elfwriter_appendrela(elf, kZipCfileOffsetOffset, lfilesym,

View file

@ -16,17 +16,17 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/psk.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "tool/build/lib/psk.h"
/**
* Returns preshared key for runit testing infrastructure.
@ -35,7 +35,7 @@ void *GetRunitPsk(void) {
int fd;
char *r, *p;
struct stat st;
p = _gc(xasprintf("%s/.runit.psk", _gc(xhomedir())));
p = gc(xasprintf("%s/.runit.psk", gc(xhomedir())));
if (stat(p, &st) == -1 || st.st_size != 32) {
fprintf(stderr, "need o//examples/getrandom.com -bn32 >~/.runit.psk\n");
exit(1);

View file

@ -22,7 +22,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"

View file

@ -149,7 +149,7 @@ void Connect(void) {
int rc, err, expo;
struct addrinfo *ai;
struct timespec deadline;
if ((rc = getaddrinfo(g_hostname, _gc(xasprintf("%hu", g_runitdport)),
if ((rc = getaddrinfo(g_hostname, gc(xasprintf("%hu", g_runitdport)),
&kResolvHints, &ai)) != 0) {
FATALF("%s:%hu: EAI_%s %m", g_hostname, g_runitdport, gai_strerror(rc));
__builtin_unreachable();
@ -210,7 +210,7 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
static bool once;
static z_stream zs;
zsize = 32768;
zbuf = _gc(malloc(zsize));
zbuf = gc(malloc(zsize));
if (!once) {
CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY));
@ -249,7 +249,7 @@ bool SendRequest(int tmpfd) {
CHECK_NE(MAP_FAILED, (p = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
CHECK_LE((namesize = strlen((name = basename(g_prog)))), PATH_MAX);
CHECK_LE((progsize = st.st_size), INT_MAX);
CHECK_NOTNULL((hdr = _gc(calloc(1, (hdrsize = 17 + namesize)))));
CHECK_NOTNULL((hdr = gc(calloc(1, (hdrsize = 17 + namesize)))));
crc = crc32_z(0, (unsigned char *)p, st.st_size);
q = hdr;
q = WRITE32BE(q, RUNITD_MAGIC);
@ -269,7 +269,7 @@ bool SendRequest(int tmpfd) {
void RelayRequest(void) {
int i, rc, have, transferred;
char *buf = _gc(malloc(PIPE_BUF));
char *buf = gc(malloc(PIPE_BUF));
for (transferred = 0;;) {
rc = read(13, buf, PIPE_BUF);
CHECK_NE(-1, rc);
@ -409,7 +409,7 @@ int SpawnSubprocesses(int argc, char *argv[]) {
// create compressed network request ahead of time
const char *tmpdir = firstnonnull(getenv("TMPDIR"), "/tmp");
char *tpath = _gc(xasprintf("%s/runit.XXXXXX", tmpdir));
char *tpath = gc(xasprintf("%s/runit.XXXXXX", tmpdir));
int tmpfd = mkstemp(tpath);
CHECK_NE(-1, tmpfd);
CHECK(SendRequest(tmpfd));

View file

@ -36,7 +36,7 @@
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/proc/posix_spawn.h"

View file

@ -26,7 +26,7 @@
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -15,7 +15,7 @@
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/goodsocket.internal.h"

View file

@ -31,7 +31,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -18,7 +18,7 @@
*/
#include "tool/decode/lib/asmcodegen.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -23,7 +23,7 @@
#include "libc/fmt/libgen.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macho.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -20,16 +20,16 @@
#include "libc/calls/struct/stat.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/libgen.h"
#include "libc/serialize.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nt/struct/imagedosheader.internal.h"
#include "libc/nt/struct/imagentheaders.internal.h"
#include "libc/nt/struct/imageoptionalheader.internal.h"
#include "libc/nt/struct/imagesectionheader.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/serialize.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
@ -204,7 +204,7 @@ static void showpeoptionalheader(struct NtImageOptionalHeader *opt) {
show(".long", \
format(b1, "%#X,%u", opt->DataDirectory[x].VirtualAddress, \
opt->DataDirectory[x].Size), \
_gc(xasprintf("opt->DataDirectory[%s]", #x))); \
gc(xasprintf("opt->DataDirectory[%s]", #x))); \
} \
} while (0)
@ -235,8 +235,8 @@ static void ShowIlt(uint32_t rva) {
do {
printf("\n");
show(".quad", format(b1, "%#lx", *ilt),
_gc(xasprintf("rva=%#lx off=%#lx", (char *)ilt - (char *)ilt0 + rva,
(intptr_t)ilt - (intptr_t)mz)));
gc(xasprintf("rva=%#lx off=%#lx", (char *)ilt - (char *)ilt0 + rva,
(intptr_t)ilt - (intptr_t)mz)));
if (*ilt) {
char *hint = GetRva(*ilt);
printf("/\t.short\t%d\t\t\t# @%#lx\n", READ16LE(hint),
@ -256,13 +256,13 @@ static void ShowIdt(char *idt, size_t size) {
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
printf("\n");
show(".long", format(b1, "%#x", READ32LE(p)),
_gc(xasprintf("ImportLookupTable RVA @%#lx",
(intptr_t)p - (intptr_t)mz)));
gc(xasprintf("ImportLookupTable RVA @%#lx",
(intptr_t)p - (intptr_t)mz)));
show(".long", format(b1, "%#x", READ32LE(p + 4)), "TimeDateStamp");
show(".long", format(b1, "%#x", READ32LE(p + 8)), "ForwarderChain");
show(".long", format(b1, "%#x", READ32LE(p + 12)),
READ32LE(p + 12)
? _gc(xasprintf("DllName RVA (%s)", GetRva(READ32LE(p + 12))))
? gc(xasprintf("DllName RVA (%s)", GetRva(READ32LE(p + 12))))
: "DllName RVA");
show(".long", format(b1, "%#x", READ32LE(p + 16)),
"ImportAddressTable RVA");

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/stat.h"
#include "libc/fmt/libgen.h"
#include "libc/fmt/wintime.internal.h"
#include "libc/serialize.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h"
@ -29,6 +28,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nt/struct/filetime.h"
#include "libc/serialize.h"
#include "libc/stdckdint.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/sysparam.h"
@ -86,9 +86,9 @@ void ShowGeneralFlag(uint16_t generalflag) {
void ShowTimestamp(uint16_t time, uint16_t date) {
show(".short", format(b1, "%#04hx", time),
_gc(xasprintf("%s (%s)", "lastmodifiedtime", _gc(FormatDosTime(time)))));
gc(xasprintf("%s (%s)", "lastmodifiedtime", gc(FormatDosTime(time)))));
show(".short", format(b1, "%#04hx", date),
_gc(xasprintf("%s (%s)", "lastmodifieddate", _gc(FormatDosDate(date)))));
gc(xasprintf("%s (%s)", "lastmodifieddate", gc(FormatDosDate(date)))));
}
void ShowCompressionMethod(uint16_t compressmethod) {
@ -103,19 +103,18 @@ void ShowNtfs(uint8_t *ntfs, size_t n) {
mtime = WindowsTimeToTimeSpec(READ64LE(ntfs + 8));
atime = WindowsTimeToTimeSpec(READ64LE(ntfs + 16));
ctime = WindowsTimeToTimeSpec(READ64LE(ntfs + 24));
show(".long", _gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved");
show(".short", _gc(xasprintf("0x%04x", READ16LE(ntfs + 4))),
show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved");
show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))),
"ntfs attribute tag value #1");
show(".short", _gc(xasprintf("%hu", READ16LE(ntfs + 6))),
show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))),
"ntfs attribute tag size");
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 8))),
_gc(xasprintf("%s (%s)", "ntfs last modified time",
_gc(xiso8601(&mtime)))));
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 16))),
_gc(xasprintf("%s (%s)", "ntfs last access time",
_gc(xiso8601(&atime)))));
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 24))),
_gc(xasprintf("%s (%s)", "ntfs creation time", _gc(xiso8601(&ctime)))));
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))),
gc(xasprintf("%s (%s)", "ntfs last modified time",
gc(xiso8601(&mtime)))));
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))),
gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime)))));
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))),
gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime)))));
}
void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
@ -123,28 +122,28 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
if (n) {
--n;
flag = *p++;
show(".byte", _gc(xasprintf("0b%03hhb", flag)), "fields present in local");
show(".byte", gc(xasprintf("0b%03hhb", flag)), "fields present in local");
if ((flag & 1) && n >= 4) {
show(".long", _gc(xasprintf("%u", READ32LE(p))),
_gc(xasprintf("%s (%s)", "last modified",
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "last modified",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}
flag >>= 1;
if (islocal) {
if ((flag & 1) && n >= 4) {
show(".long", _gc(xasprintf("%u", READ32LE(p))),
_gc(xasprintf("%s (%s)", "access time",
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "access time",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}
flag >>= 1;
if ((flag & 1) && n >= 4) {
show(".long", _gc(xasprintf("%u", READ32LE(p))),
_gc(xasprintf("%s (%s)", "creation time",
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "creation time",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}
@ -163,8 +162,8 @@ void ShowZip64(uint8_t *lf, uint8_t *p, size_t n, bool islocal) {
}
if (uncompsize == 0xffffffffu) {
if (i + 8 <= n) {
show(".quad", _gc(xasprintf("0x%lx", READ64LE(p + i))),
_gc(xasprintf("uncompressed size (%,ld)", READ64LE(p + i))));
show(".quad", gc(xasprintf("0x%lx", READ64LE(p + i))),
gc(xasprintf("uncompressed size (%,ld)", READ64LE(p + i))));
} else {
kprintf("/\tWARNING: ZIP64 EXTRA MISSING UNCOMPRESSED SIZE\n");
}
@ -179,8 +178,8 @@ void ShowZip64(uint8_t *lf, uint8_t *p, size_t n, bool islocal) {
}
if (compsize == 0xffffffffu) {
if (i + 8 <= n) {
show(".quad", _gc(xasprintf("0x%lx", READ64LE(p + i))),
_gc(xasprintf("compressed size (%,ld)", READ64LE(p + i))));
show(".quad", gc(xasprintf("0x%lx", READ64LE(p + i))),
gc(xasprintf("compressed size (%,ld)", READ64LE(p + i))));
} else {
kprintf("/\tWARNING: ZIP64 EXTRA MISSING COMPRESSED SIZE\n");
}
@ -192,8 +191,8 @@ void ShowZip64(uint8_t *lf, uint8_t *p, size_t n, bool islocal) {
offset = ZIP_CFILE_OFFSET(lf);
if (offset == 0xffffffffu) {
if (i + 8 <= n) {
show(".quad", _gc(xasprintf("0x%lx", READ64LE(p + i))),
_gc(xasprintf("lfile offset (%,ld)", READ64LE(p + i))));
show(".quad", gc(xasprintf("0x%lx", READ64LE(p + i))),
gc(xasprintf("lfile offset (%,ld)", READ64LE(p + i))));
} else {
kprintf("/\tWARNING: ZIP64 EXTRA MISSING OFFSET\n");
}
@ -206,8 +205,8 @@ void ShowZip64(uint8_t *lf, uint8_t *p, size_t n, bool islocal) {
disk = ZIP_CFILE_DISK(lf);
if (disk == 0xffff) {
if (i + 4 <= n) {
show(".long", _gc(xasprintf("0x%x", READ32LE(p + i))),
_gc(xasprintf("lfile disk (%,ld)", READ32LE(p + i))));
show(".long", gc(xasprintf("0x%x", READ32LE(p + i))),
gc(xasprintf("lfile disk (%,ld)", READ32LE(p + i))));
} else {
kprintf("/\tWARNING: ZIP64 EXTRA MISSING DISK\n");
}
@ -224,9 +223,9 @@ void ShowInfoZipNewUnixExtra(uint8_t *p, size_t n, bool islocal) {
if (p[0] == 1 && p[1] == 4 && p[6] == 4) {
show(".byte", "1", "version");
show(".byte", "4", "uid length");
show(".long", _gc(xasprintf("%u", READ32LE(p + 2))), "uid");
show(".long", gc(xasprintf("%u", READ32LE(p + 2))), "uid");
show(".byte", "4", "gid length");
show(".long", _gc(xasprintf("%u", READ32LE(p + 7))), "gid");
show(".long", gc(xasprintf("%u", READ32LE(p + 7))), "gid");
} else {
disassemblehex(p, n, stdout);
}
@ -279,11 +278,11 @@ void ShowExtras(uint8_t *lf, uint8_t *extras, uint16_t extrassize,
p += ZIP_EXTRA_SIZE(p), ++i) {
show(".short",
firstnonnull(findnamebyid(kZipExtraNames, ZIP_EXTRA_HEADERID(p)),
_gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))),
_gc(xasprintf("%s[%d].%s", "extras", i, "headerid")));
show(".short", _gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)),
_gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize",
ZIP_EXTRA_CONTENTSIZE(p), "bytes")));
gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))),
gc(xasprintf("%s[%d].%s", "extras", i, "headerid")));
show(".short", gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)),
gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize",
ZIP_EXTRA_CONTENTSIZE(p), "bytes")));
if (first) {
first = false;
printf("%d:", (i + 1) * 10);
@ -301,18 +300,18 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
show(".ascii", format(b1, "%`'.*s", 4, lf), "magic");
show(".byte",
firstnonnull(findnamebyid(kZipEraNames, ZIP_LFILE_VERSIONNEED(lf)),
_gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))),
gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))),
"pkzip version need");
show(".byte",
firstnonnull(findnamebyid(kZipOsNames, ZIP_LFILE_OSNEED(lf)),
_gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))),
gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))),
"os need");
ShowGeneralFlag(ZIP_LFILE_GENERALFLAG(lf));
ShowCompressionMethod(ZIP_LFILE_COMPRESSIONMETHOD(lf));
ShowTimestamp(ZIP_LFILE_LASTMODIFIEDTIME(lf), ZIP_LFILE_LASTMODIFIEDDATE(lf));
show(
".long",
format(b1, "%#x", ZIP_LFILE_CRC32(lf)), _gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */)));
format(b1, "%#x", ZIP_LFILE_CRC32(lf)), gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */)));
if (ZIP_LFILE_COMPRESSEDSIZE(lf) == 0xFFFFFFFF) {
show(".long", "0xFFFFFFFF", "compressedsize (zip64)");
} else {
@ -333,7 +332,7 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
printf("0:");
show(".ascii",
format(b1, "%`'s",
_gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))),
gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))),
"name");
printf("1:");
ShowExtras(lf, ZIP_LFILE_EXTRA(lf), ZIP_LFILE_EXTRASIZE(lf), true);
@ -347,19 +346,19 @@ void ShowCentralFileHeader(uint8_t *cf) {
printf("\n/\t%s (%zu %s @ %#lx)\n", "central directory file header",
ZIP_CFILE_HDRSIZE(cf), "bytes", cf - map);
show(".ascii", format(b1, "%`'.*s", 4, cf), "magic");
show(".byte", _gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))),
show(".byte", gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))),
"zip version made");
show(".byte",
firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_FILEATTRCOMPAT(cf)),
_gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))),
gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))),
"file attr compat");
show(".byte",
firstnonnull(findnamebyid(kZipEraNames, ZIP_CFILE_VERSIONNEED(cf)),
_gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))),
gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))),
"pkzip version need");
show(".byte",
firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_OSNEED(cf)),
_gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))),
gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))),
"os need");
ShowGeneralFlag(ZIP_CFILE_GENERALFLAG(cf));
ShowCompressionMethod(ZIP_CFILE_COMPRESSIONMETHOD(cf));
@ -398,7 +397,7 @@ void ShowCentralFileHeader(uint8_t *cf) {
printf("0:");
show(".ascii",
format(b1, "%`'s",
_gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))),
gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))),
"name");
printf("1:");
ShowExtras(cf, ZIP_CFILE_EXTRA(cf), ZIP_CFILE_EXTRASIZE(cf), false);

View file

@ -95,7 +95,7 @@ static int LuaFetch(lua_State *L) {
return LuaNilError(L, "invalid header name: %s", key);
val = lua_tolstring(L, -1, &vallen);
if (!(hdr = _gc(EncodeHttpHeaderValue(val, vallen, 0))))
if (!(hdr = gc(EncodeHttpHeaderValue(val, vallen, 0))))
return LuaNilError(L, "invalid header %s value encoding", key);
// Content-Length will be overwritten; skip it to avoid duplicates;
@ -133,14 +133,14 @@ static int LuaFetch(lua_State *L) {
if (bodylen > 0 || !(methodidx == kHttpGet || methodidx == kHttpHead ||
methodidx == kHttpTrace || methodidx == kHttpDelete ||
methodidx == kHttpConnect)) {
conlenhdr = _gc(xasprintf("Content-Length: %zu\r\n", bodylen));
conlenhdr = gc(xasprintf("Content-Length: %zu\r\n", bodylen));
}
/*
* Parse URL.
*/
_gc(ParseUrl(urlarg, urlarglen, &url, true));
_gc(url.params.p);
gc(ParseUrl(urlarg, urlarglen, &url, true));
gc(url.params.p);
usingssl = false;
if (url.scheme.n) {
#ifndef UNSECURE
@ -160,9 +160,9 @@ static int LuaFetch(lua_State *L) {
#endif
if (url.host.n) {
host = _gc(strndup(url.host.p, url.host.n));
host = gc(strndup(url.host.p, url.host.n));
if (url.port.n) {
port = _gc(strndup(url.port.p, url.port.n));
port = gc(strndup(url.port.p, url.port.n));
#ifndef UNSECURE
} else if (usingssl) {
port = "443";
@ -179,7 +179,7 @@ static int LuaFetch(lua_State *L) {
if (!IsAcceptableHost(host, -1)) {
return LuaNilError(L, "invalid host");
}
if (!hosthdr) hosthdr = _gc(xasprintf("%s:%s", host, port));
if (!hosthdr) hosthdr = gc(xasprintf("%s:%s", host, port));
// check if hosthdr is in keepalive table
if (keepalive && lua_istable(L, 2)) {
@ -207,7 +207,7 @@ static int LuaFetch(lua_State *L) {
url.host.p = 0, url.host.n = 0;
url.port.p = 0, url.port.n = 0;
if (!url.path.n || url.path.p[0] != '/') {
void *p = _gc(xmalloc(1 + url.path.n));
void *p = gc(xmalloc(1 + url.path.n));
mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n);
url.path.p = p;
++url.path.n;
@ -224,14 +224,14 @@ static int LuaFetch(lua_State *L) {
"User-Agent: %s\r\n"
"%s%s"
"\r\n",
method, _gc(EncodeUrl(&url, 0)), hosthdr,
method, gc(EncodeUrl(&url, 0)), hosthdr,
(keepalive == kaNONE || keepalive == kaCLOSE)
? "close"
: (connhdr ? connhdr : "keep-alive"),
agenthdr, conlenhdr, headers ? headers : "");
appendd(&request, body, bodylen);
requestlen = appendz(request).i;
_gc(request);
gc(request);
if (keepalive == kaNONE || keepalive == kaOPEN) {
/*
@ -274,7 +274,7 @@ static int LuaFetch(lua_State *L) {
if (!evadedragnetsurveillance) {
mbedtls_ssl_set_hostname(&sslcli, host);
}
bio = _gc(malloc(sizeof(struct TlsBio)));
bio = gc(malloc(sizeof(struct TlsBio)));
bio->fd = sock;
bio->a = 0;
bio->b = 0;
@ -524,7 +524,7 @@ VerifyFailed:
LockInc(&shared->c.sslverifyfailed);
close(sock);
return LuaNilTlsError(
L, _gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)),
L, gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)),
ret);
#endif
#undef ssl

View file

@ -32,7 +32,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bench.h"
#include "libc/nexgen32e/crc32.h"

View file

@ -28,7 +28,7 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/calls/weirdtypes.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "third_party/lua/lauxlib.h"

View file

@ -49,7 +49,7 @@
#include "libc/math.h"
#include "libc/mem/alloca.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/rdtsc.h"
@ -687,7 +687,7 @@ static void UseCertificate(mbedtls_ssl_config *c, struct Cert *kp,
const char *role) {
VERBOSEF("(ssl) using %s certificate %`'s for HTTPS %s",
mbedtls_pk_get_name(&kp->cert->pk),
_gc(FormatX509Name(&kp->cert->subject)), role);
gc(FormatX509Name(&kp->cert->subject)), role);
CHECK_EQ(0, mbedtls_ssl_conf_own_cert(c, kp->cert, kp->key));
}
@ -704,21 +704,21 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) {
if (prev) {
if (mbedtls_x509_crt_check_parent(prev, cert, 1)) {
DEBUGF("(ssl) unbundling %`'s from %`'s",
_gc(FormatX509Name(&prev->subject)),
_gc(FormatX509Name(&cert->subject)));
gc(FormatX509Name(&prev->subject)),
gc(FormatX509Name(&cert->subject)));
prev->next = 0;
} else if ((r = mbedtls_x509_crt_check_signature(prev, cert, 0))) {
WARNF("(ssl) invalid signature for %`'s -> %`'s (-0x%04x)",
_gc(FormatX509Name(&prev->subject)),
_gc(FormatX509Name(&cert->subject)), -r);
gc(FormatX509Name(&prev->subject)),
gc(FormatX509Name(&cert->subject)), -r);
}
}
if (mbedtls_x509_time_is_past(&cert->valid_to)) {
WARNF("(ssl) certificate %`'s is expired",
_gc(FormatX509Name(&cert->subject)));
gc(FormatX509Name(&cert->subject)));
} else if (mbedtls_x509_time_is_future(&cert->valid_from)) {
WARNF("(ssl) certificate %`'s is from the future",
_gc(FormatX509Name(&cert->subject)));
gc(FormatX509Name(&cert->subject)));
}
for (i = 0; i < certs.n; ++i) {
if (!certs.p[i].cert && certs.p[i].key &&
@ -1044,8 +1044,8 @@ static void ProgramCache(long x, const char *s) {
}
static void SetDefaults(void) {
ProgramBrand(_gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020,
VERSION >> 010, VERSION >> 000)));
ProgramBrand(gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020,
VERSION >> 010, VERSION >> 000)));
__log_level = kLogInfo;
maxpayloadsize = 64 * 1024;
ProgramCache(-1, "must-revalidate");
@ -1094,7 +1094,7 @@ static void UpdateLuaPath(const char *s) {
// if the DEFAULT path is not found, append to the end
respath = xasprintf("%s;%s/.lua/?.lua;%s/.lua/?/init.lua", curpath, s, s);
}
lua_pushstring(L, _gc(respath));
lua_pushstring(L, gc(respath));
lua_setfield(L, -3, "path");
}
lua_settop(L, n);
@ -1210,7 +1210,7 @@ static void LuaEvalCode(const char *code) {
// handle `-F PATH` arg
static void LuaEvalFile(const char *path) {
char *f = _gc(xslurp(path, 0));
char *f = gc(xslurp(path, 0));
if (!f) FATALF("(cfg) error: failed to read file %`'s", path);
LuaEvalCode(f);
}
@ -1731,7 +1731,7 @@ static bool TlsRouteFind(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl,
0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key));
DEBUGF("(ssl) TlsRoute(%s, %`'.*s) %s %`'s", mbedtls_pk_type_name(type),
size, host, mbedtls_pk_get_name(&certs.p[i].cert->pk),
_gc(FormatX509Name(&certs.p[i].cert->subject)));
gc(FormatX509Name(&certs.p[i].cert->subject)));
return true;
}
}
@ -1746,7 +1746,7 @@ static bool TlsRouteFirst(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl) {
0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key));
DEBUGF("(ssl) TlsRoute(%s) %s %`'s", mbedtls_pk_type_name(type),
mbedtls_pk_get_name(&certs.p[i].cert->pk),
_gc(FormatX509Name(&certs.p[i].cert->subject)));
gc(FormatX509Name(&certs.p[i].cert->subject)));
return true;
}
}
@ -1811,7 +1811,7 @@ static bool TlsSetup(void) {
ssl.session->compression ? " COMPRESSED" : "",
ssl.curve ? ssl.curve->name : "uncurved");
DEBUGF("(ssl) client ciphersuite preference was %s",
_gc(FormatSslClientCiphers(&ssl)));
gc(FormatSslClientCiphers(&ssl)));
return true;
} else if (r == MBEDTLS_ERR_SSL_WANT_READ) {
LockInc(&shared->c.handshakeinterrupts);
@ -1835,12 +1835,12 @@ static bool TlsSetup(void) {
case MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN:
LockInc(&shared->c.sslnociphers);
WARNF("(ssl) %s %s %s", DescribeClient(), "sslnociphers",
_gc(FormatSslClientCiphers(&ssl)));
gc(FormatSslClientCiphers(&ssl)));
return false;
case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE:
LockInc(&shared->c.sslcantciphers);
WARNF("(ssl) %s %s %s", DescribeClient(), "sslcantciphers",
_gc(FormatSslClientCiphers(&ssl)));
gc(FormatSslClientCiphers(&ssl)));
return false;
case MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION:
LockInc(&shared->c.sslnoversion);
@ -1859,7 +1859,7 @@ static bool TlsSetup(void) {
case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
LockInc(&shared->c.sslverifyfailed);
WARNF("(ssl) %s SSL %s", DescribeClient(),
_gc(DescribeSslVerifyFailure(
gc(DescribeSslVerifyFailure(
ssl.session_negotiate->verify_result)));
return false;
case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
@ -1904,7 +1904,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca,
struct sockaddr_in addr4 = {AF_INET, 0, {htonl(ip)}};
if (getnameinfo((struct sockaddr *)&addr4, sizeof(addr4), rname,
sizeof(rname), 0, 0, NI_NAMEREQD) == 0) {
char *s = _gc(strdup(rname));
char *s = gc(strdup(rname));
if (!name) name = s;
bool isduplicate = false;
for (int j = 0; j < nsan; ++j) {
@ -1919,7 +1919,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca,
san[nsan - 2].tag = MBEDTLS_X509_SAN_DNS_NAME;
san[nsan - 2].val = s;
san[nsan - 1].tag = MBEDTLS_X509_SAN_DNS_NAME;
san[nsan - 1].val = _gc(xasprintf("*.%s", s));
san[nsan - 1].val = gc(xasprintf("*.%s", s));
}
}
}
@ -2050,7 +2050,7 @@ static void LoadCertificates(void) {
if (!havecert && (!psks.n || ksk.key)) {
if ((ksk = GetKeySigningKey()).key) {
DEBUGF("(ssl) generating ssl certificates using %`'s",
_gc(FormatX509Name(&ksk.cert->subject)));
gc(FormatX509Name(&ksk.cert->subject)));
} else {
VERBOSEF("(ssl) could not find non-CA SSL certificate key pair with"
" -addext keyUsage=digitalSignature"
@ -2913,10 +2913,10 @@ static void LaunchBrowser(const char *path) {
}
// assign a loopback address if no server or unknown server address
if (!servers.n || !addr.s_addr) addr.s_addr = htonl(INADDR_LOOPBACK);
if (*path != '/') path = _gc(xasprintf("/%s", path));
if ((prog = commandv(GetSystemUrlLauncherCommand(), _gc(malloc(PATH_MAX)),
if (*path != '/') path = gc(xasprintf("/%s", path));
if ((prog = commandv(GetSystemUrlLauncherCommand(), gc(malloc(PATH_MAX)),
PATH_MAX))) {
u = _gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path));
u = gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path));
DEBUGF("(srvr) opening browser with command %`'s %s", prog, u);
ignore.sa_flags = 0;
ignore.sa_handler = SIG_IGN;
@ -3587,7 +3587,7 @@ static int LuaGetSslIdentity(lua_State *L) {
psks.p[sslpskindex - 1].identity_len);
} else {
cert = mbedtls_ssl_get_peer_cert(&ssl);
lua_pushstring(L, cert ? _gc(FormatX509Name(&cert->subject)) : "");
lua_pushstring(L, cert ? gc(FormatX509Name(&cert->subject)) : "");
}
}
return 1;
@ -3858,7 +3858,7 @@ static void StorePath(const char *dirpath) {
while ((e = readdir(d))) {
if (strcmp(e->d_name, ".") == 0) continue;
if (strcmp(e->d_name, "..") == 0) continue;
path = _gc(xjoinpaths(dirpath, e->d_name));
path = gc(xjoinpaths(dirpath, e->d_name));
if (e->d_type == DT_DIR) {
StorePath(path);
} else {
@ -3930,7 +3930,7 @@ static int LuaNilError(lua_State *L, const char *fmt, ...) {
static int LuaNilTlsError(lua_State *L, const char *s, int r) {
return LuaNilError(L, "tls %s failed (%s %s)", s,
IsTiny() ? "grep" : GetTlsError(r),
_gc(xasprintf("-0x%04x", -r)));
gc(xasprintf("-0x%04x", -r)));
}
#include "tool/net/fetch.inc"
@ -4001,7 +4001,7 @@ static int LuaLog(lua_State *L) {
module = ar.short_src;
line = ar.currentline;
} else {
module = _gc(strndup(effectivepath.p, effectivepath.n));
module = gc(strndup(effectivepath.p, effectivepath.n));
line = -1;
}
flogf(level, module, line, NULL, "%s", msg);
@ -4298,7 +4298,7 @@ static int LuaSetHeader(lua_State *L) {
static int LuaGetCookie(lua_State *L) {
char *cookie = 0, *cookietmpl, *cookieval;
OnlyCallDuringRequest(L, "GetCookie");
cookietmpl = _gc(xasprintf(" %s=", luaL_checkstring(L, 1)));
cookietmpl = gc(xasprintf(" %s=", luaL_checkstring(L, 1)));
if (HasHeader(kHttpCookie)) {
appends(&cookie, " "); // prepend space to simplify cookie search
appendd(&cookie, HeaderData(kHttpCookie), HeaderLength(kHttpCookie));
@ -4343,7 +4343,7 @@ static int LuaSetCookie(lua_State *L) {
if ((ishostpref || issecurepref) && !usingssl) {
luaL_argerror(
L, 1,
_gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
__builtin_unreachable();
}
@ -4674,7 +4674,7 @@ static int LuaProgramCertificate(lua_State *L) {
static int LuaProgramHeader(lua_State *L) {
ProgramHeader(
_gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2))));
gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2))));
return 0;
}
@ -5824,7 +5824,7 @@ static char *OpenAsset(struct Asset *a) {
UnmapLater(fd, data, size);
cpm.content = data;
cpm.contentlength = size;
} else if ((st = _gc(malloc(sizeof(struct stat)))) &&
} else if ((st = gc(malloc(sizeof(struct stat)))) &&
fstat(fd, st) != -1 && (data = malloc(st->st_size))) {
/* probably empty file or zipos handle */
LockInc(&shared->c.slurps);

View file

@ -75,15 +75,15 @@ void showcachesizes(void) {
CPUID4_ITERATE(i, {
printf("%-19s%s%s %u-way %,7u byte cache w/%s %,5u sets of %u byte lines "
"shared across %u threads\n",
_gc(xasprintf("Level %u%s", CPUID4_CACHE_LEVEL,
CPUID4_CACHE_TYPE == 1 ? " data"
: CPUID4_CACHE_TYPE == 2 ? " code"
: "")),
gc(xasprintf("Level %u%s", CPUID4_CACHE_LEVEL,
CPUID4_CACHE_TYPE == 1 ? " data"
: CPUID4_CACHE_TYPE == 2 ? " code"
: "")),
CPUID4_IS_FULLY_ASSOCIATIVE ? " fully-associative" : "",
CPUID4_COMPLEX_INDEXING ? " complexly-indexed" : "",
CPUID4_WAYS_OF_ASSOCIATIVITY, CPUID4_CACHE_SIZE_IN_BYTES,
CPUID4_PHYSICAL_LINE_PARTITIONS > 1
? _gc(xasprintf(" %u physically partitioned"))
? gc(xasprintf(" %u physically partitioned"))
: "",
CPUID4_NUMBER_OF_SETS, CPUID4_SYSTEM_COHERENCY_LINE_SIZE,
CPUID4_MAX_THREADS_SHARING_CACHE);

View file

@ -9,7 +9,7 @@
#endif
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/x/x.h"

View file

@ -27,7 +27,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"

View file

@ -87,8 +87,8 @@ int main(int argc, char *argv[]) {
}
n = end + 1 - start;
m = ROUNDUP(n, 16);
present = _gc(malloc(m));
intotal = _gc(calloc(1, m));
present = gc(malloc(m));
intotal = gc(calloc(1, m));
if (optind < argc) {
for (arg = optind; arg < argc; ++arg) {
ttf = xslurp(argv[arg], &ttfsize);

View file

@ -54,10 +54,10 @@ void *GenerateTortureImage(unsigned char RGB[YN][YM][XN][XM][3]) {
int main(int argc, char *argv[]) {
stbi_write_png(
_gc(xasprintf("maxwell_%dx%d_%dx%d.png", XN * XM, YN * YM, XM, YM)),
gc(xasprintf("maxwell_%dx%d_%dx%d.png", XN * XM, YN * YM, XM, YM)),
XN * XM, YN * YM, 3,
GenerateTortureImage(
_gc(xmemalign(32, sizeof(unsigned char) * XN * XM * YN * YM * 3))),
gc(xmemalign(32, sizeof(unsigned char) * XN * XM * YN * YM * 3))),
XN * XM * 3);
return 0;
}

View file

@ -137,14 +137,14 @@ int main(int argc, char *argv[]) {
}
}
m = argc - optind;
w = _gc(calloc(m, sizeof(*w)));
h = _gc(calloc(m, sizeof(*h)));
ttf = _gc(calloc(m, sizeof(*ttf)));
font = _gc(calloc(m, sizeof(*font)));
rasters = _gc(calloc(m, sizeof(*rasters)));
fasters = _gc(calloc(m, sizeof(*fasters)));
w = gc(calloc(m, sizeof(*w)));
h = gc(calloc(m, sizeof(*h)));
ttf = gc(calloc(m, sizeof(*ttf)));
font = gc(calloc(m, sizeof(*font)));
rasters = gc(calloc(m, sizeof(*rasters)));
fasters = gc(calloc(m, sizeof(*fasters)));
for (j = 0; j < m; ++j) {
ttf[j] = _gc(xslurp(argv[optind + j], &ttfsize));
ttf[j] = gc(xslurp(argv[optind + j], &ttfsize));
if (!ttf[j]) {
fprintf(stderr, "%s: not found\n", argv[optind + j]);
exit(1);

View file

@ -46,15 +46,15 @@ void PrintImg(const char *path) {
size_t n;
int yn, xn, cn, w, h;
void *img, *pix, *src;
if (!(img = _gc(xslurp(path, &n)))) exit(2);
if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
if (!(img = gc(xslurp(path, &n)))) exit(2);
if (!(pix = gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
if (linktag) {
printf("<a href=\"%s\"\n >", path);
}
src = (void *)path;
if (datauri) {
src = xasprintf("data:%s;base64,%s", FindContentType(path, -1),
_gc(EncodeBase64(img, n, &n)));
gc(EncodeBase64(img, n, &n)));
}
w = (xn + (1 << scale) / 2) >> scale;
h = (yn + (1 << scale) / 2) >> scale;

View file

@ -86,12 +86,12 @@ void *BilinearScale(long dcw, long dyw, long dxw,
DCHECK_LT(_bsrl(cn) + _bsrl(dyn) + _bsrl(dxn), 32);
BilinearScaler(dcw, dyw, dxw, dst, scw, syw, sxw, src, c0, cn, dyn, dxn,
syn, sxn, ry, rx, oy, ox,
_gc(xmemalign(64, ROUNDUP(sizeof(int) * (dyn + 1), 64))),
_gc(xmemalign(64, ROUNDUP(dyn + 1, 64))),
_gc(xmemalign(64, ROUNDUP(sizeof(int) * (dxn + 1), 64))),
_gc(xmemalign(64, ROUNDUP(dxn + 1, 64))),
_gc(xmemalign(64, ROUNDUP(dxn, 64))),
_gc(xmemalign(64, ROUNDUP(sxn, 64) * 2)));
gc(xmemalign(64, ROUNDUP(sizeof(int) * (dyn + 1), 64))),
gc(xmemalign(64, ROUNDUP(dyn + 1, 64))),
gc(xmemalign(64, ROUNDUP(sizeof(int) * (dxn + 1), 64))),
gc(xmemalign(64, ROUNDUP(dxn + 1, 64))),
gc(xmemalign(64, ROUNDUP(dxn, 64))),
gc(xmemalign(64, ROUNDUP(sxn, 64) * 2)));
} else {
bzero(dst[c0], &dst[cn][0][0] - &dst[c0][0][0]);
}

View file

@ -22,7 +22,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/viz/lib/graphic.h"

View file

@ -18,8 +18,8 @@
*/
#include "libc/assert.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/x/xasprintf.h"
#include "tool/viz/lib/formatstringtable.h"
#include "tool/viz/lib/stringbuilder.h"
@ -44,7 +44,7 @@ void FormatMatrixByte(long yn, long xn, const unsigned char M[yn][xn],
yn, xn,
formatter(yn, xn,
ConvertByteMatrixToStringTable(
yn, xn, _gc(calloc(yn * xn, sizeof(char *))), M),
yn, xn, gc(calloc(yn * xn, sizeof(char *))), M),
emit, arg, param1, param2, param3));
}

View file

@ -20,7 +20,7 @@
#include "libc/fmt/conv.h"
#include "libc/log/check.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/x/x.h"
#include "third_party/gdtoa/gdtoa.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/x/x.h"
#include "tool/viz/lib/formatstringtable.h"

View file

@ -18,8 +18,8 @@
*/
#include "libc/assert.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "tool/viz/lib/formatstringtable.h"
@ -45,7 +45,7 @@ void FormatMatrixShort(long yn, long xn, const short M[yn][xn], int emit(),
yn, xn,
formatter(yn, xn,
ConvertShortMatrixToStringTable(
yn, xn, _gc(xcalloc(yn * xn, sizeof(char *))), M),
yn, xn, gc(xcalloc(yn * xn, sizeof(char *))), M),
emit, arg, param1, param2, param3));
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/fmt/itoa.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/str/str.h"
#include "libc/str/strwidth.h"
#include "libc/x/x.h"

View file

@ -35,7 +35,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/gc.internal.h"
#include "libc/nexgen32e/nexgen32e.h"

View file

@ -20,7 +20,7 @@
#include "libc/serialize.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "net/http/http.h"

View file

@ -35,7 +35,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"

View file

@ -30,7 +30,7 @@
#include "libc/fmt/conv.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"