mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/mem/gc.h"
|
||||
|
||||
void _gc_free(void *p) {
|
||||
free(p);
|
||||
|
|
|
@ -26,32 +26,13 @@ int heapsort_r(void *, size_t, size_t,
|
|||
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
int mergesort_r(void *, size_t, size_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
int tarjan(int, const int (*)[2], int, int[], int[], int *)
|
||||
int _tarjan(int, const int (*)[2], int, int[], int[], int *)
|
||||
paramsnonnull((2, 4)) nocallback dontthrow;
|
||||
|
||||
#define __algalloc returnspointerwithnoaliases dontthrow nocallback dontdiscard
|
||||
|
||||
char *replacestr(const char *, const char *, const char *)
|
||||
char *_replacestr(const char *, const char *, const char *)
|
||||
paramsnonnull() __algalloc;
|
||||
char16_t *replacestr16(const char16_t *, const char16_t *, const char16_t *)
|
||||
paramsnonnull() __algalloc;
|
||||
wchar_t *replacewcs(const wchar_t *, const wchar_t *, const wchar_t *)
|
||||
paramsnonnull() __algalloc;
|
||||
|
||||
char *concatstr(const char *, ...) nullterminated() paramsnonnull() __algalloc;
|
||||
char16_t *concatstr16(const char16_t *, ...) nullterminated()
|
||||
paramsnonnull() __algalloc;
|
||||
wchar_t *concatwcs(const wchar_t *, ...) nullterminated()
|
||||
paramsnonnull() __algalloc;
|
||||
|
||||
int cmpsb(const void *, const void *);
|
||||
int cmpub(const void *, const void *);
|
||||
int cmpsw(const void *, const void *);
|
||||
int cmpuw(const void *, const void *);
|
||||
int cmpsl(const void *, const void *);
|
||||
int cmpul(const void *, const void *);
|
||||
int cmpsq(const void *, const void *);
|
||||
int cmpuq(const void *, const void *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/limits.h"
|
||||
|
@ -26,8 +28,6 @@
|
|||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/arena.h"
|
||||
#include "libc/mem/hook/hook.internal.h"
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -39,7 +39,7 @@
|
|||
#define SIZE 0x2ff80000
|
||||
#define P(i) ((void *)(intptr_t)(i))
|
||||
#define EXCHANGE(HOOK, SLOT) \
|
||||
__arena_hook((intptr_t *)weaken(HOOK), (intptr_t *)(&(SLOT)))
|
||||
__arena_hook((intptr_t *)_weaken(HOOK), (intptr_t *)(&(SLOT)))
|
||||
|
||||
static struct Arena {
|
||||
bool once;
|
||||
|
@ -58,7 +58,7 @@ static struct Arena {
|
|||
} __arena;
|
||||
|
||||
static wontreturn void __arena_die(void) {
|
||||
if (weaken(__die)) weaken(__die)();
|
||||
if (_weaken(__die)) _weaken(__die)();
|
||||
_exit(83);
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,8 @@ static dontinline bool __arena_grow(size_t offset, size_t request) {
|
|||
} else {
|
||||
enomem();
|
||||
}
|
||||
if (weaken(__oom_hook)) {
|
||||
weaken(__oom_hook)(request);
|
||||
if (_weaken(__oom_hook)) {
|
||||
_weaken(__oom_hook)(request);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ static void *__arena_memalign(size_t a, size_t n) {
|
|||
if (a <= sizeof(size_t)) {
|
||||
return __arena_alloc(8, n);
|
||||
} else {
|
||||
return __arena_alloc(2ul << bsrl(a - 1), n);
|
||||
return __arena_alloc(2ul << _bsrl(a - 1), n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ static void *__arena_realloc(void *p, size_t n) {
|
|||
if ((m = __arena_get_size(p)) >= n) {
|
||||
return p;
|
||||
} else if (n <= SIZE) {
|
||||
z = 2ul << bsrl(n - 1);
|
||||
z = 2ul << _bsrl(n - 1);
|
||||
if (__arena.offset[__arena.depth] - m == (o = (intptr_t)p - BASE)) {
|
||||
if (UNLIKELY(o + z > __arena.size)) {
|
||||
if (o + z <= SIZE) {
|
||||
|
@ -205,7 +205,7 @@ static void *__arena_realloc(void *p, size_t n) {
|
|||
__arena.offset[__arena.depth] = o + z;
|
||||
*(size_t *)((char *)p - sizeof(size_t)) = z;
|
||||
return p;
|
||||
} else if ((q = __arena_alloc(1ul << bsfl((intptr_t)p), z))) {
|
||||
} else if ((q = __arena_alloc(1ul << _bsfl((intptr_t)p), z))) {
|
||||
memmove(q, p, m);
|
||||
return q;
|
||||
} else {
|
||||
|
@ -225,7 +225,7 @@ static void *__arena_realloc(void *p, size_t n) {
|
|||
if (n <= 16) {
|
||||
n = 16;
|
||||
} else {
|
||||
n = 2ul << bsrl(n - 1);
|
||||
n = 2ul << _bsrl(n - 1);
|
||||
}
|
||||
return __arena_alloc(16, n);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/buffer.h"
|
||||
#include "libc/runtime/buffer.internal.h"
|
||||
|
||||
/* TODO(jart): delete */
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/buffer.h"
|
||||
#include "libc/runtime/buffer.internal.h"
|
||||
|
||||
/**
|
||||
* Frees memory return by balloc().
|
||||
|
|
27
libc/mem/gc.h
Normal file
27
libc/mem/gc.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
|
||||
#define COSMOPOLITAN_LIBC_MEM_GC_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void *_gc(void *);
|
||||
void *_defer(void *, void *);
|
||||
void __defer(void *, void *, void *);
|
||||
void _gclongjmp(void *, int) dontthrow wontreturn;
|
||||
void _gc_free(void *);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define _gc(THING) _defer((void *)_gc_free, (void *)(THING))
|
||||
#define _defer(FN, ARG) \
|
||||
({ \
|
||||
autotype(ARG) Arg = (ARG); \
|
||||
/* prevent weird opts like tail call */ \
|
||||
asm volatile("" : "+g"(Arg) : : "memory"); \
|
||||
__defer(__builtin_frame_address(0), FN, Arg); \
|
||||
asm volatile("" : "+g"(Arg) : : "memory"); \
|
||||
Arg; \
|
||||
})
|
||||
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */
|
11
libc/mem/gc.internal.h
Normal file
11
libc/mem/gc.internal.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_
|
||||
#include "libc/mem/gc.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define gc(THING) _gc(THING)
|
||||
#define defer(FN, ARG) _defer(FN, ARG)
|
||||
#define gclongjmp(JB, ARG) _gclongjmp(JB, ARG)
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_MEM_GC_INTERNAL_H_ */
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_MEM_IO_H_
|
||||
#define COSMOPOLITAN_LIBC_MEM_IO_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
ssize_t _copyfd(int, int, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_MEM_IO_H_ */
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/arraylist2.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/arraylist2.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
|||
* @return newly allocated memory that must be free()'d or NULL w/ errno
|
||||
* @error ENOMEM, EINVAL
|
||||
*/
|
||||
char *replacestr(const char *s, const char *needle, const char *replacement) {
|
||||
char *_replacestr(const char *s, const char *needle, const char *replacement) {
|
||||
char *p1, *p2, *res_p;
|
||||
size_t left, nlen, rlen, res_i, res_n;
|
||||
if (*needle) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/mem/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
||||
/**
|
||||
|
@ -130,9 +130,9 @@ static bool TarjanConnect(struct Tarjan *t, int v) {
|
|||
* @error ENOMEM
|
||||
* @note Tarjan's Algorithm is O(|V|+|E|)
|
||||
*/
|
||||
int tarjan(int vertex_count, const int (*edges)[2], int edge_count,
|
||||
int out_sorted[], int out_opt_components[],
|
||||
int *out_opt_componentcount) {
|
||||
int _tarjan(int vertex_count, const int (*edges)[2], int edge_count,
|
||||
int out_sorted[], int out_opt_components[],
|
||||
int *out_opt_componentcount) {
|
||||
int i, rc, v, e;
|
||||
struct Tarjan *t;
|
||||
assert(0 <= edge_count && edge_count <= INT_MAX);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue