Clean up more code

The *NSYNC linked list API is good enough that it deserves to be part of
the C libray, so this change writes an improved version of it which uses
that offsetof() trick from the Linux Kernel. We vendor all of the *NSYNC
tests in third_party which helped confirm the needed refactoring is safe

This change also deletes more old code that didn't pan out. My goal here
is to work towards a vision where the Cosmopolitan core libraries become
less experimental and more focused on curation. This better reflects the
current level of quality we've managed to achieve.
This commit is contained in:
Justine Tunney 2023-07-06 06:57:28 -07:00
parent 88612a2cd7
commit 0a24b4fc3c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
268 changed files with 632 additions and 8688 deletions

57
libc/intrin/dll.h Normal file
View file

@ -0,0 +1,57 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#ifdef COSMO
#define dll_make_first __dll_make_first
#define dll_make_last __dll_make_last
#define dll_remove __dll_remove
#define dll_splice_after __dll_splice_after
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))
struct Dll {
struct Dll *next;
struct Dll *prev;
};
static inline void dll_init(struct Dll *e) {
e->next = e;
e->prev = e;
}
static inline int dll_is_empty(struct Dll *list) {
return !list;
}
static inline struct Dll *dll_last(struct Dll *list) {
return list;
}
static inline struct Dll *dll_first(struct Dll *list) {
struct Dll *first = 0;
if (list) first = list->next;
return first;
}
static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
struct Dll *next = 0;
if (e != list) next = e->next;
return next;
}
static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
struct Dll *prev = 0;
if (e != list->next) prev = e->prev;
return prev;
}
void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMO */
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */