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

@ -27,7 +27,8 @@ static intptr_t allprefixed_traverse(unsigned char *top,
struct CritbitNode *q = (void *)(top - 1);
for (int direction = 0; direction < 2; ++direction) {
intptr_t rc = allprefixed_traverse(q->child[direction], callback, arg);
if (rc) return rc;
if (rc)
return rc;
}
return 0;
}
@ -48,14 +49,17 @@ intptr_t critbit0_allprefixed(struct critbit0 *t, const char *prefix,
const size_t ulen = strlen(prefix);
unsigned char *p = t->root;
unsigned char *top = p;
if (!p) return 0;
if (!p)
return 0;
while (1 & (intptr_t)p) {
struct CritbitNode *q = (void *)(p - 1);
unsigned char c = 0;
if (q->byte < ulen) c = ubytes[q->byte];
if (q->byte < ulen)
c = ubytes[q->byte];
const int direction = (1 + (q->otherbits | c)) >> 8;
p = q->child[direction];
if (q->byte < ulen) top = p;
if (q->byte < ulen)
top = p;
}
for (size_t i = 0; i < ulen; ++i) {
if (p[i] != ubytes[i]) {

View file

@ -30,11 +30,13 @@ bool critbit0_contains(struct critbit0 *t, const char *u) {
const unsigned char *ubytes = (void *)u;
const size_t ulen = strlen(u);
unsigned char *p = t->root;
if (!p) return 0;
if (!p)
return 0;
while (1 & (intptr_t)p) {
struct CritbitNode *q = (void *)(p - 1);
unsigned char c = 0;
if (q->byte < ulen) c = ubytes[q->byte];
if (q->byte < ulen)
c = ubytes[q->byte];
const int direction = (1 + (q->otherbits | c)) >> 8;
p = q->child[direction];
}

View file

@ -36,17 +36,20 @@ bool critbit0_delete(struct critbit0 *t, const char *u) {
void **whereq = 0;
struct CritbitNode *q = 0;
int direction = 0;
if (!p) return false;
if (!p)
return false;
while (1 & (intptr_t)p) {
whereq = wherep;
q = (void *)(p - 1);
unsigned char c = 0;
if (q->byte < ulen) c = ubytes[q->byte];
if (q->byte < ulen)
c = ubytes[q->byte];
direction = (1 + (q->otherbits | c)) >> 8;
wherep = q->child + direction;
p = *wherep;
}
if (0 != strcmp(u, (const char *)p)) return false;
if (0 != strcmp(u, (const char *)p))
return false;
free(p), p = NULL;
if (!whereq) {
t->root = NULL;

View file

@ -53,7 +53,8 @@ int critbit0_emplace(struct critbit0 *t, const void *u, size_t ulen) {
while (1 & (intptr_t)p) {
struct CritbitNode *q = (void *)(p - 1);
unsigned char c = 0;
if (q->byte < ulen) c = ubytes[q->byte];
if (q->byte < ulen)
c = ubytes[q->byte];
const int direction = (1 + (q->otherbits | c)) >> 8;
p = q->child[direction];
}
@ -86,12 +87,16 @@ DifferentByteFound:
void **wherep = &t->root;
for (;;) {
unsigned char *wp = *wherep;
if (!(1 & (intptr_t)wp)) break;
if (!(1 & (intptr_t)wp))
break;
struct CritbitNode *q = (void *)(wp - 1);
if (q->byte > newbyte) break;
if (q->byte == newbyte && q->otherbits > newotherbits) break;
if (q->byte > newbyte)
break;
if (q->byte == newbyte && q->otherbits > newotherbits)
break;
unsigned char c2 = 0;
if (q->byte < ulen) c2 = ubytes[q->byte];
if (q->byte < ulen)
c2 = ubytes[q->byte];
const int direction = (1 + (q->otherbits | c2)) >> 8;
wherep = q->child + direction;
}

View file

@ -31,11 +31,13 @@ char *critbit0_get(struct critbit0 *t, const char *u) {
const unsigned char *ubytes = (void *)u;
const size_t ulen = strlen(u);
unsigned char *p = t->root;
if (!p) return 0;
if (!p)
return 0;
while (1 & (intptr_t)p) {
struct CritbitNode *q = (void *)(p - 1);
unsigned char c = 0;
if (q->byte < ulen) c = ubytes[q->byte];
if (q->byte < ulen)
c = ubytes[q->byte];
const int direction = (1 + (q->otherbits | c)) >> 8;
p = q->child[direction];
}

View file

@ -65,10 +65,12 @@ static void DeferFunction(struct StackFrame *frame, void *fn, void *arg) {
t = __get_tls();
g = t->tib_garbages;
if (UNLIKELY(!g)) {
if (!(g = malloc(sizeof(struct Garbages)))) notpossible;
if (!(g = malloc(sizeof(struct Garbages))))
notpossible;
g->i = 0;
g->n = 4;
if (!(g->p = malloc(g->n * sizeof(struct Garbage)))) notpossible;
if (!(g->p = malloc(g->n * sizeof(struct Garbage))))
notpossible;
t->tib_garbages = g;
} else if (UNLIKELY(g->i == g->n)) {
p2 = g->p;

View file

@ -30,14 +30,16 @@ static size_t capacity;
static size_t __lenenv(char **env) {
char **p = env;
while (*p) ++p;
while (*p)
++p;
return p - env;
}
static char **__growenv(char **a) {
size_t n, c;
char **b, **p;
if (!a) a = environ;
if (!a)
a = environ;
n = a ? __lenenv(a) : 0;
c = MAX(8ul, n) << 1;
if ((b = malloc(c * sizeof(char *)))) {

View file

@ -37,7 +37,8 @@ int setenv(const char *name, const char *value, int overwrite) {
int rc;
char *s;
size_t n, m;
if (!name || !*name || !value || strchr(name, '=')) return einval();
if (!name || !*name || !value || strchr(name, '='))
return einval();
if ((s = malloc((n = strlen(name)) + 1 + (m = strlen(value)) + 1))) {
memcpy(mempcpy(mempcpy(s, name, n), "=", 1), value, m + 1);
rc = __putenv(s, overwrite);

View file

@ -31,7 +31,8 @@ char *strndup(const char *s, size_t n) {
char *s2;
size_t len = strnlen(s, n);
if ((s2 = malloc(len + 1))) {
if (len) memcpy(s2, s, len);
if (len)
memcpy(s2, s, len);
s2[len] = '\0';
return s2;
}