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

View file

@ -56,7 +56,6 @@
#include "libc/nexgen32e/x86feature.h"
#include "libc/nt/console.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/buffer.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
@ -173,7 +172,7 @@ mode.\n\
#define BALLOC(B, A, N, NAME) \
({ \
INFOF("balloc/%s %,zu bytes", NAME, N); \
balloc(B, A, N); \
*(B) = pvalloc(N); \
})
#define TIMEIT(OUT_NANOS, FORM) \
@ -207,7 +206,7 @@ struct NamedVector {
struct VtFrame {
size_t i, n;
union {
struct GuardedBuffer b;
void *b;
char *bytes;
};
};
@ -266,6 +265,7 @@ static bool emboss_, sobel_;
static volatile int playpid_;
static struct winsize wsize_;
static float hue_, sat_, lit_;
static void *xtcodes_, *audio_;
static struct FrameBuffer fb0_;
static unsigned chans_, srate_;
static volatile bool ignoresigs_;
@ -277,7 +277,6 @@ static openspeaker_f tryspeakerfns_[4];
static int primaries_, lighting_, swing_;
static uint64_t t1, t2, t3, t4, t5, t6, t8;
static const char *sox_, *ffplay_, *patharg_;
static struct GuardedBuffer xtcodes_, audio_;
static struct VtFrame vtframe_[2], *f1_, *f2_;
static struct Graphic graphic_[2], *g1_, *g2_;
static bool yes_, stats_, dither_, ttymode_, istango_;
@ -614,7 +613,7 @@ static char *StartRender(char *vt) {
static void EndRender(char *vt) {
vt += sprintf(vt, "\e[0m");
f2_->n = (intptr_t)vt - (intptr_t)f2_->b.p;
f2_->n = (intptr_t)vt - (intptr_t)f2_->b;
f2_->i = 0;
}
@ -692,7 +691,7 @@ static void RenderIt(void) {
struct TtyRgb bg, fg;
yn = g2_->yn;
xn = g2_->xn;
vt = f2_->b.p;
vt = f2_->b;
p = StartRender(vt);
if (TTYQUANT()->alg == kTtyQuantTrue) {
bg = (struct TtyRgb){0, 0, 0, 0};
@ -708,7 +707,7 @@ static void RenderIt(void) {
fg = (struct TtyRgb){0xff, 0xff, 0xff, 231};
p = stpcpy(p, "\e[48;5;16;38;5;231m");
}
p = ttyraster(p, xtcodes_.p, yn, xn, bg, fg);
p = ttyraster(p, xtcodes_, yn, xn, bg, fg);
if (ttymode_ && stats_) {
bpc = bpf = p - vt;
bpc /= wsize_.ws_row * wsize_.ws_col;
@ -759,7 +758,7 @@ static void RasterIt(void) {
once = true;
}
WriteToFrameBuffer(fb0_.vscreen.yres_virtual, fb0_.vscreen.xres_virtual, buf,
g2_->yn, g2_->xn, g2_->b.p, fb0_.vscreen.yres,
g2_->yn, g2_->xn, g2_->b, fb0_.vscreen.yres,
fb0_.vscreen.xres);
memcpy(fb0_.map, buf, fb0_.size);
}
@ -776,7 +775,7 @@ static void TranscodeVideo(plm_frame_t *pf) {
if (pf1_) pary_ = 1.;
if (pf2_) pary_ = (266 / 64.) * (900 / 1600.);
pary_ *= plm_get_pixel_aspect_ratio(plm_);
YCbCr2RgbScale(g2_->yn, g2_->xn, g2_->b.p, pf->y.height, pf->y.width,
YCbCr2RgbScale(g2_->yn, g2_->xn, g2_->b, pf->y.height, pf->y.width,
(void *)pf->y.data, pf->cr.height, pf->cr.width,
(void *)pf->cb.data, (void *)pf->cr.data, pf->y.height,
pf->y.width, pf->cr.height, pf->cr.width, pf->height,
@ -791,7 +790,7 @@ static void TranscodeVideo(plm_frame_t *pf) {
boxblur(g2_);
break;
case kBlurGaussian:
gaussian(g2_->yn, g2_->xn, g2_->b.p);
gaussian(g2_->yn, g2_->xn, g2_->b);
break;
default:
break;
@ -800,16 +799,16 @@ static void TranscodeVideo(plm_frame_t *pf) {
if (emboss_) emboss(g2_);
switch (sharp_) {
case kSharpSharp:
sharpen(3, g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn);
sharpen(3, g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn);
break;
case kSharpUnsharp:
unsharp(3, g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn);
unsharp(3, g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn);
break;
default:
break;
}
if (dither_ && TTYQUANT()->alg != kTtyQuantTrue) {
dither(g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn);
dither(g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn);
}
});
@ -817,7 +816,7 @@ static void TranscodeVideo(plm_frame_t *pf) {
t3 = 0;
TIMEIT(t4, RasterIt());
} else {
TIMEIT(t3, getxtermcodes(xtcodes_.p, g2_));
TIMEIT(t3, getxtermcodes(xtcodes_, g2_));
TIMEIT(t4, RenderIt());
}
@ -1401,19 +1400,16 @@ static void OnExit(void) {
ttyidentclear(&ti_);
close(infd_), infd_ = -1;
close(outfd_), outfd_ = -1;
bfree(&graphic_[0].b);
bfree(&graphic_[1].b);
bfree(&vtframe_[0].b);
bfree(&vtframe_[1].b);
bfree(&xtcodes_);
bfree(&audio_);
free(graphic_[0].b);
free(graphic_[1].b);
free(vtframe_[0].b);
free(vtframe_[1].b);
free(xtcodes_);
free(audio_);
CloseSpeaker();
}
static void MakeLatencyLittleLessBad(void) {
#ifdef __x86_64__
_peekall();
#endif
LOGIFNEG1(sys_mlockall(MCL_CURRENT));
LOGIFNEG1(nice(-5));
}