Make more fixes and improvements

- Fix Makefile flaking due to ZIPOBJ_FLAGS generation
- Make printf() floating point and gdtoa thread safe
- Polish up the runit / runitd programs some more
- Prune some more makefile dependencies
This commit is contained in:
Justine Tunney 2022-06-13 11:02:13 -07:00
parent 3c285337a2
commit a3865ecc3c
61 changed files with 316 additions and 132 deletions

View file

@ -348,9 +348,8 @@ typedef struct ThInfo {
#define Bcopy(x, y) \
memcpy(&x->sign, &y->sign, y->wds * sizeof(ULong) + 2 * sizeof(int))
hidden extern char *__gdtoa_dtoa_result;
hidden extern const double __gdtoa_bigtens[];
hidden extern const double __gdtoa_tens[];
hidden extern const double __gdtoa_bigtens[];
hidden extern const double __gdtoa_tinytens[];
hidden extern const unsigned char __gdtoa_hexdig[];
hidden extern const char *const __gdtoa_InfName[6];

30
third_party/gdtoa/lock.c vendored Normal file
View file

@ -0,0 +1,30 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/pthread.h"
#include "third_party/gdtoa/lock.h"
static pthread_mutex_t __gdtoa_lock_obj;
int(__gdtoa_lock)(void) {
return pthread_mutex_lock(&__gdtoa_lock_obj);
}
int(__gdtoa_unlock)(void) {
return pthread_mutex_unlock(&__gdtoa_lock_obj);
}

21
third_party/gdtoa/lock.h vendored Normal file
View file

@ -0,0 +1,21 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_GDTOA_LOCK_H_
#define COSMOPOLITAN_THIRD_PARTY_GDTOA_LOCK_H_
#include "libc/intrin/nopl.h"
#include "libc/nexgen32e/threaded.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int __gdtoa_lock(void);
int __gdtoa_unlock(void);
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__)
#define __gdtoa_lock() _NOPL0("__threadcalls", __gdtoa_lock)
#define __gdtoa_unlock() _NOPL0("__threadcalls", __gdtoa_unlock)
#else
#define __gdtoa_lock() (__threaded ? __gdtoa_lock() : 0)
#define __gdtoa_unlock() (__threaded ? __gdtoa_unlock() : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_GDTOA_LOCK_H_ */

View file

@ -33,6 +33,7 @@
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "third_party/gdtoa/gdtoa.internal.h"
#include "third_party/gdtoa/lock.h"
/* clang-format off */
static ThInfo TI0;
@ -46,68 +47,62 @@ __gdtoa_Brelease(Bigint *rv)
}
static void
Bclear(void)
__gdtoa_Bclear(void)
{
int i;
__gdtoa_lock();
for (i = 0; i < ARRAYLEN(TI0.Freelist); ++i)
__gdtoa_Brelease(TI0.Freelist[i]);
bzero(&TI0.Freelist, sizeof(TI0.Freelist));
__gdtoa_Brelease(TI0.P5s);
bzero(&TI0, sizeof(TI0));
__gdtoa_unlock();
}
__attribute__((__constructor__)) static void
__gdtoa_Binit(void)
{
atexit(__gdtoa_Bclear);
TI0.P5s = __gdtoa_i2b(625);
TI0.P5s->next = 0;
}
Bigint *
__gdtoa_Balloc(int k)
{
#if 0
int x;
Bigint *rv;
x = 1 << k;
rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(ULong));
rv->k = k;
rv->maxwds = x;
rv->sign = 0;
rv->wds = 0;
return rv;
#else
int x;
Bigint *rv;
static char once;
if (!once) {
atexit(Bclear);
once = 1;
}
__gdtoa_lock();
if (k <= Kmax && (rv = TI0.Freelist[k]) != 0) {
TI0.Freelist[k] = rv->next;
} else {
x = 1 << k;
rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(ULong));
rv = malloc(sizeof(Bigint) + (x-1)*sizeof(ULong));
rv->k = k;
rv->maxwds = x;
}
rv->sign = 0;
rv->wds = 0;
__gdtoa_unlock();
return rv;
#endif
}
void
__gdtoa_Bfree(Bigint *v)
{
#if 0
free(v);
#else
if (v) {
if (v->k > Kmax) {
free((void*)v);
free(v);
} else {
__gdtoa_lock();
v->next = TI0.Freelist[v->k];
TI0.Freelist[v->k] = v;
__gdtoa_unlock();
}
}
#endif
}
Bigint *
__gdtoa_multadd(Bigint *b, int m, int a) /* multiply by m and add a */
Bigint * /* multiply by m and add a */
__gdtoa_multadd(Bigint *b, int m, int a)
{
int i, wds;
ULong *x;
@ -192,27 +187,18 @@ __gdtoa_mult(Bigint *a, Bigint *b)
return c;
}
static void
__gdtoa_pow5mult_destroy(void) {
__gdtoa_Brelease(TI0.P5s);
TI0.P5s = 0;
}
Bigint *
__gdtoa_pow5mult(Bigint *b, int k)
{
Bigint *b1, *p5, *p51;
int i;
Bigint *b1, *p5, *p51;
static const int p05[3] = { 5, 25, 125 };
if ((i = k & 3))
b = __gdtoa_multadd(b, p05[i-1], 0);
if (!(k >>= 2))
return b;
if (!(p5 = TI0.P5s)) {
p5 = TI0.P5s = __gdtoa_i2b(625);
p5->next = 0;
atexit(__gdtoa_pow5mult_destroy);
}
__gdtoa_lock();
p5 = TI0.P5s;
for(;;) {
if (k & 1) {
b1 = __gdtoa_mult(b, p5);
@ -227,6 +213,7 @@ __gdtoa_pow5mult(Bigint *b, int k)
}
p5 = p51;
}
__gdtoa_unlock();
return b;
}

View file

@ -293,7 +293,7 @@ THIRD_PARTY_PYTHON_INCS = \
THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
third_party/python/Modules/_tracemalloc.c \
third_party/python/Modules/faulthandler.c \
third_party/python/Objects/abstract.c \
third_party/python/Objects/abstract.c \
third_party/python/Modules/fspath.c \
third_party/python/Modules/gcmodule.c \
third_party/python/Modules/getbuildinfo.c \
@ -305,7 +305,7 @@ THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
third_party/python/Objects/bytes_methods.c \
third_party/python/Objects/bytesobject.c \
third_party/python/Objects/capsule.c \
third_party/python/Objects/call.c \
third_party/python/Objects/call.c \
third_party/python/Objects/cellobject.c \
third_party/python/Objects/classobject.c \
third_party/python/Objects/codeobject.c \