diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..ea6e5d408 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,69 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}" + ], + "cStandard": "c11", + "cppStandard": "c++11", + "compilerPath": "${workspaceFolder}/o/third_party/gcc/bin/x86_64-linux-musl-gcc", + "forcedInclude": ["${workspaceFolder}/.vscode/vscode.h"], + "defines": [ + "libcesque=", + "pureconst=", + "paramsnonnull(x)=", + "alignas(x)", + "alignof(x)", + "artificial=", + "nodiscard=", + "mayalias=", + "forceinline=", + "forcealign(x)=", + "scanfesque(x)=", + "strftimeesque(x)=", + "wontreturn=", + "textreal=", + "mallocesque=", + "callocesque=", + "vallocesque=", + "reallocesque=", + "strlenesque=", + "memcpyesque=", + "hasatleast=", + "noinline=", + "textexit=", + "returnstwice=", + "textwindows=", + "privileged=", + "compatfn=", + "noinstrument=", + "nodebuginfo=", + "interruptfn=", + "optimizespeed=", + "forcealignargpointer=", + "noasan=", + "noubsan=", + "testonly=", + "donothing=", + "nosideeffect=", + "unreachable=", + "thatispacked=", + "nothrow=", + "nocallback=", + "relegated=", + "hidden=", + "textstartup=", + "initarray=", + "returnsnonnull=", + "returnspointerwithnoaliases=", + "printfesque(x)=", + "attributeallocsize(x)=", + "returnsaligned(x)=", + "attributeallocalign(x)=", + "nullterminated(x)=" + ] + } + ], + "version": 4 +} diff --git a/.vscode/vscode.h b/.vscode/vscode.h new file mode 100644 index 000000000..a01ec51d8 --- /dev/null +++ b/.vscode/vscode.h @@ -0,0 +1,168 @@ +#define __VSCODE_INTELLISENSE__ 1 +#define __LP64__ /* TODO: this is a lazy kludge */ +#include "libc/integral/normalize.inc" + +#if 0 +#define __VSCODE_INTELLISENSE__ 1 +#define __BIGGEST_ALIGNMENT__ 1 +#define __CHAR_MAX__ 0x7F +#define __SCHAR_MAX__ __CHAR_MAX__ +#define __SHRT_MAX__ 0x7FFF +#define __INT_MAX__ 0x7FFFFFFF +#define __LONG_MAX__ 0x7FFFFFFFFFFFFFFF +#define __LONG_LONG_MAX__ __LONG_MAX__ +#define __CHAR_MIN__ -((__CHAR_MAX__)+1) +#define __SHRT_MIN__ -((__SHRT_MAX__)+1) +#define __INT_MIN__ -((__INT_MAX__)+1) +#define __LONG_MIN__ -((__LONG_MAX__)+1) +#define __LONG_LONG_MIN__ -((__LONG_LONG_MAX__)+1) +#define __UCHAR_MAX__ 0xFF +#define __USHRT_MAX__ 0xFFFF +#define __UINT_MAX__ 0xFFFFFFFF +#define __ULONG_MAX__ 0xFFFFFFFFFFFFFFFF +#define __SIZE_MAX__ __ULONG_MAX__ +#define __SSIZE_MAX__ __LONG_MAX__ +#define __UINTPTR_MAX__ __SIZE_MAX__ +#define __INTPTR_MAX__ __SSIZE_MAX__ +#define __WCHAR_MAX__ __UINT_MAX__ +#define __PTRDIFF_MAX__ __UINTPTR_MAX__ +#define __INTMAX_MAX__ __ULONG_MAX__ +#define __SIZEOF_POINTER__ 8 +#define __SIZEOF_SHORT__ 2 +#define __SIZEOF_INT__ 4 +#define __SIZEOF_LONG__ 8 +#define __SIZEOF_LONG_LONG__ 8 +#define __SIZEOF_PTRDIFF_T__ 8 +#define __SIZEOF_SIZE_T__ 8 +#define __SIZEOF_WCHAR_T__ 4 +#define __SIZEOF_WINT_T__ 4 +#define __SIZEOF_FLOAT__ 4 +#define __SIZEOF_FLOAT128__ 16 +#define __SIZEOF_DOUBLE__ 8 +#define __SIZEOF_FLOAT80__ 10 +#define __SIZEOF_LONG_DOUBLE__ 16 +#define __FLT_MAX__ 1 +#define __DBL_MAX__ 1 + +#define __INT_LEAST8_TYPE__ signed char +#define __INT_LEAST16_TYPE__ signed short +#define __INT_LEAST32_TYPE__ signed int +#define __INT_LEAST64_TYPE__ signed long long +#define __UINT_LEAST8_TYPE__ unsigned char +#define __UINT_LEAST16_TYPE__ unsigned short +#define __UINT_LEAST32_TYPE__ unsigned int +#define __UINT_LEAST64_TYPE__ unsigned long long + +#define __UINT8_MAX__ __UCHAR_MAX__ +#define __UINT16_MAX__ __USHRT_MAX__ +#define __UINT32_MAX__ __UINT_MAX__ +#define __UINT64_MAX__ __ULONG_MAX__ + +#define __INT8_MAX__ __CHAR_MAX__ +#define __INT16_MAX__ __SHRT_MAX__ +#define __INT32_MAX__ __INT_MAX__ +#define __INT64_MAX__ __LONG_MAX__ + +#define ATEXIT_MAX 1 +#define STACKSIZE 0x10000 +#define ARG_MAX 255 +#define OPEN_MAX 0x7FFF +#define CHAR_BIT 7 +#define NSIG 1 +#define NULL (0) +#define false 0 +#define true (!(false)) +#define COSMOPOLITAN_C_START_ +#define COSMOPOLITAN_C_END_ +#define PAGESIZE 0x1000 +#define BIGPAGESIZE 0x10000 +#define NAME_MAX 255 + +#define SWITCHEROO(...) 0 + +extern unsigned g_loglevel; + +typedef void * va_list; + +#define va_start(...) 0 +#define va_end(...) 0 +#define va_arg(x, y) (y)(0) + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +#define int64_t long long +#define int128_t int64_t +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef unsigned long long uint128_t; + +typedef int errno_t; +typedef uint64_t size_t; +typedef unsigned long long ssize_t; +typedef uint64_t uintptr_t; +typedef long long intptr_t; + +typedef unsigned long long uintmax_t; +typedef long long intmax_t; + +typedef uint32_t bool32; + +#ifndef __cplusplus +typedef uint8_t bool; +typedef uint16_t char16_t; +typedef uint32_t char32_t; +#endif /* __cplusplus */ + +typedef char32_t wint_t; +typedef char32_t wchar_t; +typedef struct { int ax, dx; } axdx_t; + +/* duplicate and replace xmmintrin.internal.h to fix it for IntelliSense + * SEE: <> */ + +#define _Vector_size(x) __attribute__(( vector_size( x ) )) + +#define IMAGE_BASE_VIRTUAL 0x400000 +#define __SIGACTION(...) (0) +#define VEIL(x, y) (y) +#define STATIC_YOINK(x) +#define BUFSIZ 1 +#define FRAMESIZE 0x10000 +#define PATH_MAX 252 +#define concat(x, y, z) 0 +#define CONCAT(a, b, c, d, e) 0 +#define shuffle(...) 0 +#define reverse(x, y) 0 +#define atomic_load(...) 0 +#define atomic_store(...) 0 +#define autotype(x) int + +#define _Generic_(...) (void*)(0) +#define _Generic(...) _Generic_ +#define _Alignas(...) +#define _Section(...) + +#define offsetof(x, y) 0 +#define cmpxchg(...) 0 +#define lockxchg(...) 0 +#define lockcmpxchg(...) 0 +#define xgetbv(...) 0 +#define rdmsr(...) 0 +#define INITIALIZER(...) struct _dummy +#define __far +#define tinystrstr(...) 0 +#define BENCHLOOP(...) 0 + +#ifdef __hook +#undef __hook +#endif /* __hook */ + +#ifdef UriKeyval +#undef UriKeyval +#endif /* UriKeyval */ + +#define _Static_assert(...) 0 +#endif /* 0 */ diff --git a/dsp/tty/quant.h b/dsp/tty/quant.h index d60e5f36a..575c309ba 100644 --- a/dsp/tty/quant.h +++ b/dsp/tty/quant.h @@ -72,6 +72,7 @@ void ttyquantsetup(enum TtyQuantizationAlgorithm, enum TtyQuantizationChannels, extern char *ttyraster(char *, const struct TtyRgb *, size_t, size_t, struct TtyRgb, struct TtyRgb); +#ifndef ttyquant #define ttyquant() (&g_ttyquant_) #define TTYQUANT() VEIL("r", &g_ttyquant_) #define rgb2tty(...) (ttyquant()->rgb2tty(__VA_ARGS__)) @@ -81,6 +82,7 @@ extern char *ttyraster(char *, const struct TtyRgb *, size_t, size_t, #define setbg(...) (ttyquant()->setbg(__VA_ARGS__)) #define setfg(...) (ttyquant()->setfg(__VA_ARGS__)) #define setbgfg(...) (ttyquant()->setbgfg(__VA_ARGS__)) +#endif /* ttyquant */ forceinline bool ttyeq(struct TtyRgb x, struct TtyRgb y) { return x.r == y.r && x.g == y.g && x.b == y.b; diff --git a/libc/alg/arraylist.internal.h b/libc/alg/arraylist.internal.h index 6012fe507..3b7a5c8be 100644 --- a/libc/alg/arraylist.internal.h +++ b/libc/alg/arraylist.internal.h @@ -28,6 +28,7 @@ #define append(ARRAYLIST, ITEM) concat((ARRAYLIST), (ITEM), 1) +#ifndef concat #define concat(ARRAYLIST, ITEM, COUNT) \ ({ \ autotype(ARRAYLIST) List = (ARRAYLIST); \ @@ -43,6 +44,7 @@ } \ (ssize_t)(Idx); \ }) +#endif /* concat */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_ALG_ARRAYLIST_H_ */ diff --git a/libc/alg/arraylist2.internal.h b/libc/alg/arraylist2.internal.h index b78008ec7..e86d3a402 100644 --- a/libc/alg/arraylist2.internal.h +++ b/libc/alg/arraylist2.internal.h @@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_ #define APPEND(LIST_P, LIST_I, LIST_N, ITEM) \ CONCAT(LIST_P, LIST_I, LIST_N, ITEM, 1) +#ifndef CONCAT #define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \ ({ \ autotype(LIST_P) ListP = (LIST_P); \ @@ -31,6 +32,7 @@ COSMOPOLITAN_C_START_ } \ Entry; \ }) +#endif /* CONCAT */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/alg/reverse.h b/libc/alg/reverse.h index a782ec7ff..598f65826 100644 --- a/libc/alg/reverse.h +++ b/libc/alg/reverse.h @@ -11,6 +11,7 @@ * @return pointer to start of array * @see ARRAYLEN() */ +#ifndef reverse #define reverse(ARRAY, COUNT) \ ({ \ autotype(&(ARRAY)[0]) Array = (ARRAY); \ @@ -26,6 +27,7 @@ } \ Array; \ }) +#endif /* reverse */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_ALG_REVERSE_H_ */ diff --git a/libc/alg/shuffle.h b/libc/alg/shuffle.h index 43e55862f..027675a4f 100644 --- a/libc/alg/shuffle.h +++ b/libc/alg/shuffle.h @@ -11,6 +11,7 @@ * @param n is the number of items in A * @see ARRAYLEN() */ +#ifndef shuffle #define shuffle(R, A, n) \ do { \ autotype(A) Array = (A); \ @@ -18,6 +19,7 @@ xchg(&Array[i], &Array[R() % (i + 1)]); \ } \ } while (0) +#endif /* shuffle */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_RAND_SHUFFLE_H_ */ diff --git a/libc/bits/bits.h b/libc/bits/bits.h index 86b148e2e..e596f40d1 100644 --- a/libc/bits/bits.h +++ b/libc/bits/bits.h @@ -174,6 +174,7 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); * @see Intel's Six-Thousand Page Manual V.3A Β§8.2.3.1 * @see atomic_store() */ +#ifndef atomic_load #define atomic_load(MEM) \ ({ \ autotype(MEM) Mem = (MEM); \ @@ -181,6 +182,7 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); asm("mov\t%1,%0" : "=r"(Reg) : "m"(*Mem)); \ Reg; \ }) +#endif /* atomic_load */ /** * Saves scalar to memory w/ one operation. @@ -198,6 +200,7 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); * @see Intel Six-Thousand Page Manual Manual V.3A Β§8.2.3.1 * @see atomic_load() */ +#ifndef atomic_store #define atomic_store(MEM, VAL) \ ({ \ autotype(VAL) Val = (VAL); \ @@ -205,6 +208,7 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); asm("mov%z1\t%1,%0" : "=m"(*Mem) : "r"(Val)); \ Val; \ }) +#endif /* atomic_store */ #define bts(MEM, BIT) __BitOp("bts", BIT, MEM) /** bit test and set */ #define btr(MEM, BIT) __BitOp("btr", BIT, MEM) /** bit test and reset */ @@ -232,6 +236,7 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); * @return LOCALVAR[0] * @see xchg() */ +#ifndef lockxchg #define lockxchg(MEMORY, LOCALVAR) \ ({ \ _Static_assert( \ @@ -239,7 +244,16 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); asm("xchg\t%0,%1" : "+%m"(*(MEMORY)), "+r"(*(LOCALVAR))); \ *(LOCALVAR); \ }) +#endif /* lockxchg */ +/** + * Compares and exchanges. + * + * @param IFTHING is uintπ‘˜_t[hasatleast 1] where π‘˜ ∈ {8,16,32,64} + * @return true if value was exchanged, otherwise false + * @see lockcmpxchg() + */ +#ifndef cmpxchg #define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ ({ \ bool DidIt; \ @@ -252,7 +266,16 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); : "cc"); \ DidIt; \ }) +#endif /* cmpxchg */ +/** + * Compares and exchanges w/ one operation. + * + * @param IFTHING is uintπ‘˜_t[hasatleast 1] where π‘˜ ∈ {8,16,32,64} + * @return true if value was exchanged, otherwise false + * @see lockcmpxchg() + */ +#ifndef lockcmpxchg #define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ ({ \ bool DidIt; \ @@ -265,27 +288,32 @@ bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); : "cc"); \ DidIt; \ }) +#endif /* lockcmpxchg */ /** * Gets value of extended control register. */ +#ifndef xgetbv #define xgetbv(xcr_register_num) \ ({ \ unsigned hi, lo; \ asm("xgetbv" : "=d"(hi), "=a"(lo) : "c"(cr_register_num)); \ (uint64_t) hi << 32 | lo; \ }) +#endif /* xgetbv */ /** * Reads model-specific register. * @note programs running as guests won't have authorization */ +#ifndef rdmsr #define rdmsr(msr) \ ({ \ uint32_t lo, hi; \ asm volatile("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr)); \ (uint64_t) hi << 32 | lo; \ }) +#endif rdmsr /** * Writes model-specific register. diff --git a/libc/bits/initializer.internal.h b/libc/bits/initializer.internal.h index a6b90a842..6aa1708de 100644 --- a/libc/bits/initializer.internal.h +++ b/libc/bits/initializer.internal.h @@ -7,6 +7,7 @@ /** * Teleports code fragment inside _init(). */ +#ifndef INITIALIZER #define INITIALIZER(PRI, NAME, CODE) \ asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \ "call\t" #NAME "\n\t" \ @@ -15,6 +16,7 @@ CODE; \ asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \ } +#endif /* INITIALIZER */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ */ diff --git a/libc/bits/safemacros.h b/libc/bits/safemacros.h index cd5718bf0..01254d35b 100644 --- a/libc/bits/safemacros.h +++ b/libc/bits/safemacros.h @@ -15,7 +15,8 @@ const char *emptytonull(const char *); const char *firstnonnull(const char *, const char *); uint64_t(unsignedsubtract)(uint64_t, uint64_t) pureconst; -#if !defined(__STRICT_ANSI__) && defined(__GNUC__) +#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && \ +!defined(__VSCODE_INTELLISENSE__) #define min(x, y) \ ({ \ diff --git a/libc/calls/calls.h b/libc/calls/calls.h index c57a840c1..0198a637b 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -251,6 +251,7 @@ int vdprintf(int, const char *, va_list) paramsnonnull(); void _init_onntconsoleevent(void); void _init_wincrash(void); +#ifndef __SIGACTION #define __SIGACTION(FN, SIG, ...) \ ({ \ if (SupportsWindows()) { \ @@ -279,6 +280,7 @@ void _init_wincrash(void); } \ (FN)(SIG, __VA_ARGS__); \ }) +#endif #define dprintf(FD, FMT, ...) (dprintf)(FD, PFLINK(FMT), ##__VA_ARGS__) #define sigaction(SIG, ACT, OLD) __SIGACTION(sigaction, SIG, ACT, OLD) diff --git a/libc/calls/internal.h b/libc/calls/internal.h index eb8a59586..c9d4161f3 100644 --- a/libc/calls/internal.h +++ b/libc/calls/internal.h @@ -36,25 +36,29 @@ struct IoctlPtmGet { char workername[16]; }; +enum FdKind { + kFdEmpty, + kFdFile, + kFdSocket, + kFdProcess, + kFdConsole, + kFdSerial, + kFdZip, + kFdEpoll, + kFdReserved +}; + +struct Fd { + int64_t handle; + int64_t extra; + int kind; + unsigned flags; +}; + struct Fds { size_t f; // lowest free slot size_t n; // monotonic capacity - struct Fd { - int64_t handle; - int64_t extra; - enum FdKind { - kFdEmpty, - kFdFile, - kFdSocket, - kFdProcess, - kFdConsole, - kFdSerial, - kFdZip, - kFdEpoll, - kFdReserved, - } kind; - unsigned flags; - } * p; + struct Fd * p; struct Fd __init_p[OPEN_MAX]; }; @@ -77,7 +81,7 @@ forceinline bool __isfdopen(int fd) { return 0 <= fd && fd < g_fds.n && g_fds.p[fd].kind != kFdEmpty; } -forceinline bool __isfdkind(int fd, enum FdKind kind) { +forceinline bool __isfdkind(int fd, int kind) { return 0 <= fd && fd < g_fds.n && g_fds.p[fd].kind == kind; } diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index 4aba36a04..67eedd1e3 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -46,6 +46,7 @@ union metasigaction { struct sigaction_xnu_out xnu_out; }; +#ifndef SWITCHEROO #define SWITCHEROO(S1, S2, A, B, C, D) \ do { \ autotype((S2).A) a = (typeof((S2).A))(S1).A; \ @@ -60,6 +61,7 @@ union metasigaction { memset(&((S2).D), 0, sizeof((S2).D)); \ memcpy(&((S2).D), &d, MIN(sizeof(d), sizeof((S2).D))); \ } while (0); +#endif static void sigaction$cosmo2native(union metasigaction *sa) { if (!sa) return; diff --git a/libc/calls/stat2linux.c b/libc/calls/stat2linux.c index 1a3b11304..ba6b0ea66 100644 --- a/libc/calls/stat2linux.c +++ b/libc/calls/stat2linux.c @@ -20,6 +20,7 @@ #include "libc/calls/struct/metastat.internal.h" #include "libc/dce.h" +#ifndef SWITCHEROO #define SWITCHEROO(S1, S2, A, B, C, D, E, F, G, H, I, J, K, L, M) \ do { \ autotype((S2).A) a = (typeof((S2).A))(S1).A; \ @@ -49,6 +50,7 @@ (S2).L = l; \ (S2).M = m; \ } while (0); +#endif static textstartup void __stat2linux_xnu(union metastat *ms) { SWITCHEROO(ms->xnu, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid, diff --git a/libc/log/check.h b/libc/log/check.h index 38ef26365..f7b0b0f73 100644 --- a/libc/log/check.h +++ b/libc/log/check.h @@ -47,6 +47,9 @@ COSMOPOLITAN_C_START_ VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \ } while (0) +#if defined(__VSCODE_INTELLISENSE__) +#define __CHK(...) +#else #define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \ do { \ autotype(GOT) Got = (GOT); \ @@ -61,7 +64,11 @@ COSMOPOLITAN_C_START_ unreachable; \ } \ } while (0) +#endif /* defined(__VSCODE_INTELLISENSE__) */ +#if defined(__VSCODE_INTELLISENSE__) +#define __DCHK(...) +#else #ifdef NDEBUG #define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \ do { \ @@ -74,7 +81,8 @@ COSMOPOLITAN_C_START_ #else #define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \ __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__) -#endif +#endif /* NDEBUG */ +#endif /* defined(__VSCODE_INTELLISENSE__) */ #ifdef NDEBUG #define __DCHK_ALIGNED(BYTES, VAR) diff --git a/libc/runtime/gc.h b/libc/runtime/gc.h index 46aec7c4c..9ca8bec93 100644 --- a/libc/runtime/gc.h +++ b/libc/runtime/gc.h @@ -30,6 +30,7 @@ void gclongjmp(jmp_buf, int) nothrow wontreturn paramsnonnull(); /** * Calls FN(ARG) when function returns. */ +#ifndef __VSCODE_INTELLISENSE__ #define defer(FN, ARG) \ ({ \ autotype(ARG) Arg = (ARG); \ @@ -39,6 +40,7 @@ void gclongjmp(jmp_buf, int) nothrow wontreturn paramsnonnull(); asm volatile("" : "+g"(Arg) : : "memory"); \ Arg; \ }) +#endif /* __VSCODE_INTELLISENSE__ */ void __defer(struct StackFrame *, void *, void *) hidden paramsnonnull((1, 2)); diff --git a/libc/str/tpdecodecb.internal.h b/libc/str/tpdecodecb.internal.h index 6ec04a388..0bb8f1915 100644 --- a/libc/str/tpdecodecb.internal.h +++ b/libc/str/tpdecodecb.internal.h @@ -27,7 +27,7 @@ forceinline int tpdecodecb(wint_t *out, int first, if ((cb & 0b11000000) == 0b10000000) { wc = wc << 6 | (cb & 0b00111111); } else { - if (out) *out = u'οΏ½'; + if (out) *out = u'\xFFFD'; return -1; } } diff --git a/libc/testlib/bench.h b/libc/testlib/bench.h index eea7c6e30..c64f8c9f8 100644 --- a/libc/testlib/bench.h +++ b/libc/testlib/bench.h @@ -8,6 +8,7 @@ COSMOPOLITAN_C_START_ * @fileoverview Microbenchmarking tools. */ +#ifndef BENCHLOOP #define BENCHLOOP(START, STOP, N, INIT, EXPR) \ ({ \ unsigned long Iter, Count; \ @@ -22,6 +23,7 @@ COSMOPOLITAN_C_START_ } \ Average; \ }) +#endif /* BENCHLOOP */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/net/http/uri.h b/net/http/uri.h index 7d8c42400..9cb4e224e 100644 --- a/net/http/uri.h +++ b/net/http/uri.h @@ -18,17 +18,42 @@ enum UriScheme { kUriSchemeS3 }; +struct UriSlice { + /* + * !i && !n means absent + * i && !n means empty + */ + unsigned i, n; +}; + +struct UriSlices { + unsigned i, n; + struct UriSlice *p; +}; + +struct UriKeyval { + struct UriSlice k, v; +}; + +struct UriKeyvals { + unsigned i, n; + struct UriKeyval * p; +}; + +struct UriRef { + unsigned r; +}; + +struct UriRefs { + unsigned i, n; + struct UriRef * p; +}; + struct Uri { /* * e.g. "", "http", "sip", "http", "dns+http", etc. */ - struct UriSlice { - /* - * !i && !n means absent - * i && !n means empty - */ - unsigned i, n; - } scheme; + struct UriSlice scheme; /* * Holds remainder for exotic URI schemes, e.g. data. @@ -60,18 +85,10 @@ struct Uri { * - memcmp("/dir", p + segs.p[0].i, segs.p[0].n) == 0 * - memcmp("/index.html", p + segs.p[1].i, segs.p[1].n) == 0 */ - struct UriSlices { - unsigned i, n; - struct UriSlice *p; - } segs; + struct UriSlices segs; /* e.g. ;lr;isup-oli=00;day=tuesday */ - struct UriKeyvals { - unsigned i, n; - struct UriKeyval { - struct UriSlice k, v; - } * p; - } params; + struct UriKeyvals params; /* * e.g. /dir;super=rare/index.html @@ -79,12 +96,7 @@ struct Uri { * let 𝑖 ∈ [0,params.i) * paramsegs.p[𝑖].r ∈ [0,segs.i] */ - struct UriRefs { - unsigned i, n; - struct UriRef { - unsigned r; - } * p; - } paramsegs; + struct UriRefs paramsegs; /* e.g. ?boop&subject=project%20x&lol=cat */ struct UriKeyvals queries; diff --git a/tool/build/lib/elfwriter.h b/tool/build/lib/elfwriter.h index a9baaa94d..309d15ce0 100644 --- a/tool/build/lib/elfwriter.h +++ b/tool/build/lib/elfwriter.h @@ -8,6 +8,29 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +struct ElfWriterSyms { + size_t i, n; + Elf64_Sym *p; +}; + +enum ElfWriterSymOrder { + kElfWriterSymSection, + kElfWriterSymLocal, + kElfWriterSymGlobal +}; + +struct ElfWriterSymRef { + int slg; + uint32_t sym; +}; + +struct ElfWriterRela { + uint64_t offset; + struct ElfWriterSymRef symkey; + uint32_t type; + int64_t addend; +}; + struct ElfWriter { char *path; char *tmppath; @@ -22,25 +45,10 @@ struct ElfWriter { size_t i, n; Elf64_Shdr *p; } shdrs[1]; - struct ElfWriterSyms { - size_t i, n; - Elf64_Sym *p; - } syms[3][1]; + struct ElfWriterSyms syms[3][1]; struct { size_t i, j, n; - struct ElfWriterRela { - uint64_t offset; - struct ElfWriterSymRef { - enum ElfWriterSymOrder { - kElfWriterSymSection, - kElfWriterSymLocal, - kElfWriterSymGlobal - } slg; - uint32_t sym; - } symkey; - uint32_t type; - int64_t addend; - } * p; + struct ElfWriterRela * p; } relas[1]; struct Interner *strtab; struct Interner *shstrtab; diff --git a/tool/build/lib/fds.h b/tool/build/lib/fds.h index 27d016e90..8899893c9 100644 --- a/tool/build/lib/fds.h +++ b/tool/build/lib/fds.h @@ -4,21 +4,27 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +struct MachineFdClosed { + unsigned fd; + struct MachineFdClosed *next; +}; + +struct MachineFdCb { + int (*close)(int); + ssize_t (*readv)(int, const struct iovec *, int); + ssize_t (*writev)(int, const struct iovec *, int); + int (*ioctl)(int, uint64_t, void *); +}; + +struct MachineFd { + int fd; + struct MachineFdCb * cb; +}; + struct MachineFds { size_t i, n; - struct MachineFd { - int fd; - struct MachineFdCb { - int (*close)(int); - ssize_t (*readv)(int, const struct iovec *, int); - ssize_t (*writev)(int, const struct iovec *, int); - int (*ioctl)(int, uint64_t, void *); - } * cb; - } * p; - struct MachineFdClosed { - unsigned fd; - struct MachineFdClosed *next; - } * closed; + struct MachineFd * p; + struct MachineFdClosed * closed; }; int MachineFdAdd(struct MachineFds *); diff --git a/tool/build/lib/javadown.h b/tool/build/lib/javadown.h index 3a8b7240b..41fc62612 100644 --- a/tool/build/lib/javadown.h +++ b/tool/build/lib/javadown.h @@ -3,17 +3,21 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +struct JavadownTag { + char *tag; + char *text; +}; + +struct JavadownTags { + size_t n; + struct JavadownTag * p; +}; + struct Javadown { bool isfileoverview; char *title; char *text; - struct JavadownTags { - size_t n; - struct JavadownTag { - char *tag; - char *text; - } * p; - } tags; + struct JavadownTags tags; }; struct Javadown *ParseJavadown(const char *, size_t); diff --git a/tool/build/lib/persist.h b/tool/build/lib/persist.h index e903ed55a..731b63b49 100644 --- a/tool/build/lib/persist.h +++ b/tool/build/lib/persist.h @@ -3,16 +3,18 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +struct ObjectArrayParam { + size_t len; + size_t size; + void *pp; +}; + struct ObjectParam { size_t size; void *p; uint32_t *magic; int32_t *abi; - struct ObjectArrayParam { - size_t len; - size_t size; - void *pp; - } * arrays; + struct ObjectArrayParam * arrays; }; void PersistObject(const char *, size_t, const struct ObjectParam *);