mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
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:
parent
6cb0354e19
commit
a4b455185b
280 changed files with 1362 additions and 1407 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue