mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 12:18:31 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -72,7 +72,8 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) {
|
|||
layout = "layout asm";
|
||||
if ((elf = FindDebugBinary())) {
|
||||
se = "-se";
|
||||
if (fileexists(__FILE__)) layout = "layout src";
|
||||
if (fileexists(__FILE__))
|
||||
layout = "layout src";
|
||||
} else {
|
||||
se = "-q";
|
||||
elf = "-q";
|
||||
|
|
|
@ -135,7 +135,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
sys_close(pipefds[1]);
|
||||
for (;;) {
|
||||
got = sys_read(pipefds[0], buf, kBacktraceBufSize);
|
||||
if (!got) break;
|
||||
if (!got)
|
||||
break;
|
||||
if (got == -1 && errno == EINTR) {
|
||||
errno = 0;
|
||||
continue;
|
||||
|
@ -150,7 +151,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
if ((p2 = memmem(p1, got, " (discriminator ",
|
||||
strlen(" (discriminator ") - 1)) &&
|
||||
(p3 = memchr(p2, '\n', got - (p2 - p1)))) {
|
||||
if (p3 > p2 && p3[-1] == '\r') --p3;
|
||||
if (p3 > p2 && p3[-1] == '\r')
|
||||
--p3;
|
||||
klog(p1, p2 - p1);
|
||||
got -= p3 - p1;
|
||||
p1 += p3 - p1;
|
||||
|
@ -162,7 +164,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
}
|
||||
sys_close(pipefds[0]);
|
||||
while (sys_wait4(pid, &ws, 0, 0) == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
if (WIFEXITED(ws) && !WEXITSTATUS(ws)) {
|
||||
|
@ -191,7 +194,8 @@ void ShowBacktrace(int fd, const struct StackFrame *bp) {
|
|||
/* asan runtime depends on this function */
|
||||
ftrace_enabled(-1);
|
||||
strace_enabled(-1);
|
||||
if (!bp) bp = __builtin_frame_address(0);
|
||||
if (!bp)
|
||||
bp = __builtin_frame_address(0);
|
||||
PrintBacktrace(fd, bp);
|
||||
strace_enabled(+1);
|
||||
ftrace_enabled(+1);
|
||||
|
|
|
@ -51,7 +51,8 @@ dontinstrument dontasan int PrintBacktraceUsingSymbols(
|
|||
struct Garbages *garbage;
|
||||
const struct StackFrame *frame;
|
||||
(void)gi;
|
||||
if (!bp) bp = __builtin_frame_address(0);
|
||||
if (!bp)
|
||||
bp = __builtin_frame_address(0);
|
||||
garbage = __tls_enabled ? __get_tls()->tib_garbages : 0;
|
||||
gi = garbage ? garbage->i : 0;
|
||||
for (i = 0, frame = bp; frame; frame = frame->next) {
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
void __check_fail_aligned(unsigned bytes, uint64_t ptr, const char *file,
|
||||
int line, const char *fmt, ...) {
|
||||
fflush(stderr);
|
||||
if (!IsTiny()) _memsummary(fileno(stderr));
|
||||
if (!IsTiny())
|
||||
_memsummary(fileno(stderr));
|
||||
kprintf("%s:%d: error: pointer not %d-byte aligned: %p\n", file, line, bytes,
|
||||
ptr);
|
||||
__die();
|
||||
|
|
|
@ -48,7 +48,8 @@ static relegated wontreturn void __check_fail_ndebug(uint64_t want, //
|
|||
kvprintf(fmt, va);
|
||||
}
|
||||
kprintf("\n");
|
||||
if (_weaken(__die)) _weaken(__die)();
|
||||
if (_weaken(__die))
|
||||
_weaken(__die)();
|
||||
_Exit(68);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,11 @@
|
|||
const char *commandvenv(const char *var, const char *cmd) {
|
||||
const char *exepath;
|
||||
static char pathbuf[PATH_MAX];
|
||||
if (*cmd == '/' || *cmd == '\\') return cmd;
|
||||
if (*cmd == '/' || *cmd == '\\')
|
||||
return cmd;
|
||||
if ((exepath = getenv(var))) {
|
||||
if (isempty(exepath)) return NULL;
|
||||
if (isempty(exepath))
|
||||
return NULL;
|
||||
if (access(exepath, X_OK) != -1) {
|
||||
return exepath;
|
||||
} else {
|
||||
|
|
|
@ -51,17 +51,22 @@ static int CompareCounters(const void *a, const void *b) {
|
|||
double x, y;
|
||||
x = RankCounter(a);
|
||||
y = RankCounter(b);
|
||||
if (x > y) return +1;
|
||||
if (x < y) return -1;
|
||||
if (GetTotal(a) < GetTotal(b)) return +1;
|
||||
if (GetTotal(a) > GetTotal(b)) return -1;
|
||||
if (x > y)
|
||||
return +1;
|
||||
if (x < y)
|
||||
return -1;
|
||||
if (GetTotal(a) < GetTotal(b))
|
||||
return +1;
|
||||
if (GetTotal(a) > GetTotal(b))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t CountCounters(void) {
|
||||
size_t n;
|
||||
struct countbranch *p;
|
||||
for (n = 0, p = countbranch_data; p->total >= 0; ++p) ++n;
|
||||
for (n = 0, p = countbranch_data; p->total >= 0; ++p)
|
||||
++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ static long GetLongSum(const long *h, size_t n) {
|
|||
}
|
||||
|
||||
static size_t GetRowCount(const long *h, size_t n) {
|
||||
while (n && !h[n - 1]) --n;
|
||||
while (n && !h[n - 1])
|
||||
--n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,8 @@ static void PrintHistogram(const long *h, size_t n, long t) {
|
|||
p = (h[i] * 10000 + (t >> 1)) / t;
|
||||
unassert(0 <= p && p <= 10000);
|
||||
if (p) {
|
||||
for (j = 0; j < p / 100; ++j) s[j] = '#';
|
||||
for (j = 0; j < p / 100; ++j)
|
||||
s[j] = '#';
|
||||
s[j] = 0;
|
||||
logos = i ? 1ul << (i - 1) : 0;
|
||||
kprintf("%'12lu %'16ld %3d.%02d%% %s\n", logos, h[i], p / 100, p % 100,
|
||||
|
|
|
@ -32,7 +32,8 @@ relegated int(gdbexec)(const char *cmd) {
|
|||
struct StackFrame *bp;
|
||||
const char *se, *elf, *gdb;
|
||||
char pidstr[11], breakcmd[40];
|
||||
if (!(gdb = GetGdbPath())) return -1;
|
||||
if (!(gdb = GetGdbPath()))
|
||||
return -1;
|
||||
snprintf(pidstr, sizeof(pidstr), "%u", getpid());
|
||||
if ((elf = FindDebugBinary())) {
|
||||
se = "-se";
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
* Returns name of function that called caller function.
|
||||
*/
|
||||
const char *GetCallerName(const struct StackFrame *bp) {
|
||||
if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next;
|
||||
if (bp) return GetSymbolByAddr(bp->addr);
|
||||
if (!bp && (bp = __builtin_frame_address(0)))
|
||||
bp = bp->next;
|
||||
if (bp)
|
||||
return GetSymbolByAddr(bp->addr);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,8 @@ static dontasan bool HasLeaks(void) {
|
|||
*/
|
||||
dontasan void CheckForMemoryLeaks(void) {
|
||||
struct mallinfo mi;
|
||||
if (!IsAsan()) return; // we need traces to exclude leaky
|
||||
if (!IsAsan())
|
||||
return; // we need traces to exclude leaky
|
||||
if (!GetSymbolTable()) {
|
||||
kprintf("CheckForMemoryLeaks() needs the symbol table\n");
|
||||
return;
|
||||
|
|
|
@ -88,13 +88,17 @@ static long __memlog_size(void *p) {
|
|||
static void __memlog_backtrace(struct StackFrame *frame, intptr_t *a,
|
||||
intptr_t *b, intptr_t *c, intptr_t *d) {
|
||||
*a = *b = *c = *d = 0;
|
||||
if (!frame) return;
|
||||
if (!frame)
|
||||
return;
|
||||
*a = frame->addr;
|
||||
if (!(frame = frame->next)) return;
|
||||
if (!(frame = frame->next))
|
||||
return;
|
||||
*b = frame->addr;
|
||||
if (!(frame = frame->next)) return;
|
||||
if (!(frame = frame->next))
|
||||
return;
|
||||
*c = frame->addr;
|
||||
if (!(frame = frame->next)) return;
|
||||
if (!(frame = frame->next))
|
||||
return;
|
||||
*d = frame->addr;
|
||||
}
|
||||
|
||||
|
@ -163,7 +167,8 @@ static void __memlog_log(struct StackFrame *frame, const char *op, void *res,
|
|||
|
||||
static void __memlog_free(void *p) {
|
||||
long i, n;
|
||||
if (!p) return;
|
||||
if (!p)
|
||||
return;
|
||||
__memlog_lock();
|
||||
if ((i = __memlog_find(p)) != -1) {
|
||||
n = __memlog.allocs.p[i].size;
|
||||
|
|
|
@ -120,7 +120,8 @@ relegated static dontinline char *DescribeCpuFlags(char *p, int flags,
|
|||
}
|
||||
|
||||
static char *HexCpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
|
||||
while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
|
||||
while (k > 0)
|
||||
*p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
|
||||
*p = '\0';
|
||||
return p;
|
||||
}
|
||||
|
@ -130,8 +131,10 @@ relegated static char *ShowGeneralRegisters(char *p, ucontext_t *ctx) {
|
|||
const char *s;
|
||||
*p++ = '\n';
|
||||
for (i = 0, j = 0; i < ARRAYLEN(kGregNames); ++i) {
|
||||
if (j > 0) *p++ = ' ';
|
||||
if (!(s = kGregNames[(unsigned)kGregOrder[i]])[2]) *p++ = ' ';
|
||||
if (j > 0)
|
||||
*p++ = ' ';
|
||||
if (!(s = kGregNames[(unsigned)kGregOrder[i]])[2])
|
||||
*p++ = ' ';
|
||||
p = stpcpy(p, s), *p++ = ' ';
|
||||
p = HexCpy(p, ctx->uc_mcontext.gregs[(unsigned)kGregOrder[i]], 64);
|
||||
if (++j == 3) {
|
||||
|
|
|
@ -80,7 +80,8 @@ static relegated void Append(struct Buffer *b, const char *fmt, ...) {
|
|||
}
|
||||
|
||||
static relegated const char *ColorRegister(int r) {
|
||||
if (__nocolor) return "";
|
||||
if (__nocolor)
|
||||
return "";
|
||||
switch (r) {
|
||||
case 0: // arg / res
|
||||
case 1: // arg / res
|
||||
|
@ -125,9 +126,12 @@ static relegated bool AppendFileLine(struct Buffer *b, const char *addr2line,
|
|||
ssize_t rc;
|
||||
char *p, *q, buf[128];
|
||||
int j, k, ws, pid, pfd[2];
|
||||
if (!debugbin || !*debugbin) return false;
|
||||
if (!addr2line || !*addr2line) return false;
|
||||
if (sys_pipe(pfd)) return false;
|
||||
if (!debugbin || !*debugbin)
|
||||
return false;
|
||||
if (!addr2line || !*addr2line)
|
||||
return false;
|
||||
if (sys_pipe(pfd))
|
||||
return false;
|
||||
ksnprintf(buf, sizeof(buf), "%lx", addr);
|
||||
if ((pid = vfork()) == -1) {
|
||||
sys_close(pfd[1]);
|
||||
|
@ -261,7 +265,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
|||
Append(b, " ");
|
||||
for (j = 0; j < 4; ++j) {
|
||||
int r = 8 * j + i;
|
||||
if (j) Append(b, " ");
|
||||
if (j)
|
||||
Append(b, " ");
|
||||
Append(b, "%s%016lx%s x%d%s", ColorRegister(r),
|
||||
ctx->uc_mcontext.regs[r], reset, r, r == 8 || r == 9 ? " " : "");
|
||||
}
|
||||
|
@ -272,12 +277,14 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
|||
vc = (struct fpsimd_context *)ctx->uc_mcontext.__reserved;
|
||||
if (vc->head.magic == FPSIMD_MAGIC) {
|
||||
int n = 16;
|
||||
while (n && !vc->vregs[n - 1] && !vc->vregs[n - 2]) n -= 2;
|
||||
while (n && !vc->vregs[n - 1] && !vc->vregs[n - 2])
|
||||
n -= 2;
|
||||
for (i = 0; i * 2 < n; ++i) {
|
||||
Append(b, " ");
|
||||
for (j = 0; j < 2; ++j) {
|
||||
int r = j + 2 * i;
|
||||
if (j) Append(b, " ");
|
||||
if (j)
|
||||
Append(b, " ");
|
||||
Append(b, "%016lx ..%s %016lx v%d%s", (long)(vc->vregs[r] >> 64),
|
||||
!j ? "" : ".", (long)vc->vregs[r], r, r < 10 ? " " : "");
|
||||
}
|
||||
|
@ -297,7 +304,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
|||
Append(b, " ");
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
if (addend) Append(b, "%+d", addend);
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
}
|
||||
Append(b, "\n");
|
||||
|
@ -318,7 +326,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
|||
Append(b, " ");
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
if (addend) Append(b, "%+d", addend);
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
}
|
||||
Append(b, "\n");
|
||||
|
@ -357,7 +366,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
|
|||
Append(b, " %016lx fp %lx lr ", fp, pc);
|
||||
if (!AppendFileLine(b, addr2line, debugbin, pc) && st) {
|
||||
Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz));
|
||||
if (addend) Append(b, "%+d", addend);
|
||||
if (addend)
|
||||
Append(b, "%+d", addend);
|
||||
}
|
||||
Append(b, "\n");
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ void PrintWindowsMemory(const char *high, size_t size) {
|
|||
for (p = 0;; p = (char *)mi.BaseAddress + mi.RegionSize) {
|
||||
const char *start, *stop;
|
||||
bzero(&mi, sizeof(mi));
|
||||
if (!VirtualQuery(p, &mi, sizeof(mi))) break;
|
||||
if (!VirtualQuery(p, &mi, sizeof(mi)))
|
||||
break;
|
||||
sizefmt(b[0], mi.RegionSize, 1024);
|
||||
if (MAX(high, (char *)mi.BaseAddress) <
|
||||
MIN(high + size, (char *)mi.BaseAddress + mi.RegionSize)) {
|
||||
|
|
|
@ -50,7 +50,8 @@ static struct timespec vflogf_ts;
|
|||
static void vflogf_onfail(FILE *f) {
|
||||
errno_t err;
|
||||
struct stat st;
|
||||
if (IsTiny()) return;
|
||||
if (IsTiny())
|
||||
return;
|
||||
err = ferror_unlocked(f);
|
||||
if (fileno_unlocked(f) != -1 &&
|
||||
(err == ENOSPC || err == EDQUOT || err == EFBIG) &&
|
||||
|
@ -90,8 +91,10 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
|
|||
const char *prog;
|
||||
const char *sign;
|
||||
struct timespec t2;
|
||||
if (!f) f = __log_file;
|
||||
if (!f) return;
|
||||
if (!f)
|
||||
f = __log_file;
|
||||
if (!f)
|
||||
return;
|
||||
flockfile(f);
|
||||
strace_enabled(-1);
|
||||
BLOCK_SIGNALS;
|
||||
|
@ -113,7 +116,8 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
|
|||
strcpy(iso8601(buf32, &tm), sign);
|
||||
prog = basename(firstnonnull(program_invocation_name, "unknown"));
|
||||
bufmode = f->bufmode;
|
||||
if (bufmode == _IOLBF) f->bufmode = _IOFBF;
|
||||
if (bufmode == _IOLBF)
|
||||
f->bufmode = _IOFBF;
|
||||
|
||||
if ((fprintf_unlocked)(f, "%r%c%s%06ld:%s:%d:%.*s:%d] ",
|
||||
"FEWIVDNT"[level & 7], buf32, dots / 1000, file, line,
|
||||
|
|
|
@ -41,8 +41,10 @@ static dontinstrument inline void Copy(char *p, char *q, size_t n) {
|
|||
}
|
||||
|
||||
static dontinstrument inline int Cmp(char *p, char *q, size_t n) {
|
||||
if (n == 8) return READ64LE(p) != READ64LE(q);
|
||||
if (n == 4) return READ32LE(p) != READ32LE(q);
|
||||
if (n == 8)
|
||||
return READ64LE(p) != READ64LE(q);
|
||||
if (n == 4)
|
||||
return READ32LE(p) != READ32LE(q);
|
||||
for (; n; ++p, ++q, --n) {
|
||||
if (*p != *q) {
|
||||
return 1;
|
||||
|
@ -52,7 +54,8 @@ static dontinstrument inline int Cmp(char *p, char *q, size_t n) {
|
|||
}
|
||||
|
||||
dontinstrument void __watcher(void) {
|
||||
if (__watch_busy) return;
|
||||
if (__watch_busy)
|
||||
return;
|
||||
__watch_busy = true;
|
||||
if (Cmp(__watch_last, __watch_addr, __watch_size)) {
|
||||
kprintf("watchpoint %p changed:\n"
|
||||
|
@ -74,11 +77,15 @@ dontinstrument void __watcher(void) {
|
|||
*/
|
||||
int __watch(void *addr, size_t size) {
|
||||
static bool once;
|
||||
if (__watch_busy) ebusy();
|
||||
if (size > sizeof(__watch_last)) return einval();
|
||||
if (__watch_busy)
|
||||
ebusy();
|
||||
if (size > sizeof(__watch_last))
|
||||
return einval();
|
||||
if (!once) {
|
||||
if (!GetSymbolTable()) return -1;
|
||||
if (__hook(__watch_hook, GetSymbolTable()) == -1) return -1;
|
||||
if (!GetSymbolTable())
|
||||
return -1;
|
||||
if (__hook(__watch_hook, GetSymbolTable()) == -1)
|
||||
return -1;
|
||||
once = true;
|
||||
}
|
||||
__watch_addr = addr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue