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:
Jōshin 2024-04-25 10:38:00 -07:00 committed by GitHub
parent 342d0c81e5
commit 6e6fc38935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
863 changed files with 9201 additions and 4627 deletions

View file

@ -23,6 +23,7 @@
bool testlib_almostequallongdouble(long double x, long double y) {
/* TODO(jart): This algorithm has to be binary. */
if (isnan(x) || isnan(y)) return false;
if (isnan(x) || isnan(y))
return false;
return fabsl(x - y) <= EPSILON;
}

View file

@ -54,7 +54,8 @@ void testlib_benchwarmup(void) {
void EnableCruiseControlForCool(void) {
int fd, micros = 10;
if (!IsLinux()) return;
if (!IsLinux())
return;
BLOCK_CANCELATION;
if ((fd = __sys_openat(AT_FDCWD, "/dev/cpu_dma_latency", O_WRONLY, 0)) !=
-1) {

View file

@ -30,11 +30,15 @@
bool testlib_binequals(const char16_t *want, const void *got, size_t n) {
size_t i;
const unsigned char *p = (const unsigned char *)got;
if (!got) return false;
if (!got)
return false;
for (i = 0; i < n; ++i) {
if (!want[i]) break;
if (i == n) break;
if (want[i] != kCp437[p[i]]) return false;
if (!want[i])
break;
if (i == n)
break;
if (want[i] != kCp437[p[i]])
return false;
}
return true;
}

View file

@ -20,8 +20,10 @@
#include "libc/testlib/testlib.h"
bool testlib_contains(size_t cw, const void *s, const void *needle) {
if (s == needle) return true;
if (!s || !needle) return false;
if (s == needle)
return true;
if (!s || !needle)
return false;
return sizeof(cw) == sizeof(char16_t) ? !!strstr16(s, needle)
: !!strstr(s, needle);
}

View file

@ -20,8 +20,10 @@
#include "libc/testlib/testlib.h"
bool testlib_endswith(size_t cw, const void *s, const void *suffix) {
if (s == suffix) return true;
if (!s || !suffix) return false;
if (s == suffix)
return true;
if (!s || !suffix)
return false;
return cw == sizeof(wchar_t) ? wcsendswith(s, suffix)
: cw == sizeof(char16_t) ? endswith16(s, suffix)
: endswith(s, suffix);

View file

@ -22,7 +22,8 @@
void testlib_formatbinaryasglyphs(const char16_t *want, const void *got,
size_t n, char **out_v1, char **out_v2) {
if (n == -1ul) n = strlen16(want);
if (n == -1ul)
n = strlen16(want);
*out_v1 = xasprintf("%`#.*hs", n, want);
*out_v2 = xasprintf(" %`'#.*s", n, got);
}

View file

@ -26,7 +26,8 @@ void testlib_formatbinaryashex(const char *want, const void *got, size_t n,
size_t i;
uint8_t b;
char *gothex;
if (n == -1ul) n = strlen(want) / 2;
if (n == -1ul)
n = strlen(want) / 2;
gothex = xmalloc(n * 2 + 1);
gothex[n * 2] = '\0';
for (i = 0; i < n; ++i) {

View file

@ -60,12 +60,14 @@ static int AppendWide(wint_t x, int i, int j) {
*/
char *testlib_formatstr(size_t cw, const void *p, int n) {
int i, j = 0;
if (!p) return "NULL";
if (!p)
return "NULL";
i = atomic_fetch_add(&bufi, 1) % STRS;
switch (cw) {
case 1: {
const char *s = p;
if (n < 0) n = s ? strlen(s) : 0;
if (n < 0)
n = s ? strlen(s) : 0;
const char *se = s + n;
APPEND('"');
while (s < se) {
@ -75,13 +77,15 @@ char *testlib_formatstr(size_t cw, const void *p, int n) {
}
case 2: {
const char16_t *s = p;
if (n < 0) n = s ? strlen16(s) : 0;
if (n < 0)
n = s ? strlen16(s) : 0;
const char16_t *se = s + n;
APPEND('u');
APPEND('"');
while (s < se) {
wint_t x = *s++ & 0xffff;
if (IsUtf16Cont(x)) continue;
if (IsUtf16Cont(x))
continue;
if (!IsUcs2(x) && s < se) {
wint_t y = *s++ & 0xffff;
x = MergeUtf16(x, y);
@ -92,7 +96,8 @@ char *testlib_formatstr(size_t cw, const void *p, int n) {
}
case 4: {
const wchar_t *s = p;
if (n < 0) n = s ? wcslen(s) : 0;
if (n < 0)
n = s ? wcslen(s) : 0;
const wchar_t *se = s + n;
APPEND('L');
APPEND('"');

View file

@ -29,10 +29,13 @@
bool testlib_hexequals(const char *want, const void *got, size_t n) {
size_t i;
const unsigned char *p = (const unsigned char *)got;
if (!got) return false;
if (!got)
return false;
for (i = 0; i < n; ++i) {
if (!want[i * 2]) break;
if (i == n) break;
if (!want[i * 2])
break;
if (i == n)
break;
if (p[i] != (kHexToInt[want[i * 2 + 0] & 255] * 16 +
kHexToInt[want[i * 2 + 1] & 255])) {
return false;

View file

@ -20,8 +20,10 @@
#include "libc/testlib/testlib.h"
bool testlib_startswith(size_t cw, const void *s, const void *prefix) {
if (s == prefix) return true;
if (!s || !prefix) return false;
if (s == prefix)
return true;
if (!s || !prefix)
return false;
return cw == sizeof(wchar_t) ? wcsstartswith(s, prefix)
: cw == sizeof(char16_t) ? startswith16(s, prefix)
: startswith(s, prefix);

View file

@ -26,8 +26,10 @@ bool testlib_strcaseequals(size_t cw, const void *s1, const void *s2) {
bool testlib_strncaseequals(size_t cw, const void *s1, const void *s2,
size_t n) {
if (s1 == s2) return true;
if (!s1 || !s2) return false;
if (s1 == s2)
return true;
if (!s1 || !s2)
return false;
return (cw == sizeof(wchar_t) ? wcsncasecmp(s1, s2, n)
: cw == sizeof(char16_t) ? strncasecmp16(s1, s2, n)
: strncasecmp(s1, s2, n)) == 0;

View file

@ -25,8 +25,10 @@ bool testlib_strequals(size_t cw, const void *s1, const void *s2) {
}
bool testlib_strnequals(size_t cw, const void *s1, const void *s2, size_t n) {
if (s1 == s2) return true;
if (!s1 || !s2) return false;
if (s1 == s2)
return true;
if (!s1 || !s2)
return false;
return (cw == sizeof(wchar_t) ? wcsncmp(s1, s2, n)
: cw == sizeof(char16_t) ? strncmp16(s1, s2, n)
: strncmp(s1, s2, n)) == 0;

View file

@ -110,7 +110,8 @@ dontasan int main(int argc, char *argv[]) {
errno = 0;
STRACE("");
STRACE("# setting up once");
if (!IsWindows()) sys_getpid();
if (!IsWindows())
sys_getpid();
testlib_clearxmmregisters();
if (_weaken(SetUpOnce)) {
_weaken(SetUpOnce)();

View file

@ -53,8 +53,10 @@ void testlib_error_enter(const char *file, const char *func) {
ftrace_enabled(-1);
strace_enabled(-1);
pthread_mutex_lock(&testlib_error_lock);
if (!IsWindows()) sys_getpid(); /* make strace easier to read */
if (!IsWindows()) sys_getpid();
if (!IsWindows())
sys_getpid(); /* make strace easier to read */
if (!IsWindows())
sys_getpid();
if (g_testlib_shoulddebugbreak) {
DebugBreak();
}
@ -106,18 +108,23 @@ void testlib_runtestcases(const testfn_t *start, const testfn_t *end,
a->setup(fn);
}
}
if (_weaken(SetUp)) _weaken(SetUp)();
if (_weaken(SetUp))
_weaken(SetUp)();
errno = 0;
if (IsWindows()) SetLastError(0);
if (!IsWindows()) sys_getpid();
if (warmup) warmup();
if (IsWindows())
SetLastError(0);
if (!IsWindows())
sys_getpid();
if (warmup)
warmup();
testlib_clearxmmregisters();
STRACE("");
STRACE("# running test %t on %s@%s", fn, user, host);
(*fn)();
STRACE("");
STRACE("# tearing down %t", fn);
if (!IsWindows()) sys_getpid();
if (!IsWindows())
sys_getpid();
if (_weaken(TearDown)) {
_weaken(TearDown)();
}