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

@ -3,19 +3,19 @@
#include "libc/macros.internal.h"
COSMOPOLITAN_C_START_
__funline unsigned long __strlen(const char *s) {
forceinline unsigned long __strlen(const char *s) {
unsigned long n = 0;
while (*s++) ++n;
return n;
}
__funline int __strcmp(const char *l, const char *r) {
forceinline int __strcmp(const char *l, const char *r) {
size_t i = 0;
while (l[i] == r[i] && r[i]) ++i;
return (l[i] & 255) - (r[i] & 255);
}
__funline char *__stpcpy(char *d, const char *s) {
forceinline char *__stpcpy(char *d, const char *s) {
size_t i;
for (i = 0;; ++i) {
if (!(d[i] = s[i])) {
@ -24,7 +24,7 @@ __funline char *__stpcpy(char *d, const char *s) {
}
}
__funline void *__repstosb(void *di, char al, size_t cx) {
forceinline void *__repstosb(void *di, char al, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
asm("rep stosb"
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
@ -40,7 +40,7 @@ __funline void *__repstosb(void *di, char al, size_t cx) {
#endif
}
__funline void *__repmovsb(void *di, const void *si, size_t cx) {
forceinline void *__repmovsb(void *di, const void *si, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
asm("rep movsb"
: "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di)
@ -57,7 +57,7 @@ __funline void *__repmovsb(void *di, const void *si, size_t cx) {
#endif
}
__funline void *__mempcpy(void *d, const void *s, size_t n) {
forceinline void *__mempcpy(void *d, const void *s, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
((char *)d)[i] = ((const char *)s)[i];
@ -66,7 +66,7 @@ __funline void *__mempcpy(void *d, const void *s, size_t n) {
return (char *)d + n;
}
__funline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
forceinline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
char t;
size_t i, a, b;
i = 0;
@ -85,22 +85,22 @@ __funline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
return p + i;
}
__funline char *__intcpy(char p[hasatleast 21], int64_t x) {
forceinline char *__intcpy(char p[hasatleast 21], int64_t x) {
if (x < 0) *p++ = '-', x = -(uint64_t)x;
return __uintcpy(p, x);
}
__funline char *__fixcpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
forceinline char *__fixcpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
*p = '\0';
return p;
}
__funline char *__hexcpy(char p[hasatleast 17], uint64_t x) {
forceinline char *__hexcpy(char p[hasatleast 17], uint64_t x) {
return __fixcpy(p, x, ROUNDUP(x ? (__builtin_clzll(x) ^ 63) + 1 : 1, 4));
}
__funline const void *__memchr(const void *s, unsigned char c, size_t n) {
forceinline const void *__memchr(const void *s, unsigned char c, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
if (((const unsigned char *)s)[i] == c) {
@ -110,7 +110,7 @@ __funline const void *__memchr(const void *s, unsigned char c, size_t n) {
return 0;
}
__funline char *__strstr(const char *haystack, const char *needle) {
forceinline char *__strstr(const char *haystack, const char *needle) {
size_t i;
for (;;) {
for (i = 0;; ++i) {
@ -123,8 +123,8 @@ __funline char *__strstr(const char *haystack, const char *needle) {
return 0;
}
__funline char16_t *__strstr16(const char16_t *haystack,
const char16_t *needle) {
forceinline char16_t *__strstr16(const char16_t *haystack,
const char16_t *needle) {
size_t i;
for (;;) {
for (i = 0;; ++i) {
@ -137,21 +137,21 @@ __funline char16_t *__strstr16(const char16_t *haystack,
return 0;
}
__funline const char *__strchr(const char *s, unsigned char c) {
forceinline const char *__strchr(const char *s, unsigned char c) {
for (;; ++s) {
if ((*s & 255) == c) return s;
if (!*s) return 0;
}
}
__funline unsigned long __atoul(const char *p) {
forceinline unsigned long __atoul(const char *p) {
int c;
unsigned long x = 0;
while ('0' <= (c = *p++) && c <= '9') x *= 10, x += c - '0';
return x;
}
__funline long __atol(const char *p) {
forceinline long __atol(const char *p) {
int s = *p;
unsigned long x;
if (s == '-' || s == '+') ++p;
@ -160,7 +160,7 @@ __funline long __atol(const char *p) {
return x;
}
__funline void *__memset(void *a, int c, unsigned long n) {
forceinline void *__memset(void *a, int c, unsigned long n) {
char *d = a;
unsigned long i;
for (i = 0; i < n; ++i) {
@ -170,7 +170,7 @@ __funline void *__memset(void *a, int c, unsigned long n) {
return d;
}
__funline void *__memcpy(void *a, const void *b, unsigned long n) {
forceinline void *__memcpy(void *a, const void *b, unsigned long n) {
char *d = a;
unsigned long i;
const char *s = b;
@ -181,7 +181,7 @@ __funline void *__memcpy(void *a, const void *b, unsigned long n) {
return d;
}
__funline void *__memmove(void *a, const void *b, unsigned long n) {
forceinline void *__memmove(void *a, const void *b, unsigned long n) {
char *d = a;
unsigned long i;
const char *s = b;