mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-29 05:50:27 +00:00
Improve memory safety
This commit makes numerous refinements to cosmopolitan memory handling. The default stack size has been reduced from 2mb to 128kb. A new macro is now provided so you can easily reconfigure the stack size to be any value you want. Work around the breaking change by adding to your main: STATIC_STACK_SIZE(0x00200000); // 2mb stack If you're not sure how much stack you need, then you can use: STATIC_YOINK("stack_usage_logging"); After which you can `sort -nr o/$MODE/stack.log`. Based on the unit test suite, nothing in the Cosmopolitan repository (except for Python) needs a stack size greater than 30kb. There are also new macros for detecting the size and address of the stack at runtime, e.g. GetStackAddr(). We also now support sigaltstack() so if you want to see nice looking crash reports whenever a stack overflow happens, you can put this in main(): ShowCrashReports(); Under `make MODE=dbg` and `make MODE=asan` the unit testing framework will now automatically print backtraces of memory allocations when things like memory leaks happen. Bugs are now fixed in ASAN global variable overrun detection. The memtrack and asan runtimes also handle edge cases now. The new tools helped to identify a few memory leaks, which are fixed by this change. This change should fix an issue reported in #288 with ARG_MAX limits. Fixing this doubled the performance of MKDEPS.COM and AR.COM yet again.
This commit is contained in:
parent
a0b39f886c
commit
226aaf3547
317 changed files with 6474 additions and 3993 deletions
2
third_party/bzip2/bzip2.c
vendored
2
third_party/bzip2/bzip2.c
vendored
|
@ -1,4 +1,5 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -9,6 +10,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/struct/utimbuf.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "third_party/bzip2/bzlib.h"
|
||||
|
|
29
third_party/chibicc/alloc.c
vendored
29
third_party/chibicc/alloc.c
vendored
|
@ -16,6 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/chibicc/chibicc.h"
|
||||
|
||||
long alloc_node_count;
|
||||
|
@ -23,22 +25,33 @@ long alloc_token_count;
|
|||
long alloc_obj_count;
|
||||
long alloc_type_count;
|
||||
|
||||
wontreturn void __oom_hook(size_t request) {
|
||||
fprintf(stderr, "error: chibicc ran out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void *alloc(size_t n, long *c) {
|
||||
void *r;
|
||||
if ((r = calloc(1, n))) {
|
||||
++*c;
|
||||
return r;
|
||||
} else {
|
||||
__oom_hook(n);
|
||||
}
|
||||
}
|
||||
|
||||
Node *alloc_node(void) {
|
||||
++alloc_node_count;
|
||||
return calloc(1, sizeof(Node));
|
||||
return alloc(sizeof(Node), &alloc_node_count);
|
||||
}
|
||||
|
||||
Token *alloc_token(void) {
|
||||
++alloc_token_count;
|
||||
return calloc(1, sizeof(Token));
|
||||
return alloc(sizeof(Token), &alloc_token_count);
|
||||
}
|
||||
|
||||
Obj *alloc_obj(void) {
|
||||
++alloc_obj_count;
|
||||
return calloc(1, sizeof(Obj));
|
||||
return alloc(sizeof(Obj), &alloc_obj_count);
|
||||
}
|
||||
|
||||
Type *alloc_type(void) {
|
||||
++alloc_type_count;
|
||||
return calloc(1, sizeof(Type));
|
||||
return alloc(sizeof(Type), &alloc_type_count);
|
||||
}
|
||||
|
|
54
third_party/chibicc/chibicc.c
vendored
54
third_party/chibicc/chibicc.c
vendored
|
@ -66,20 +66,31 @@ static char *output_file;
|
|||
static StringArray input_paths;
|
||||
char **chibicc_tmpfiles;
|
||||
|
||||
static void usage(int status) {
|
||||
char *p;
|
||||
size_t n;
|
||||
p = gc(xslurp("/zip/third_party/chibicc/help.txt", &n));
|
||||
xwrite(1, p, n);
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static void version(void) {
|
||||
printf("\
|
||||
static const char kChibiccVersion[] = "\
|
||||
chibicc (cosmopolitan) 9.0.0\n\
|
||||
copyright 2019 rui ueyama\n\
|
||||
copyright 2020 justine alexandra roberts tunney\n");
|
||||
exit(0);
|
||||
copyright 2020 justine alexandra roberts tunney\n";
|
||||
|
||||
static void chibicc_version(void) {
|
||||
xwrite(1, kChibiccVersion, sizeof(kChibiccVersion) - 1);
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
static void chibicc_usage(int status) {
|
||||
char *p;
|
||||
size_t n;
|
||||
p = xslurp("/zip/third_party/chibicc/help.txt", &n);
|
||||
xwrite(1, p, n);
|
||||
_Exit(status);
|
||||
}
|
||||
|
||||
void chibicc_cleanup(void) {
|
||||
size_t i;
|
||||
if (chibicc_tmpfiles && !opt_save_temps) {
|
||||
for (i = 0; chibicc_tmpfiles[i]; i++) {
|
||||
unlink(chibicc_tmpfiles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool take_arg(char *arg) {
|
||||
|
@ -185,7 +196,7 @@ static void parse_args(int argc, char **argv) {
|
|||
for (int i = 1; i < argc; i++) {
|
||||
if (take_arg(argv[i])) {
|
||||
if (!argv[++i]) {
|
||||
usage(1);
|
||||
chibicc_usage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,9 +207,9 @@ static void parse_args(int argc, char **argv) {
|
|||
} else if (!strcmp(argv[i], "-cc1")) {
|
||||
opt_cc1 = true;
|
||||
} else if (!strcmp(argv[i], "--help")) {
|
||||
usage(0);
|
||||
chibicc_usage(0);
|
||||
} else if (!strcmp(argv[i], "--version")) {
|
||||
version();
|
||||
chibicc_version();
|
||||
} else if (!strcmp(argv[i], "-v")) {
|
||||
opt_verbose = true;
|
||||
atexit(PrintMemoryUsage);
|
||||
|
@ -365,15 +376,6 @@ static char *replace_extn(char *tmpl, char *extn) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void cleanup(void) {
|
||||
size_t i;
|
||||
if (chibicc_tmpfiles && !opt_save_temps) {
|
||||
for (i = 0; chibicc_tmpfiles[i]; i++) {
|
||||
unlink(chibicc_tmpfiles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *create_tmpfile(void) {
|
||||
char *path = xjoinpaths(kTmpPath, "chibicc-XXXXXX");
|
||||
int fd = mkstemp(path);
|
||||
|
@ -442,7 +444,7 @@ static bool run_subprocess(char **argv) {
|
|||
if (!vfork()) {
|
||||
// Child process. Run a new command.
|
||||
execvp(argv[0], argv);
|
||||
_exit(1);
|
||||
_Exit(1);
|
||||
}
|
||||
// Wait for the child process to finish.
|
||||
do rc = wait(&ws);
|
||||
|
@ -683,9 +685,7 @@ static void OnCtrlC(int sig, siginfo_t *si, ucontext_t *ctx) {
|
|||
}
|
||||
|
||||
int chibicc(int argc, char **argv) {
|
||||
showcrashreports();
|
||||
sigaction(SIGINT, &(struct sigaction){.sa_sigaction = OnCtrlC}, NULL);
|
||||
atexit(cleanup);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-cc1")) {
|
||||
opt_cc1 = true;
|
||||
|
|
1
third_party/chibicc/chibicc.h
vendored
1
third_party/chibicc/chibicc.h
vendored
|
@ -608,6 +608,7 @@ extern char *base_file;
|
|||
extern char **chibicc_tmpfiles;
|
||||
|
||||
int chibicc(int, char **);
|
||||
void chibicc_cleanup(void);
|
||||
|
||||
//
|
||||
// alloc.c
|
||||
|
|
2
third_party/chibicc/chibicc.main.c
vendored
2
third_party/chibicc/chibicc.main.c
vendored
|
@ -1,3 +1,5 @@
|
|||
#include "libc/mem/arena.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "third_party/chibicc/chibicc.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
6
third_party/chibicc/test/test.mk
vendored
6
third_party/chibicc/test/test.mk
vendored
|
@ -93,8 +93,10 @@ o/$(MODE)/third_party/chibicc/test/%2.com.dbg: \
|
|||
.PRECIOUS: $(THIRD_PARTY_CHIBICC_TEST_OBJS)
|
||||
.PRECIOUS: $(THIRD_PARTY_CHIBICC_TEST2_OBJS)
|
||||
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.chibicc.o: QUOTA = -M512m
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.chibicc2.o: QUOTA = -M512m
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.o: QUOTA = -M512m
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.o: QUOTA = -M512m
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.chibicc.o: QUOTA = -M1024m
|
||||
o/$(MODE)/third_party/chibicc/test/int128_test.chibicc2.o: QUOTA = -M1024m
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/chibicc/test
|
||||
o/$(MODE)/third_party/chibicc/test: \
|
||||
|
|
4
third_party/dlmalloc/README
vendored
4
third_party/dlmalloc/README
vendored
|
@ -389,10 +389,6 @@ HAVE_MMAP default: 1 (true)
|
|||
able to unmap memory that may have be allocated using multiple calls
|
||||
to MMAP, so long as they are adjacent.
|
||||
|
||||
HAVE_MREMAP default: 1 on linux, else 0
|
||||
If true realloc() uses mremap() to re-allocate large blocks and
|
||||
extend or shrink allocation spaces.
|
||||
|
||||
MMAP_CLEARS default: 1 except on WINCE.
|
||||
True if mmap clears memory so calloc doesn't need to. This is true
|
||||
for standard unix mmap using /dev/zero and on WIN32 except for WINCE.
|
||||
|
|
21
third_party/dlmalloc/bulk_free.c
vendored
21
third_party/dlmalloc/bulk_free.c
vendored
|
@ -10,6 +10,9 @@
|
|||
* to sort this array before calling bulk_free.
|
||||
*/
|
||||
size_t dlbulk_free(void *array[], size_t nelem) {
|
||||
void **a, **b, *mem, **fence;
|
||||
struct MallocChunk *p, *next;
|
||||
size_t psize, newsize, unfreed;
|
||||
/*
|
||||
* Try to free all pointers in the given array. Note: this could be
|
||||
* made faster, by delaying consolidation, at the price of disabling
|
||||
|
@ -17,15 +20,15 @@ size_t dlbulk_free(void *array[], size_t nelem) {
|
|||
* by combining adjacent chunks before freeing, which will occur often
|
||||
* if allocated with ialloc or the array is sorted.
|
||||
*/
|
||||
size_t unfreed = 0;
|
||||
unfreed = 0;
|
||||
if (!PREACTION(g_dlmalloc)) {
|
||||
void **a;
|
||||
void **fence = &(array[nelem]);
|
||||
a;
|
||||
fence = &(array[nelem]);
|
||||
for (a = array; a != fence; ++a) {
|
||||
void *mem = *a;
|
||||
mem = *a;
|
||||
if (mem != 0) {
|
||||
mchunkptr p = mem2chunk(AddressDeathAction(mem));
|
||||
size_t psize = chunksize(p);
|
||||
p = mem2chunk(AddressDeathAction(mem));
|
||||
psize = chunksize(p);
|
||||
#if FOOTERS
|
||||
if (get_mstate_for(p) != g_dlmalloc) {
|
||||
++unfreed;
|
||||
|
@ -35,10 +38,10 @@ size_t dlbulk_free(void *array[], size_t nelem) {
|
|||
check_inuse_chunk(g_dlmalloc, p);
|
||||
*a = 0;
|
||||
if (RTCHECK(ok_address(g_dlmalloc, p) && ok_inuse(p))) {
|
||||
void **b = a + 1; /* try to merge with next chunk */
|
||||
mchunkptr next = next_chunk(p);
|
||||
b = a + 1; /* try to merge with next chunk */
|
||||
next = next_chunk(p);
|
||||
if (b != fence && *b == chunk2mem(next)) {
|
||||
size_t newsize = chunksize(next) + psize;
|
||||
newsize = chunksize(next) + psize;
|
||||
set_inuse(g_dlmalloc, p, newsize);
|
||||
*b = chunk2mem(p);
|
||||
} else
|
||||
|
|
2
third_party/dlmalloc/dlcalloc.c
vendored
2
third_party/dlmalloc/dlcalloc.c
vendored
|
@ -6,7 +6,7 @@ void *dlcalloc(size_t n_elements, size_t elem_size) {
|
|||
size_t req;
|
||||
if (__builtin_mul_overflow(n_elements, elem_size, &req)) req = -1;
|
||||
mem = dlmalloc(req);
|
||||
if (mem != 0 && calloc_must_clear(mem2chunk(mem))) {
|
||||
if (mem && calloc_must_clear(mem2chunk(mem))) {
|
||||
bzero(mem, req);
|
||||
}
|
||||
return mem;
|
||||
|
|
9
third_party/dlmalloc/dlindependent_calloc.c
vendored
9
third_party/dlmalloc/dlindependent_calloc.c
vendored
|
@ -96,7 +96,7 @@ static void **ialloc(mstate m, size_t n_elements, size_t *sizes, int opts,
|
|||
}
|
||||
}
|
||||
|
||||
#if DEBUG + MODE_DBG + 0
|
||||
#ifdef DEBUG
|
||||
if (marray != chunks) {
|
||||
/* final element must have exactly exhausted chunk */
|
||||
if (element_size != 0) {
|
||||
|
@ -106,9 +106,10 @@ static void **ialloc(mstate m, size_t n_elements, size_t *sizes, int opts,
|
|||
}
|
||||
check_inuse_chunk(m, mem2chunk(marray));
|
||||
}
|
||||
for (i = 0; i != n_elements; ++i) check_inuse_chunk(m, mem2chunk(marray[i]));
|
||||
|
||||
#endif /* DEBUG */
|
||||
for (i = 0; i != n_elements; ++i) {
|
||||
check_inuse_chunk(m, mem2chunk(marray[i]));
|
||||
}
|
||||
#endif /* IsModeDbg() */
|
||||
|
||||
POSTACTION(m);
|
||||
return marray;
|
||||
|
|
113
third_party/dlmalloc/dlmalloc.c
vendored
113
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -1,3 +1,4 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
|
@ -13,6 +14,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
@ -51,7 +53,8 @@ static void *dlmalloc_requires_more_vespene_gas(size_t size) {
|
|||
/* ─────────────────────────── mspace management ─────────────────────────── */
|
||||
|
||||
/* Initialize top chunk and its size */
|
||||
static void dlmalloc_init_top(mstate m, mchunkptr p, size_t psize) {
|
||||
static void dlmalloc_init_top(struct MallocState *m, mchunkptr p,
|
||||
size_t psize) {
|
||||
/* Ensure alignment */
|
||||
size_t offset = align_offset(chunk2mem(p));
|
||||
p = (mchunkptr)((char *)p + offset);
|
||||
|
@ -65,7 +68,7 @@ static void dlmalloc_init_top(mstate m, mchunkptr p, size_t psize) {
|
|||
}
|
||||
|
||||
/* Initialize bins for a new mstate that is otherwise zeroed out */
|
||||
static void init_bins(mstate m) {
|
||||
static void init_bins(struct MallocState *m) {
|
||||
/* Establish circular links for smallbins */
|
||||
bindex_t i;
|
||||
for (i = 0; i < NSMALLBINS; ++i) {
|
||||
|
@ -75,8 +78,8 @@ static void init_bins(mstate m) {
|
|||
}
|
||||
|
||||
/* Allocate chunk and prepend remainder with chunk in successor base. */
|
||||
static void *dlmalloc_prepend_alloc(mstate m, char *newbase, char *oldbase,
|
||||
size_t nb) {
|
||||
static void *dlmalloc_prepend_alloc(struct MallocState *m, char *newbase,
|
||||
char *oldbase, size_t nb) {
|
||||
mchunkptr p = align_as_chunk(newbase);
|
||||
mchunkptr oldfirst = align_as_chunk(oldbase);
|
||||
size_t psize = (char *)oldfirst - (char *)p;
|
||||
|
@ -112,13 +115,13 @@ static void *dlmalloc_prepend_alloc(mstate m, char *newbase, char *oldbase,
|
|||
}
|
||||
|
||||
/* Add a segment to hold a new noncontiguous region */
|
||||
static void dlmalloc_add_segment(mstate m, char *tbase, size_t tsize,
|
||||
flag_t mmapped) {
|
||||
static void dlmalloc_add_segment(struct MallocState *m, char *tbase,
|
||||
size_t tsize, flag_t mmapped) {
|
||||
/* Determine locations and sizes of segment, fenceposts, old top */
|
||||
char *old_top = (char *)m->top;
|
||||
msegmentptr oldsp = segment_holding(m, old_top);
|
||||
char *old_end = oldsp->base + oldsp->size;
|
||||
size_t ssize = pad_request(sizeof(struct malloc_segment));
|
||||
size_t ssize = pad_request(sizeof(struct MallocSegment));
|
||||
char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
|
||||
size_t offset = align_offset(chunk2mem(rawsp));
|
||||
char *asp = rawsp + offset;
|
||||
|
@ -163,8 +166,10 @@ static void dlmalloc_add_segment(mstate m, char *tbase, size_t tsize,
|
|||
/* ─────────────────────────── system integration ─────────────────────────── */
|
||||
|
||||
/* Return true if segment contains a segment link */
|
||||
static int has_segment_link(mstate m, msegmentptr ss) {
|
||||
msegmentptr sp = &m->seg;
|
||||
noinline int has_segment_link(struct MallocState *m, msegmentptr ss) {
|
||||
msegmentptr sp;
|
||||
assert(m);
|
||||
sp = &m->seg;
|
||||
for (;;) {
|
||||
if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size) return 1;
|
||||
if ((sp = sp->next) == 0) return 0;
|
||||
|
@ -183,7 +188,7 @@ static int has_segment_link(mstate m, msegmentptr ss) {
|
|||
#define SYS_ALLOC_PADDING (TOP_FOOT_SIZE + MALLOC_ALIGNMENT)
|
||||
|
||||
/* Malloc using mmap */
|
||||
static void *mmap_alloc(mstate m, size_t nb) {
|
||||
static void *mmap_alloc(struct MallocState *m, size_t nb) {
|
||||
size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
|
||||
if (m->footprint_limit != 0) {
|
||||
size_t fp = m->footprint + mmsize;
|
||||
|
@ -214,7 +219,7 @@ static void *mmap_alloc(mstate m, size_t nb) {
|
|||
/**
|
||||
* Gets memory from system.
|
||||
*/
|
||||
static void *dlmalloc_sys_alloc(mstate m, size_t nb) {
|
||||
static void *dlmalloc_sys_alloc(struct MallocState *m, size_t nb) {
|
||||
char *tbase = CMFAIL;
|
||||
size_t tsize = 0;
|
||||
flag_t mmap_flag = 0;
|
||||
|
@ -310,7 +315,7 @@ static void *dlmalloc_sys_alloc(mstate m, size_t nb) {
|
|||
}
|
||||
|
||||
/* Unmap and unlink any mmapped segments that don't contain used chunks */
|
||||
static size_t dlmalloc_release_unused_segments(mstate m) {
|
||||
static size_t dlmalloc_release_unused_segments(struct MallocState *m) {
|
||||
size_t released = 0;
|
||||
int nsegs = 0;
|
||||
msegmentptr pred = &m->seg;
|
||||
|
@ -357,7 +362,7 @@ static size_t dlmalloc_release_unused_segments(mstate m) {
|
|||
return released;
|
||||
}
|
||||
|
||||
int dlmalloc_sys_trim(mstate m, size_t pad) {
|
||||
int dlmalloc_sys_trim(struct MallocState *m, size_t pad) {
|
||||
size_t released = 0;
|
||||
ensure_initialization();
|
||||
if (pad < MAX_REQUEST && is_initialized(m)) {
|
||||
|
@ -416,7 +421,7 @@ static void post_fork_child(void) {
|
|||
/* Consolidate and bin a chunk. Differs from exported versions
|
||||
of free mainly in that the chunk need not be marked as inuse.
|
||||
*/
|
||||
void dlmalloc_dispose_chunk(mstate m, mchunkptr p, size_t psize) {
|
||||
void dlmalloc_dispose_chunk(struct MallocState *m, mchunkptr p, size_t psize) {
|
||||
mchunkptr next = chunk_plus_offset(p, psize);
|
||||
if (!pinuse(p)) {
|
||||
mchunkptr prev;
|
||||
|
@ -480,7 +485,7 @@ void dlmalloc_dispose_chunk(mstate m, mchunkptr p, size_t psize) {
|
|||
/* ──────────────────────────── malloc ─────────────────────────── */
|
||||
|
||||
/* allocate a small request from the best fitting chunk in a treebin */
|
||||
static void *tmalloc_small(mstate m, size_t nb) {
|
||||
static void *tmalloc_small(struct MallocState *m, size_t nb) {
|
||||
tchunkptr t, v;
|
||||
size_t rsize;
|
||||
bindex_t i;
|
||||
|
@ -515,7 +520,7 @@ static void *tmalloc_small(mstate m, size_t nb) {
|
|||
}
|
||||
|
||||
/* allocate a large request from the best fitting chunk in a treebin */
|
||||
static void *tmalloc_large(mstate m, size_t nb) {
|
||||
static void *tmalloc_large(struct MallocState *m, size_t nb) {
|
||||
tchunkptr v = 0;
|
||||
size_t rsize = -nb; /* Unsigned negation */
|
||||
tchunkptr t;
|
||||
|
@ -717,11 +722,8 @@ void *dlmalloc_impl(size_t bytes, bool takeaction) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *dlmalloc(size_t bytes) {
|
||||
return dlmalloc_impl(bytes, true);
|
||||
}
|
||||
|
||||
void dlfree(void *mem) {
|
||||
/* asan runtime depends on this function */
|
||||
/*
|
||||
Consolidate freed chunks with preceeding or succeeding bordering
|
||||
free chunks, if they exist, and then place in a bin. Intermixed
|
||||
|
@ -732,7 +734,7 @@ void dlfree(void *mem) {
|
|||
mchunkptr p = mem2chunk(mem);
|
||||
|
||||
#if FOOTERS
|
||||
mstate fm = get_mstate_for(p);
|
||||
struct MallocState *fm = get_mstate_for(p);
|
||||
if (!ok_magic(fm)) { /* HELLO
|
||||
* TRY #1: rm -rf o && make -j8 -O MODE=dbg
|
||||
* TRY #2: gdb: p/x (long*)(p+(*(long*)(p-8)&~(1|2|3)))
|
||||
|
@ -784,7 +786,9 @@ void dlfree(void *mem) {
|
|||
fm->dv = 0;
|
||||
fm->dvsize = 0;
|
||||
}
|
||||
if (should_trim(fm, tsize)) dlmalloc_sys_trim(fm, 0);
|
||||
if (should_trim(fm, tsize)) {
|
||||
dlmalloc_sys_trim(fm, 0);
|
||||
}
|
||||
goto postaction;
|
||||
} else if (next == fm->dv) {
|
||||
size_t dsize = fm->dvsize += psize;
|
||||
|
@ -818,6 +822,7 @@ void dlfree(void *mem) {
|
|||
}
|
||||
}
|
||||
erroraction:
|
||||
if (IsArenaFrame((intptr_t)p >> 16)) return;
|
||||
USAGE_ERROR_ACTION(fm, p);
|
||||
postaction:
|
||||
POSTACTION(fm);
|
||||
|
@ -829,6 +834,7 @@ void dlfree(void *mem) {
|
|||
}
|
||||
|
||||
size_t dlmalloc_usable_size(const void *mem) {
|
||||
/* asan runtime depends on this function */
|
||||
if (mem != 0) {
|
||||
mchunkptr p = mem2chunk(mem);
|
||||
if (is_inuse(p)) return chunksize(p) - overhead_for(p);
|
||||
|
@ -879,22 +885,19 @@ textstartup void dlmalloc_init(void) {
|
|||
RELEASE_MALLOC_GLOBAL_LOCK();
|
||||
}
|
||||
|
||||
void *dlmemalign$impl(mstate m, size_t alignment, size_t bytes) {
|
||||
void *mem = 0;
|
||||
if (bytes >= MAX_REQUEST - alignment) {
|
||||
if (m != 0) { /* Test isn't needed but avoids compiler warning */
|
||||
enomem();
|
||||
}
|
||||
} else {
|
||||
void *dlmemalign_impl(struct MallocState *m, size_t al, size_t bytes) {
|
||||
char *br, *pos, *mem = 0;
|
||||
mchunkptr p, newp, remainder;
|
||||
size_t nb, req, size, leadsize, newsize, remainder_size;
|
||||
if (bytes < MAX_REQUEST - al) {
|
||||
/* alignment is 32+ bytes rounded up to nearest two power */
|
||||
alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
|
||||
size_t nb = request2size(bytes);
|
||||
size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
|
||||
mem = dlmalloc_impl(req, false);
|
||||
if (mem != 0) {
|
||||
mchunkptr p = mem2chunk(mem);
|
||||
al = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, al) - 1);
|
||||
nb = request2size(bytes);
|
||||
req = nb + al + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
|
||||
if ((mem = dlmalloc_impl(req, false))) {
|
||||
p = mem2chunk(mem);
|
||||
if (PREACTION(m)) return 0;
|
||||
if ((((size_t)(mem)) & (alignment - 1)) != 0) { /* misaligned */
|
||||
if ((((size_t)(mem)) & (al - 1))) { /* misaligned */
|
||||
/*
|
||||
Find an aligned spot inside chunk. Since we need to give
|
||||
back leading space in a chunk of at least MIN_CHUNK_SIZE, if
|
||||
|
@ -903,14 +906,11 @@ void *dlmemalign$impl(mstate m, size_t alignment, size_t bytes) {
|
|||
We've allocated enough total room so that this is always
|
||||
possible.
|
||||
*/
|
||||
char *br = (char *)mem2chunk((size_t)(
|
||||
((size_t)((char *)mem + alignment - SIZE_T_ONE)) & -alignment));
|
||||
char *pos = ((size_t)(br - (char *)(p)) >= MIN_CHUNK_SIZE)
|
||||
? br
|
||||
: br + alignment;
|
||||
mchunkptr newp = (mchunkptr)pos;
|
||||
size_t leadsize = pos - (char *)(p);
|
||||
size_t newsize = chunksize(p) - leadsize;
|
||||
br = (char *)mem2chunk(ROUNDUP((uintptr_t)mem, al));
|
||||
pos = (size_t)(br - (char *)(p)) >= MIN_CHUNK_SIZE ? br : br + al;
|
||||
newp = (mchunkptr)pos;
|
||||
leadsize = pos - (char *)(p);
|
||||
newsize = chunksize(p) - leadsize;
|
||||
if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
|
||||
newp->prev_foot = p->prev_foot + leadsize;
|
||||
newp->head = newsize;
|
||||
|
@ -923,10 +923,10 @@ void *dlmemalign$impl(mstate m, size_t alignment, size_t bytes) {
|
|||
}
|
||||
/* Give back spare room at the end */
|
||||
if (!is_mmapped(p)) {
|
||||
size_t size = chunksize(p);
|
||||
size = chunksize(p);
|
||||
if (size > nb + MIN_CHUNK_SIZE) {
|
||||
size_t remainder_size = size - nb;
|
||||
mchunkptr remainder = chunk_plus_offset(p, nb);
|
||||
remainder_size = size - nb;
|
||||
remainder = chunk_plus_offset(p, nb);
|
||||
set_inuse(m, p, nb);
|
||||
set_inuse(m, remainder, remainder_size);
|
||||
dlmalloc_dispose_chunk(m, remainder, remainder_size);
|
||||
|
@ -934,15 +934,26 @@ void *dlmemalign$impl(mstate m, size_t alignment, size_t bytes) {
|
|||
}
|
||||
mem = chunk2mem(p);
|
||||
assert(chunksize(p) >= nb);
|
||||
assert(((size_t)mem & (alignment - 1)) == 0);
|
||||
assert(!((size_t)mem & (al - 1)));
|
||||
check_inuse_chunk(m, p);
|
||||
POSTACTION(m);
|
||||
}
|
||||
return AddressBirthAction(mem);
|
||||
} else {
|
||||
enomem();
|
||||
return 0;
|
||||
}
|
||||
return AddressBirthAction(mem);
|
||||
}
|
||||
|
||||
void *dlmalloc(size_t bytes) {
|
||||
return dlmalloc_impl(bytes, true);
|
||||
}
|
||||
|
||||
void *dlmemalign(size_t alignment, size_t bytes) {
|
||||
if (alignment <= MALLOC_ALIGNMENT) return dlmalloc(bytes);
|
||||
return dlmemalign$impl(g_dlmalloc, alignment, bytes);
|
||||
/* asan runtime depends on this function */
|
||||
if (alignment <= MALLOC_ALIGNMENT) {
|
||||
return dlmalloc_impl(bytes, true);
|
||||
} else {
|
||||
return dlmemalign_impl(g_dlmalloc, alignment, bytes);
|
||||
}
|
||||
}
|
||||
|
|
184
third_party/dlmalloc/dlmalloc.internal.h
vendored
184
third_party/dlmalloc/dlmalloc.internal.h
vendored
|
@ -18,19 +18,15 @@ COSMOPOLITAN_C_START_
|
|||
*/
|
||||
#endif
|
||||
|
||||
#define DLMALLOC_VERSION 20806
|
||||
|
||||
#ifndef FOOTERS
|
||||
#define FOOTERS !NoDebug()
|
||||
#endif
|
||||
|
||||
#define DLMALLOC_VERSION 20806
|
||||
#define HAVE_MMAP 1
|
||||
#define HAVE_MREMAP 0 /* IsLinux() */
|
||||
#define MMAP_CLEARS 1
|
||||
#define MALLOC_ALIGNMENT __BIGGEST_ALIGNMENT__
|
||||
#define MALLOC_ALIGNMENT 16
|
||||
#define NO_SEGMENT_TRAVERSAL 1
|
||||
#define MAX_RELEASE_CHECK_RATE 128
|
||||
#define MALLOC_ABORT abort()
|
||||
#define FOOTERS !NoDebug()
|
||||
#define MAX_REQUEST 0xfffffffffff
|
||||
#define DEFAULT_GRANULARITY (64UL * 1024UL)
|
||||
#define DEFAULT_TRIM_THRESHOLD (10UL * 1024UL * 1024UL)
|
||||
#define DEFAULT_MMAP_THRESHOLD (256UL * 1024UL)
|
||||
|
@ -137,7 +133,7 @@ COSMOPOLITAN_C_START_
|
|||
/*
|
||||
(The following includes lightly edited explanations by Colin Plumb.)
|
||||
|
||||
The malloc_chunk declaration below is misleading (but accurate and
|
||||
The MallocChunk declaration below is misleading (but accurate and
|
||||
necessary). It declares a "view" into memory allowing access to
|
||||
necessary fields at known offsets from a given base.
|
||||
|
||||
|
@ -269,19 +265,19 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
*/
|
||||
|
||||
struct malloc_chunk {
|
||||
size_t prev_foot; /* Size of previous chunk (if free). */
|
||||
size_t head; /* Size and inuse bits. */
|
||||
struct malloc_chunk *fd; /* double links -- used only if free. */
|
||||
struct malloc_chunk *bk;
|
||||
struct MallocChunk {
|
||||
size_t prev_foot; /* Size of previous chunk (if free). */
|
||||
size_t head; /* Size and inuse bits. */
|
||||
struct MallocChunk *fd; /* double links -- used only if free. */
|
||||
struct MallocChunk *bk;
|
||||
};
|
||||
|
||||
typedef struct malloc_chunk mchunk;
|
||||
typedef struct malloc_chunk *mchunkptr;
|
||||
typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */
|
||||
typedef unsigned int bindex_t; /* Described below */
|
||||
typedef unsigned int binmap_t; /* Described below */
|
||||
typedef unsigned int flag_t; /* The type of various bit flag sets */
|
||||
typedef struct MallocChunk mchunk;
|
||||
typedef struct MallocChunk *mchunkptr;
|
||||
typedef struct MallocChunk *sbinptr; /* The type of bins of chunks */
|
||||
typedef unsigned int bindex_t; /* Described below */
|
||||
typedef unsigned int binmap_t; /* Described below */
|
||||
typedef unsigned int flag_t; /* The type of various bit flag sets */
|
||||
|
||||
/* ─────────────────── Chunks sizes and alignments ─────────────────────── */
|
||||
|
||||
|
@ -304,7 +300,6 @@ typedef unsigned int flag_t; /* The type of various bit flag sets */
|
|||
#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A)))
|
||||
|
||||
/* Bounds on request (not chunk) sizes. */
|
||||
#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2)
|
||||
#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
|
||||
|
||||
/* pad request bytes into a usable size */
|
||||
|
@ -351,7 +346,7 @@ typedef unsigned int flag_t; /* The type of various bit flag sets */
|
|||
#define chunk_plus_offset(p, s) ((mchunkptr)(((char *)(p)) + (s)))
|
||||
#define chunk_minus_offset(p, s) ((mchunkptr)(((char *)(p)) - (s)))
|
||||
|
||||
/* Ptr to next or previous physical malloc_chunk. */
|
||||
/* Ptr to next or previous physical MallocChunk. */
|
||||
#define next_chunk(p) ((mchunkptr)(((char *)(p)) + ((p)->head & ~FLAG_BITS)))
|
||||
#define prev_chunk(p) ((mchunkptr)(((char *)(p)) - ((p)->prev_foot)))
|
||||
|
||||
|
@ -403,7 +398,7 @@ typedef unsigned int flag_t; /* The type of various bit flag sets */
|
|||
└───────────────────────────────────────────────────────────────┘
|
||||
|
||||
Larger chunks are kept in a form of bitwise digital trees (aka
|
||||
tries) keyed on chunksizes. Because malloc_tree_chunks are only for
|
||||
tries) keyed on chunksizes. Because MallocTreeChunks are only for
|
||||
free chunks greater than 256 bytes, their size doesn't impose any
|
||||
constraints on user chunk sizes. Each node looks like:
|
||||
|
||||
|
@ -468,21 +463,20 @@ typedef unsigned int flag_t; /* The type of various bit flag sets */
|
|||
is of course much better.
|
||||
*/
|
||||
|
||||
struct malloc_tree_chunk {
|
||||
/* The first four fields must be compatible with malloc_chunk */
|
||||
struct MallocTreeChunk {
|
||||
/* The first four fields must be compatible with MallocChunk */
|
||||
size_t prev_foot;
|
||||
size_t head;
|
||||
struct malloc_tree_chunk *fd;
|
||||
struct malloc_tree_chunk *bk;
|
||||
|
||||
struct malloc_tree_chunk *child[2];
|
||||
struct malloc_tree_chunk *parent;
|
||||
struct MallocTreeChunk *fd;
|
||||
struct MallocTreeChunk *bk;
|
||||
struct MallocTreeChunk *child[2];
|
||||
struct MallocTreeChunk *parent;
|
||||
bindex_t index;
|
||||
};
|
||||
|
||||
typedef struct malloc_tree_chunk tchunk;
|
||||
typedef struct malloc_tree_chunk *tchunkptr;
|
||||
typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
|
||||
typedef struct MallocTreeChunk tchunk;
|
||||
typedef struct MallocTreeChunk *tchunkptr;
|
||||
typedef struct MallocTreeChunk *tbinptr; /* The type of bins of trees */
|
||||
|
||||
/* A little helper macro for trees */
|
||||
#define leftmost_child(t) ((t)->child[0] != 0 ? (t)->child[0] : (t)->child[1])
|
||||
|
@ -490,46 +484,44 @@ typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
|
|||
/* ───────────────────────────── Segments ──────────────────────────────── */
|
||||
|
||||
/*
|
||||
Each malloc space may include non-contiguous segments, held in a
|
||||
list headed by an embedded malloc_segment record representing the
|
||||
top-most space. Segments also include flags holding properties of
|
||||
the space. Large chunks that are directly allocated by mmap are not
|
||||
included in this list. They are instead independently created and
|
||||
destroyed without otherwise keeping track of them.
|
||||
Each malloc space may include non-contiguous segments, held in a list
|
||||
headed by an embedded MallocSegment record representing the top-most
|
||||
space. Segments also include flags holding properties of the space.
|
||||
Large chunks that are directly allocated by mmap are not included in
|
||||
this list. They are instead independently created and destroyed
|
||||
without otherwise keeping track of them.
|
||||
|
||||
Segment management mainly comes into play for spaces allocated by
|
||||
MMAP. Any call to MMAP might or might not return memory that is
|
||||
adjacent to an existing segment. MORECORE normally contiguously
|
||||
MMAP. Any call to MMAP might or might not return memory that is
|
||||
adjacent to an existing segment. MORECORE normally contiguously
|
||||
extends the current space, so this space is almost always adjacent,
|
||||
which is simpler and faster to deal with. (This is why MORECORE is
|
||||
used preferentially to MMAP when both are available -- see
|
||||
sys_alloc.) When allocating using MMAP, we don't use any of the
|
||||
hinting mechanisms (inconsistently) supported in various
|
||||
implementations of unix mmap, or distinguish reserving from
|
||||
committing memory. Instead, we just ask for space, and exploit
|
||||
contiguity when we get it. It is probably possible to do
|
||||
better than this on some systems, but no general scheme seems
|
||||
to be significantly better.
|
||||
used preferentially to MMAP when both are available -- see sys_alloc.)
|
||||
When allocating using MMAP, we don't use any of the hinting mechanisms
|
||||
(inconsistently) supported in various implementations of unix mmap, or
|
||||
distinguish reserving from committing memory. Instead, we just ask for
|
||||
space, and exploit contiguity when we get it. It is probably possible
|
||||
to do better than this on some systems, but no general scheme seems to
|
||||
be significantly better.
|
||||
|
||||
Management entails a simpler variant of the consolidation scheme
|
||||
used for chunks to reduce fragmentation -- new adjacent memory is
|
||||
normally prepended or appended to an existing segment. However,
|
||||
there are limitations compared to chunk consolidation that mostly
|
||||
reflect the fact that segment processing is relatively infrequent
|
||||
(occurring only when getting memory from system) and that we
|
||||
don't expect to have huge numbers of segments:
|
||||
Management entails a simpler variant of the consolidation scheme used
|
||||
for chunks to reduce fragmentation -- new adjacent memory is normally
|
||||
prepended or appended to an existing segment. However, there are
|
||||
limitations compared to chunk consolidation that mostly reflect the
|
||||
fact that segment processing is relatively infrequent (occurring only
|
||||
when getting memory from system) and that we don't expect to have huge
|
||||
numbers of segments:
|
||||
|
||||
* Segments are not indexed, so traversal requires linear scans. (It
|
||||
* Segments are not indexed, so traversal requires linear scans. (It
|
||||
would be possible to index these, but is not worth the extra
|
||||
overhead and complexity for most programs on most platforms.)
|
||||
* New segments are only appended to old ones when holding top-most
|
||||
memory; if they cannot be prepended to others, they are held in
|
||||
different segments.
|
||||
|
||||
Except for the top-most segment of an mstate, each segment record
|
||||
is kept at the tail of its segment. Segments are added by pushing
|
||||
segment records onto the list headed by &mstate.seg for the
|
||||
containing mstate.
|
||||
Except for the top-most segment of an mstate, each segment record is
|
||||
kept at the tail of its segment. Segments are added by pushing segment
|
||||
records onto the list headed by &mstate.seg for the containing mstate.
|
||||
|
||||
Segment flags control allocation/merge/deallocation policies:
|
||||
* If EXTERN_BIT set, then we did not allocate this segment,
|
||||
|
@ -544,18 +536,18 @@ typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
|
|||
and deallocated/trimmed using MORECORE with negative arguments.
|
||||
*/
|
||||
|
||||
struct malloc_segment {
|
||||
char *base; /* base address */
|
||||
size_t size; /* allocated size */
|
||||
struct malloc_segment *next; /* ptr to next segment */
|
||||
flag_t sflags; /* mmap and extern flag */
|
||||
struct MallocSegment {
|
||||
char *base; /* base address */
|
||||
size_t size; /* allocated size */
|
||||
struct MallocSegment *next; /* ptr to next segment */
|
||||
flag_t sflags; /* mmap and extern flag */
|
||||
};
|
||||
|
||||
#define is_mmapped_segment(S) ((S)->sflags & USE_MMAP_BIT)
|
||||
#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT)
|
||||
|
||||
typedef struct malloc_segment msegment;
|
||||
typedef struct malloc_segment *msegmentptr;
|
||||
typedef struct MallocSegment msegment;
|
||||
typedef struct MallocSegment *msegmentptr;
|
||||
|
||||
/* ──────────────────────────── MallocState ───────────────────────────── */
|
||||
|
||||
|
@ -583,7 +575,7 @@ typedef struct malloc_segment *msegmentptr;
|
|||
An array of bin headers for free chunks. These bins hold chunks
|
||||
with sizes less than MIN_LARGE_SIZE bytes. Each bin contains
|
||||
chunks of all the same size, spaced 8 bytes apart. To simplify
|
||||
use in double-linked lists, each bin header acts as a malloc_chunk
|
||||
use in double-linked lists, each bin header acts as a MallocChunk
|
||||
pointing to the real first node, if it exists (else pointing to
|
||||
itself). This avoids special-casing for headers. But to avoid
|
||||
waste, we allocate only the fd/bk pointers of bins, and then use
|
||||
|
@ -609,7 +601,7 @@ typedef struct malloc_segment *msegmentptr;
|
|||
well as to reduce the number of memory locations read or written.
|
||||
|
||||
Segments
|
||||
A list of segments headed by an embedded malloc_segment record
|
||||
A list of segments headed by an embedded MallocSegment record
|
||||
representing the initial space.
|
||||
|
||||
Address check support
|
||||
|
@ -715,10 +707,12 @@ for k,v in d.items():
|
|||
*/
|
||||
#define MALLOC_TRACE 0
|
||||
|
||||
static inline void *AddressBirthAction(void *p) {
|
||||
forceinline void *AddressBirthAction(void *p) {
|
||||
#if MALLOC_TRACE
|
||||
(dprintf)(2, "BIRTH %p\n", p);
|
||||
if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) {
|
||||
if (weaken(ShowBacktrace)) {
|
||||
weaken(ShowBacktrace)(2, 0);
|
||||
} else if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) {
|
||||
weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0),
|
||||
weaken(GetSymbolTable)());
|
||||
}
|
||||
|
@ -726,10 +720,12 @@ static inline void *AddressBirthAction(void *p) {
|
|||
return p;
|
||||
}
|
||||
|
||||
static inline void *AddressDeathAction(void *p) {
|
||||
forceinline void *AddressDeathAction(void *p) {
|
||||
#if MALLOC_TRACE
|
||||
(dprintf)(2, "DEATH %p\n", p);
|
||||
if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) {
|
||||
if (weaken(ShowBacktrace)) {
|
||||
weaken(ShowBacktrace)(2, 0);
|
||||
} else if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) {
|
||||
weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0),
|
||||
weaken(GetSymbolTable)());
|
||||
}
|
||||
|
@ -766,8 +762,8 @@ static inline void *AddressDeathAction(void *p) {
|
|||
that may be needed to place segment records and fenceposts when new
|
||||
noncontiguous segments are added.
|
||||
*/
|
||||
#define TOP_FOOT_SIZE \
|
||||
(align_offset(chunk2mem(0)) + pad_request(sizeof(struct malloc_segment)) + \
|
||||
#define TOP_FOOT_SIZE \
|
||||
(align_offset(chunk2mem(0)) + pad_request(sizeof(struct MallocSegment)) + \
|
||||
MIN_CHUNK_SIZE)
|
||||
|
||||
/* ───────────── Global MallocState and MallocParams ─────────────────── */
|
||||
|
@ -1261,26 +1257,26 @@ forceinline msegmentptr segment_holding(mstate m, char *addr) {
|
|||
that may be needed to place segment records and fenceposts when new
|
||||
noncontiguous segments are added.
|
||||
*/
|
||||
#define TOP_FOOT_SIZE \
|
||||
(align_offset(chunk2mem(0)) + pad_request(sizeof(struct malloc_segment)) + \
|
||||
#define TOP_FOOT_SIZE \
|
||||
(align_offset(chunk2mem(0)) + pad_request(sizeof(struct MallocSegment)) + \
|
||||
MIN_CHUNK_SIZE)
|
||||
|
||||
/* ────────────────────────── Debugging setup ──────────────────────────── */
|
||||
|
||||
#if !(DEBUG + MODE_DBG + 0)
|
||||
#define check_free_chunk(M, P)
|
||||
#define check_inuse_chunk(M, P)
|
||||
#define check_malloced_chunk(M, P, N)
|
||||
#define check_mmapped_chunk(M, P)
|
||||
#define check_malloc_state(M)
|
||||
#define check_top_chunk(M, P)
|
||||
#else /* DEBUG */
|
||||
#ifdef DEBUG
|
||||
#define check_free_chunk(M, P) do_check_free_chunk(M, P)
|
||||
#define check_inuse_chunk(M, P) do_check_inuse_chunk(M, P)
|
||||
#define check_top_chunk(M, P) do_check_top_chunk(M, P)
|
||||
#define check_malloced_chunk(M, P, N) do_check_malloced_chunk(M, P, N)
|
||||
#define check_mmapped_chunk(M, P) do_check_mmapped_chunk(M, P)
|
||||
#define check_malloc_state(M) do_check_malloc_state(M)
|
||||
#else
|
||||
#define check_free_chunk(M, P)
|
||||
#define check_inuse_chunk(M, P)
|
||||
#define check_malloced_chunk(M, P, N)
|
||||
#define check_mmapped_chunk(M, P)
|
||||
#define check_malloc_state(M)
|
||||
#define check_top_chunk(M, P)
|
||||
#endif /* DEBUG */
|
||||
|
||||
void do_check_free_chunk(mstate, mchunkptr) hidden;
|
||||
|
@ -1292,18 +1288,16 @@ void do_check_malloc_state(mstate) hidden;
|
|||
|
||||
/* ─────────────────────────── prototypes ──────────────────────────────── */
|
||||
|
||||
void *dlmalloc(size_t) hidden;
|
||||
void *dlcalloc(size_t, size_t) hidden;
|
||||
void *dlmalloc(size_t) hidden attributeallocsize((1)) mallocesque;
|
||||
void *dlcalloc(size_t, size_t) hidden attributeallocsize((1, 2)) mallocesque;
|
||||
void dlfree(void *) nothrow nocallback hidden;
|
||||
void *dlmemalign$impl(mstate, size_t, size_t) hidden;
|
||||
void *dlrealloc(void *, size_t) hidden;
|
||||
void *dlrealloc_in_place(void *, size_t) hidden;
|
||||
void *dlvalloc(size_t) hidden;
|
||||
void *dlpvalloc(size_t) hidden;
|
||||
void *dlmemalign(size_t, size_t) hidden;
|
||||
void *dlmemalign_impl(mstate, size_t, size_t) hidden;
|
||||
void *dlrealloc(void *, size_t) hidden reallocesque;
|
||||
void *dlrealloc_in_place(void *, size_t) hidden reallocesque;
|
||||
void *dlmemalign(size_t, size_t) hidden attributeallocalign((1))
|
||||
attributeallocsize((2)) returnspointerwithnoaliases libcesque nodiscard;
|
||||
int dlmalloc_trim(size_t) hidden;
|
||||
size_t dlmalloc_usable_size(const void *) hidden;
|
||||
int dlposix_memalign(void **, size_t, size_t) hidden;
|
||||
void **dlindependent_calloc(size_t, size_t, void *[]) hidden;
|
||||
void **dlindependent_comalloc(size_t, size_t[], void *[]) hidden;
|
||||
struct MallocStats dlmalloc_stats(mstate) hidden;
|
||||
|
|
6
third_party/dlmalloc/dlmalloc.mk
vendored
6
third_party/dlmalloc/dlmalloc.mk
vendored
|
@ -52,6 +52,12 @@ $(THIRD_PARTY_DLMALLOC_A_OBJS): \
|
|||
$(NO_MAGIC) \
|
||||
-fno-sanitize=address
|
||||
|
||||
ifneq ($(MODE),dbg)
|
||||
$(THIRD_PARTY_DLMALLOC_A_OBJS): \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-DNDEBUG
|
||||
endif
|
||||
|
||||
THIRD_PARTY_DLMALLOC_LIBS = $(foreach x,$(THIRD_PARTY_DLMALLOC_ARTIFACTS),$($(x)))
|
||||
THIRD_PARTY_DLMALLOC_SRCS = $(foreach x,$(THIRD_PARTY_DLMALLOC_ARTIFACTS),$($(x)_SRCS))
|
||||
THIRD_PARTY_DLMALLOC_HDRS = $(foreach x,$(THIRD_PARTY_DLMALLOC_ARTIFACTS),$($(x)_HDRS))
|
||||
|
|
3
third_party/dlmalloc/dlmalloc_stats.c
vendored
3
third_party/dlmalloc/dlmalloc_stats.c
vendored
|
@ -21,6 +21,7 @@
|
|||
* More information can be obtained by calling mallinfo.
|
||||
*/
|
||||
struct MallocStats dlmalloc_stats(mstate m) {
|
||||
struct MallocChunk *q;
|
||||
struct MallocStats res;
|
||||
bzero(&res, sizeof(res));
|
||||
ensure_initialization();
|
||||
|
@ -32,7 +33,7 @@ struct MallocStats dlmalloc_stats(mstate m) {
|
|||
res.fp = m->footprint;
|
||||
res.used = res.fp - (m->topsize + TOP_FOOT_SIZE);
|
||||
while (s != 0) {
|
||||
mchunkptr q = align_as_chunk(s->base);
|
||||
q = align_as_chunk(s->base);
|
||||
while (segment_holds(s, q) && q != m->top &&
|
||||
q->head != FENCEPOST_HEAD) {
|
||||
if (!is_inuse(q)) res.used -= chunksize(q);
|
||||
|
|
28
third_party/dlmalloc/dlposix_memalign.c
vendored
28
third_party/dlmalloc/dlposix_memalign.c
vendored
|
@ -1,28 +0,0 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
|
||||
int dlposix_memalign(void** pp, size_t alignment, size_t bytes) {
|
||||
void* mem;
|
||||
size_t d, r;
|
||||
mem = NULL;
|
||||
if (alignment == MALLOC_ALIGNMENT) {
|
||||
mem = dlmalloc(bytes);
|
||||
} else {
|
||||
d = alignment / sizeof(void*);
|
||||
r = alignment % sizeof(void*);
|
||||
if (r != 0 || d == 0 || (d & (d - SIZE_T_ONE)) != 0) {
|
||||
return einval();
|
||||
} else if (bytes <= MAX_REQUEST - alignment) {
|
||||
if (alignment < MIN_CHUNK_SIZE) alignment = MIN_CHUNK_SIZE;
|
||||
mem = dlmemalign$impl(g_dlmalloc, alignment, bytes);
|
||||
}
|
||||
}
|
||||
if (mem == 0) {
|
||||
return enomem();
|
||||
} else {
|
||||
*pp = mem;
|
||||
return 0;
|
||||
}
|
||||
}
|
10
third_party/dlmalloc/dlpvalloc.c
vendored
10
third_party/dlmalloc/dlpvalloc.c
vendored
|
@ -1,10 +0,0 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
|
||||
void *dlpvalloc(size_t bytes) {
|
||||
size_t pagesz;
|
||||
ensure_initialization();
|
||||
pagesz = g_mparams.page_size;
|
||||
return dlmemalign(pagesz,
|
||||
(bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
|
||||
}
|
63
third_party/dlmalloc/dlrealloc.c
vendored
63
third_party/dlmalloc/dlrealloc.c
vendored
|
@ -1,42 +1,47 @@
|
|||
#include "libc/bits/likely.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
|
||||
void *dlrealloc(void *oldmem, size_t bytes) {
|
||||
void *mem = 0;
|
||||
if (oldmem == 0) {
|
||||
mem = dlmalloc(bytes);
|
||||
} else if (bytes >= MAX_REQUEST) {
|
||||
enomem();
|
||||
} else if (bytes == 0) {
|
||||
dlfree(oldmem);
|
||||
} else {
|
||||
size_t nb = request2size(bytes);
|
||||
mchunkptr oldp = mem2chunk(oldmem);
|
||||
size_t oc, nb;
|
||||
struct MallocState *m;
|
||||
struct MallocChunk *oldp, *newp;
|
||||
if (oldmem) {
|
||||
if (LIKELY(bytes < MAX_REQUEST)) {
|
||||
if (bytes) {
|
||||
nb = request2size(bytes);
|
||||
oldp = mem2chunk(oldmem);
|
||||
#if !FOOTERS
|
||||
mstate m = g_dlmalloc;
|
||||
#else /* FOOTERS */
|
||||
mstate m = get_mstate_for(oldp);
|
||||
if (!ok_magic(m)) {
|
||||
USAGE_ERROR_ACTION(m, oldmem);
|
||||
return 0;
|
||||
}
|
||||
#endif /* FOOTERS */
|
||||
if (!PREACTION(m)) {
|
||||
mchunkptr newp = dlmalloc_try_realloc_chunk(m, oldp, nb, 1);
|
||||
POSTACTION(m);
|
||||
if (newp != 0) {
|
||||
check_inuse_chunk(m, newp);
|
||||
mem = chunk2mem(newp);
|
||||
} else {
|
||||
mem = dlmalloc(bytes);
|
||||
if (mem != 0) {
|
||||
size_t oc = chunksize(oldp) - overhead_for(oldp);
|
||||
memcpy(mem, oldmem, (oc < bytes) ? oc : bytes);
|
||||
dlfree(oldmem);
|
||||
m = g_dlmalloc;
|
||||
#else /* FOOTERS */
|
||||
m = get_mstate_for(oldp);
|
||||
if (UNLIKELY(!ok_magic(m))) {
|
||||
USAGE_ERROR_ACTION(m, oldmem);
|
||||
return 0;
|
||||
}
|
||||
#endif /* FOOTERS */
|
||||
if (!PREACTION(m)) {
|
||||
newp = dlmalloc_try_realloc_chunk(m, oldp, nb, 1);
|
||||
POSTACTION(m);
|
||||
if (newp) {
|
||||
check_inuse_chunk(m, newp);
|
||||
mem = chunk2mem(newp);
|
||||
} else if ((mem = dlmalloc(bytes))) {
|
||||
oc = chunksize(oldp) - overhead_for(oldp);
|
||||
memcpy(mem, oldmem, (oc < bytes) ? oc : bytes);
|
||||
dlfree(oldmem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dlfree(oldmem);
|
||||
}
|
||||
} else {
|
||||
enomem();
|
||||
}
|
||||
} else {
|
||||
mem = dlmalloc(bytes);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
|
9
third_party/dlmalloc/dlvalloc.c
vendored
9
third_party/dlmalloc/dlvalloc.c
vendored
|
@ -1,9 +0,0 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
|
||||
void *dlvalloc(size_t bytes) {
|
||||
size_t pagesz;
|
||||
ensure_initialization();
|
||||
pagesz = g_mparams.page_size;
|
||||
return dlmemalign(pagesz, bytes);
|
||||
}
|
21
third_party/dlmalloc/malloc_inspect_all.c
vendored
21
third_party/dlmalloc/malloc_inspect_all.c
vendored
|
@ -2,10 +2,10 @@
|
|||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
|
||||
static void internal_inspect_all(mstate m,
|
||||
void (*handler)(void* start, void* end,
|
||||
void (*handler)(void *start, void *end,
|
||||
size_t used_bytes,
|
||||
void* callback_arg),
|
||||
void* arg) {
|
||||
void *callback_arg),
|
||||
void *arg) {
|
||||
if (is_initialized(m)) {
|
||||
mchunkptr top = m->top;
|
||||
msegmentptr s;
|
||||
|
@ -15,20 +15,21 @@ static void internal_inspect_all(mstate m,
|
|||
mchunkptr next = next_chunk(q);
|
||||
size_t sz = chunksize(q);
|
||||
size_t used;
|
||||
void* start;
|
||||
void *start;
|
||||
if (is_inuse(q)) {
|
||||
used = sz - CHUNK_OVERHEAD; /* must not be mmapped */
|
||||
start = chunk2mem(q);
|
||||
} else {
|
||||
used = 0;
|
||||
if (is_small(sz)) { /* offset by possible bookkeeping */
|
||||
start = (void*)((char*)q + sizeof(struct malloc_chunk));
|
||||
start = (void *)((char *)q + sizeof(struct MallocChunk));
|
||||
} else {
|
||||
start = (void*)((char*)q + sizeof(struct malloc_tree_chunk));
|
||||
start = (void *)((char *)q + sizeof(struct MallocTreeChunk));
|
||||
}
|
||||
}
|
||||
if (start < (void*)next) /* skip if all space is bookkeeping */
|
||||
if (start < (void *)next) { /* skip if all space is bookkeeping */
|
||||
handler(start, next, used, arg);
|
||||
}
|
||||
if (q == top) break;
|
||||
q = next;
|
||||
}
|
||||
|
@ -60,9 +61,9 @@ static void internal_inspect_all(mstate m,
|
|||
*
|
||||
* malloc_inspect_all(count_chunks, NULL);
|
||||
*/
|
||||
void malloc_inspect_all(void (*handler)(void* start, void* end,
|
||||
size_t used_bytes, void* callback_arg),
|
||||
void* arg) {
|
||||
void malloc_inspect_all(void (*handler)(void *start, void *end,
|
||||
size_t used_bytes, void *callback_arg),
|
||||
void *arg) {
|
||||
ensure_initialization();
|
||||
if (!PREACTION(g_dlmalloc)) {
|
||||
internal_inspect_all(g_dlmalloc, handler, arg);
|
||||
|
|
1
third_party/dlmalloc/malloc_trim.c
vendored
1
third_party/dlmalloc/malloc_trim.c
vendored
|
@ -21,6 +21,7 @@
|
|||
* @return 1 if it actually released any memory, else 0
|
||||
*/
|
||||
int dlmalloc_trim(size_t pad) {
|
||||
/* asan runtime depends on this function */
|
||||
int result = 0;
|
||||
ensure_initialization();
|
||||
if (!PREACTION(g_dlmalloc)) {
|
||||
|
|
40
third_party/gdtoa/dmisc.c
vendored
40
third_party/gdtoa/dmisc.c
vendored
|
@ -32,8 +32,16 @@
|
|||
#include "third_party/gdtoa/gdtoa.internal.h"
|
||||
/* clang-format off */
|
||||
|
||||
void
|
||||
freedtoa(char *s)
|
||||
{
|
||||
Bigint *b = (Bigint *)((int *)s - 1);
|
||||
b->maxwds = 1 << (b->k = *(int*)b);
|
||||
__gdtoa_Bfree(b);
|
||||
}
|
||||
|
||||
char *
|
||||
rv_alloc(int i)
|
||||
__gdtoa_rv_alloc(int i)
|
||||
{
|
||||
int j, k, *r;
|
||||
j = sizeof(ULong);
|
||||
|
@ -41,16 +49,16 @@ rv_alloc(int i)
|
|||
(int)(sizeof(Bigint) - sizeof(ULong) - sizeof(int)) + j <= i;
|
||||
j <<= 1)
|
||||
k++;
|
||||
r = (int*)Balloc(k);
|
||||
r = (int*)__gdtoa_Balloc(k);
|
||||
*r = k;
|
||||
return (char *)(r+1);
|
||||
}
|
||||
|
||||
char *
|
||||
nrv_alloc(char *s, char **rve, int n)
|
||||
__gdtoa_nrv_alloc(char *s, char **rve, int n)
|
||||
{
|
||||
char *rv, *t;
|
||||
t = rv = rv_alloc(n);
|
||||
t = rv = __gdtoa_rv_alloc(n);
|
||||
while((*t = *s++) !=0)
|
||||
t++;
|
||||
if (rve)
|
||||
|
@ -58,16 +66,8 @@ nrv_alloc(char *s, char **rve, int n)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
freedtoa(char *s)
|
||||
{
|
||||
Bigint *b = (Bigint *)((int *)s - 1);
|
||||
b->maxwds = 1 << (b->k = *(int*)b);
|
||||
Bfree(b);
|
||||
}
|
||||
|
||||
int
|
||||
quorem(Bigint *b, Bigint *S)
|
||||
__gdtoa_quorem(Bigint *b, Bigint *S)
|
||||
{
|
||||
int n;
|
||||
ULong *bx, *bxe, q, *sx, *sxe;
|
||||
|
@ -75,7 +75,7 @@ quorem(Bigint *b, Bigint *S)
|
|||
n = S->wds;
|
||||
#ifdef DEBUG
|
||||
if (b->wds > n)
|
||||
Bug("oversize b in quorem");
|
||||
Bug("oversize b in __gdtoa_quorem");
|
||||
#endif
|
||||
if (b->wds < n)
|
||||
return 0;
|
||||
|
@ -86,7 +86,7 @@ quorem(Bigint *b, Bigint *S)
|
|||
q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
|
||||
#ifdef DEBUG
|
||||
if (q > 9)
|
||||
Bug("oversized quotient in quorem");
|
||||
Bug("oversized quotient in __gdtoa_quorem");
|
||||
#endif
|
||||
if (q) {
|
||||
borrow = 0;
|
||||
|
@ -94,9 +94,9 @@ quorem(Bigint *b, Bigint *S)
|
|||
do {
|
||||
ys = *sx++ * (ULLong)q + carry;
|
||||
carry = ys >> 32;
|
||||
y = *bx - (ys & 0xffffffffUL) - borrow;
|
||||
y = *bx - (ys & 0xffffffff) - borrow;
|
||||
borrow = y >> 32 & 1UL;
|
||||
*bx++ = y & 0xffffffffUL;
|
||||
*bx++ = y & 0xffffffff;
|
||||
}
|
||||
while(sx <= sxe);
|
||||
if (!*bxe) {
|
||||
|
@ -106,7 +106,7 @@ quorem(Bigint *b, Bigint *S)
|
|||
b->wds = n;
|
||||
}
|
||||
}
|
||||
if (cmp(b, S) >= 0) {
|
||||
if (__gdtoa_cmp(b, S) >= 0) {
|
||||
q++;
|
||||
borrow = 0;
|
||||
carry = 0;
|
||||
|
@ -115,9 +115,9 @@ quorem(Bigint *b, Bigint *S)
|
|||
do {
|
||||
ys = *sx++ + carry;
|
||||
carry = ys >> 32;
|
||||
y = *bx - (ys & 0xffffffffUL) - borrow;
|
||||
y = *bx - (ys & 0xffffffff) - borrow;
|
||||
borrow = y >> 32 & 1UL;
|
||||
*bx++ = y & 0xffffffffUL;
|
||||
*bx++ = y & 0xffffffff;
|
||||
}
|
||||
while(sx <= sxe);
|
||||
bx = b->x;
|
||||
|
|
116
third_party/gdtoa/dtoa.c
vendored
116
third_party/gdtoa/dtoa.c
vendored
|
@ -41,12 +41,12 @@
|
|||
* Modifications:
|
||||
* 1. Rather than iterating, we use a simple numeric overestimate
|
||||
* to determine k = floor(log10(d)). We scale relevant
|
||||
* quantities using O(log2(k)) rather than O(k) multiplications.
|
||||
* quantities using O(log2(k)) rather than O(k) __gdtoa_multiplications.
|
||||
* 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
|
||||
* try to generate digits strictly left to right. Instead, we
|
||||
* compute with fewer bits and propagate the carry if necessary
|
||||
* when rounding the final digit up. This is often faster.
|
||||
* 3. Under the assumption that input will be rounded nearest,
|
||||
* 3. Under the as__gdtoa_sumption that input will be rounded nearest,
|
||||
* mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
|
||||
* That is, we allow equality in stopping tests when the
|
||||
* round-nearest rule will give the same floating-point value
|
||||
|
@ -56,10 +56,10 @@
|
|||
* quantities.
|
||||
* 5. When converting floating-point integers less than 1e16,
|
||||
* we use floating-point arithmetic rather than resorting
|
||||
* to multiple-precision integers.
|
||||
* to __gdtoa_multiple-precision integers.
|
||||
* 6. When asked to produce fewer than 15 digits, we first try
|
||||
* to get by with floating-point arithmetic; we resort to
|
||||
* multiple-precision integer arithmetic only if we cannot
|
||||
* __gdtoa_multiple-precision integer arithmetic only if we cannot
|
||||
* guarantee that the floating-point calculation has given
|
||||
* the correctly rounded result. For k requested digits and
|
||||
* "uniformly" distributed input, the probability is
|
||||
|
@ -128,12 +128,12 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
/* Infinity or NaN */
|
||||
*decpt = 9999;
|
||||
if (!word1(&d) && !(word0(&d) & 0xfffff))
|
||||
return nrv_alloc("Infinity", rve, 8);
|
||||
return nrv_alloc("NaN", rve, 3);
|
||||
return __gdtoa_nrv_alloc("Infinity", rve, 8);
|
||||
return __gdtoa_nrv_alloc("NaN", rve, 3);
|
||||
}
|
||||
if (!dval(&d)) {
|
||||
*decpt = 1;
|
||||
return nrv_alloc("0", rve, 1);
|
||||
return __gdtoa_nrv_alloc("0", rve, 1);
|
||||
}
|
||||
if (Rounding >= 2) {
|
||||
if (*sign)
|
||||
|
@ -142,7 +142,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
if (Rounding != 2)
|
||||
Rounding = 0;
|
||||
}
|
||||
b = d2b(dval(&d), &be, &bbits);
|
||||
b = __gdtoa_d2b(dval(&d), &be, &bbits);
|
||||
if (( i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {
|
||||
dval(&d2) = dval(&d);
|
||||
word0(&d2) &= Frac_mask1;
|
||||
|
@ -160,7 +160,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
* We want k to be too large rather than too small.
|
||||
* The error in the first-order Taylor series approximation
|
||||
* is in our favor, so we just round up the constant enough
|
||||
* to compensate for any error in the multiplication of
|
||||
* to compensate for any error in the __gdtoa_multiplication of
|
||||
* (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
|
||||
* and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
|
||||
* adding 1e-13 to the constant term more than suffices.
|
||||
|
@ -187,7 +187,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
k--; /* want k = floor(ds) */
|
||||
k_check = 1;
|
||||
if (k >= 0 && k <= Ten_pmax) {
|
||||
if (dval(&d) < tens[k])
|
||||
if (dval(&d) < __gdtoa_tens[k])
|
||||
k--;
|
||||
k_check = 0;
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
if (i <= 0)
|
||||
i = 1;
|
||||
}
|
||||
s = s0 = rv_alloc(i);
|
||||
s = s0 = __gdtoa_rv_alloc(i);
|
||||
if (mode > 1 && Rounding != 1)
|
||||
leftright = 0;
|
||||
if (ilim >= 0 && ilim <= Quick_max && try_quick) {
|
||||
|
@ -257,27 +257,27 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
ilim0 = ilim;
|
||||
ieps = 2; /* conservative */
|
||||
if (k > 0) {
|
||||
ds = tens[k&0xf];
|
||||
ds = __gdtoa_tens[k&0xf];
|
||||
j = k >> 4;
|
||||
if (j & Bletch) {
|
||||
/* prevent overflows */
|
||||
j &= Bletch - 1;
|
||||
dval(&d) /= bigtens[n_bigtens-1];
|
||||
dval(&d) /= __gdtoa_bigtens[n___gdtoa_bigtens-1];
|
||||
ieps++;
|
||||
}
|
||||
for(; j; j >>= 1, i++)
|
||||
if (j & 1) {
|
||||
ieps++;
|
||||
ds *= bigtens[i];
|
||||
ds *= __gdtoa_bigtens[i];
|
||||
}
|
||||
dval(&d) /= ds;
|
||||
}
|
||||
else if (( j1 = -k )!=0) {
|
||||
dval(&d) *= tens[j1 & 0xf];
|
||||
dval(&d) *= __gdtoa_tens[j1 & 0xf];
|
||||
for(j = j1 >> 4; j; j >>= 1, i++)
|
||||
if (j & 1) {
|
||||
ieps++;
|
||||
dval(&d) *= bigtens[i];
|
||||
dval(&d) *= __gdtoa_bigtens[i];
|
||||
}
|
||||
}
|
||||
if (k_check && dval(&d) < 1. && ilim > 0) {
|
||||
|
@ -303,14 +303,14 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
/* Use Steele & White method of only
|
||||
* generating digits needed.
|
||||
*/
|
||||
dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
|
||||
dval(&eps) = 0.5/__gdtoa_tens[ilim-1] - dval(&eps);
|
||||
if (k0 < 0 && j1 >= 307) {
|
||||
eps1.d = 1.01e256; /* 1.01 allows roundoff in the next few lines */
|
||||
word0(&eps1) -= Exp_msk1 * (Bias+P-1);
|
||||
dval(&eps1) *= tens[j1 & 0xf];
|
||||
dval(&eps1) *= __gdtoa_tens[j1 & 0xf];
|
||||
for(i = 0, j = (j1-256) >> 4; j; j >>= 1, i++)
|
||||
if (j & 1)
|
||||
dval(&eps1) *= bigtens[i];
|
||||
dval(&eps1) *= __gdtoa_bigtens[i];
|
||||
if (eps.d < eps1.d)
|
||||
eps.d = eps1.d;
|
||||
if (10. - d.d < 10.*eps.d && eps.d < 1.) {
|
||||
|
@ -336,7 +336,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
}
|
||||
else {
|
||||
/* Generate ilim digits, then fix them up. */
|
||||
dval(&eps) *= tens[ilim-1];
|
||||
dval(&eps) *= __gdtoa_tens[ilim-1];
|
||||
for(i = 1;; i++, dval(&d) *= 10.) {
|
||||
L = (Long)(dval(&d));
|
||||
if (!(dval(&d) -= L))
|
||||
|
@ -361,7 +361,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
/* Do we have a "small" integer? */
|
||||
if (be >= 0 && k <= Int_max) {
|
||||
/* Yes. */
|
||||
ds = tens[k];
|
||||
ds = __gdtoa_tens[k];
|
||||
if (ndigits < 0 && ilim <= 0) {
|
||||
S = mhi = 0;
|
||||
if (ilim < 0 || dval(&d) <= 5*ds)
|
||||
|
@ -409,7 +409,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
i = denorm ? be + (Bias + (P-1) - 1 + 1) : 1 + P - bbits;
|
||||
b2 += i;
|
||||
s2 += i;
|
||||
mhi = i2b(1);
|
||||
mhi = __gdtoa_i2b(1);
|
||||
}
|
||||
if (m2 > 0 && s2 > 0) {
|
||||
i = m2 < s2 ? m2 : s2;
|
||||
|
@ -420,20 +420,20 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
if (b5 > 0) {
|
||||
if (leftright) {
|
||||
if (m5 > 0) {
|
||||
mhi = pow5mult(mhi, m5);
|
||||
b1 = mult(mhi, b);
|
||||
Bfree(b);
|
||||
mhi = __gdtoa_pow5mult(mhi, m5);
|
||||
b1 = __gdtoa_mult(mhi, b);
|
||||
__gdtoa_Bfree(b);
|
||||
b = b1;
|
||||
}
|
||||
if (( j = b5 - m5 )!=0)
|
||||
b = pow5mult(b, j);
|
||||
b = __gdtoa_pow5mult(b, j);
|
||||
}
|
||||
else
|
||||
b = pow5mult(b, b5);
|
||||
b = __gdtoa_pow5mult(b, b5);
|
||||
}
|
||||
S = i2b(1);
|
||||
S = __gdtoa_i2b(1);
|
||||
if (s5 > 0)
|
||||
S = pow5mult(S, s5);
|
||||
S = __gdtoa_pow5mult(S, s5);
|
||||
|
||||
/* Check for special case that d is a normalized power of 2. */
|
||||
spec_case = 0;
|
||||
|
@ -451,7 +451,7 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
* shift left if necessary so divisor has 4 leading 0 bits.
|
||||
*
|
||||
* Perhaps we should just compute leading 28 bits of S once
|
||||
* and for all and pass them and a shift to quorem, so it
|
||||
* and for all and pass them and a shift to __gdtoa_quorem, so it
|
||||
* can do shifts and ors to compute the numerator for q.
|
||||
*/
|
||||
if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f )!=0)
|
||||
|
@ -469,20 +469,20 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
s2 += i;
|
||||
}
|
||||
if (b2 > 0)
|
||||
b = lshift(b, b2);
|
||||
b = __gdtoa_lshift(b, b2);
|
||||
if (s2 > 0)
|
||||
S = lshift(S, s2);
|
||||
S = __gdtoa_lshift(S, s2);
|
||||
if (k_check) {
|
||||
if (cmp(b,S) < 0) {
|
||||
if (__gdtoa_cmp(b,S) < 0) {
|
||||
k--;
|
||||
b = multadd(b, 10, 0); /* we botched the k estimate */
|
||||
b = __gdtoa_multadd(b, 10, 0); /* we botched the k estimate */
|
||||
if (leftright)
|
||||
mhi = multadd(mhi, 10, 0);
|
||||
mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
ilim = ilim1;
|
||||
}
|
||||
}
|
||||
if (ilim <= 0 && (mode == 3 || mode == 5)) {
|
||||
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
|
||||
if (ilim < 0 || __gdtoa_cmp(b,S = __gdtoa_multadd(S,5,0)) <= 0) {
|
||||
/* no digits, fcvt style */
|
||||
no_digits:
|
||||
k = -1 - ndigits;
|
||||
|
@ -495,25 +495,25 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
}
|
||||
if (leftright) {
|
||||
if (m2 > 0)
|
||||
mhi = lshift(mhi, m2);
|
||||
mhi = __gdtoa_lshift(mhi, m2);
|
||||
/* Compute mlo -- check for special case
|
||||
* that d is a normalized power of 2.
|
||||
*/
|
||||
mlo = mhi;
|
||||
if (spec_case) {
|
||||
mhi = Balloc(mhi->k);
|
||||
mhi = __gdtoa_Balloc(mhi->k);
|
||||
Bcopy(mhi, mlo);
|
||||
mhi = lshift(mhi, Log2P);
|
||||
mhi = __gdtoa_lshift(mhi, Log2P);
|
||||
}
|
||||
for(i = 1;;i++) {
|
||||
dig = quorem(b,S) + '0';
|
||||
dig = __gdtoa_quorem(b,S) + '0';
|
||||
/* Do we yet have the shortest decimal string
|
||||
* that will round to d?
|
||||
*/
|
||||
j = cmp(b, mlo);
|
||||
delta = diff(S, mhi);
|
||||
j1 = delta->sign ? 1 : cmp(b, delta);
|
||||
Bfree(delta);
|
||||
j = __gdtoa_cmp(b, mlo);
|
||||
delta = __gdtoa_diff(S, mhi);
|
||||
j1 = delta->sign ? 1 : __gdtoa_cmp(b, delta);
|
||||
__gdtoa_Bfree(delta);
|
||||
if (j1 == 0 && mode != 1 && !(word1(&d) & 1) && Rounding >= 1) {
|
||||
if (dig == '9')
|
||||
goto round_9_up;
|
||||
|
@ -533,8 +533,8 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
case 2: goto keep_dig;
|
||||
}
|
||||
if (j1 > 0) {
|
||||
b = lshift(b, 1);
|
||||
j1 = cmp(b, S);
|
||||
b = __gdtoa_lshift(b, 1);
|
||||
j1 = __gdtoa_cmp(b, S);
|
||||
if ((j1 > 0 || (j1 == 0 && dig & 1))
|
||||
&& dig++ == '9')
|
||||
goto round_9_up;
|
||||
|
@ -558,24 +558,24 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
*s++ = dig;
|
||||
if (i == ilim)
|
||||
break;
|
||||
b = multadd(b, 10, 0);
|
||||
b = __gdtoa_multadd(b, 10, 0);
|
||||
if (mlo == mhi)
|
||||
mlo = mhi = multadd(mhi, 10, 0);
|
||||
mlo = mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
else {
|
||||
mlo = multadd(mlo, 10, 0);
|
||||
mhi = multadd(mhi, 10, 0);
|
||||
mlo = __gdtoa_multadd(mlo, 10, 0);
|
||||
mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i = 1;; i++) {
|
||||
*s++ = dig = quorem(b,S) + '0';
|
||||
*s++ = dig = __gdtoa_quorem(b,S) + '0';
|
||||
if (!b->x[0] && b->wds <= 1) {
|
||||
goto ret;
|
||||
}
|
||||
if (i >= ilim)
|
||||
break;
|
||||
b = multadd(b, 10, 0);
|
||||
b = __gdtoa_multadd(b, 10, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -584,8 +584,8 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
case 0: goto trimzeros;
|
||||
case 2: goto roundoff;
|
||||
}
|
||||
b = lshift(b, 1);
|
||||
j = cmp(b, S);
|
||||
b = __gdtoa_lshift(b, 1);
|
||||
j = __gdtoa_cmp(b, S);
|
||||
if (j > 0 || (j == 0 && dig & 1))
|
||||
{
|
||||
roundoff:
|
||||
|
@ -603,17 +603,17 @@ dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
|
|||
s++;
|
||||
}
|
||||
ret:
|
||||
Bfree(S);
|
||||
__gdtoa_Bfree(S);
|
||||
if (mhi) {
|
||||
if (mlo && mlo != mhi)
|
||||
Bfree(mlo);
|
||||
Bfree(mhi);
|
||||
__gdtoa_Bfree(mlo);
|
||||
__gdtoa_Bfree(mhi);
|
||||
}
|
||||
retc:
|
||||
while(s > s0 && s[-1] == '0')
|
||||
--s;
|
||||
ret1:
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
*s = 0;
|
||||
*decpt = k + 1;
|
||||
if (rve)
|
||||
|
|
6
third_party/gdtoa/g__fmt.c
vendored
6
third_party/gdtoa/g__fmt.c
vendored
|
@ -40,8 +40,8 @@
|
|||
#define ldus_QNAN3 0
|
||||
#define ldus_QNAN4 0
|
||||
|
||||
const char *const InfName[6] = { "Infinity", "infinity", "INFINITY", "Inf", "inf", "INF" };
|
||||
const char *const NanName[3] = { "NaN", "nan", "NAN" };
|
||||
const char *const __gdtoa_InfName[6] = { "Infinity", "infinity", "INFINITY", "Inf", "inf", "INF" };
|
||||
const char *const __gdtoa_NanName[3] = { "NaN", "nan", "NAN" };
|
||||
const ULong __gdtoa_NanDflt_Q[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0x7fffffff };
|
||||
const ULong __gdtoa_NanDflt_d[2] = { d_QNAN1, d_QNAN0 };
|
||||
const ULong __gdtoa_NanDflt_f[1] = { f_QNAN };
|
||||
|
@ -49,7 +49,7 @@ const ULong __gdtoa_NanDflt_xL[3] = { 1, 0x80000000, 0x7fff0000 };
|
|||
const UShort __gdtoa_NanDflt_ldus[5] = { ldus_QNAN4, ldus_QNAN3, ldus_QNAN2, ldus_QNAN1, ldus_QNAN0 };
|
||||
|
||||
char *
|
||||
g__fmt(char *b, char *s, char *se, int decpt, ULong sign, size_t blen)
|
||||
__gdtoa_g__fmt(char *b, char *s, char *se, int decpt, ULong sign, size_t blen)
|
||||
{
|
||||
int i, j, k;
|
||||
char *be, *s0;
|
||||
|
|
24
third_party/gdtoa/g_ddfmt.c
vendored
24
third_party/gdtoa/g_ddfmt.c
vendored
|
@ -84,38 +84,38 @@ g_ddfmt(char *buf, double *dd0, int ndig, size_t bufsize)
|
|||
dd = ddx;
|
||||
L = dd->L;
|
||||
}
|
||||
z = d2b(dval(&dd[0]), &ex, &bx);
|
||||
z = __gdtoa_d2b(dval(&dd[0]), &ex, &bx);
|
||||
if (dval(&dd[1]) == 0.)
|
||||
goto no_y;
|
||||
x = z;
|
||||
y = d2b(dval(&dd[1]), &ey, &by);
|
||||
y = __gdtoa_d2b(dval(&dd[1]), &ey, &by);
|
||||
if ( (i = ex - ey) !=0) {
|
||||
if (i > 0) {
|
||||
x = lshift(x, i);
|
||||
x = __gdtoa_lshift(x, i);
|
||||
ex = ey;
|
||||
}
|
||||
else
|
||||
y = lshift(y, -i);
|
||||
y = __gdtoa_lshift(y, -i);
|
||||
}
|
||||
if ((L[1] ^ L[2+1]) & 0x80000000L) {
|
||||
z = diff(x, y);
|
||||
z = __gdtoa_diff(x, y);
|
||||
if (L[1] & 0x80000000L)
|
||||
z->sign = 1 - z->sign;
|
||||
}
|
||||
else {
|
||||
z = sum(x, y);
|
||||
z = __gdtoa_sum(x, y);
|
||||
if (L[1] & 0x80000000L)
|
||||
z->sign = 1;
|
||||
}
|
||||
Bfree(x);
|
||||
Bfree(y);
|
||||
__gdtoa_Bfree(x);
|
||||
__gdtoa_Bfree(y);
|
||||
no_y:
|
||||
bits = zx = z->x;
|
||||
for(i = 0; !*zx; zx++)
|
||||
i += 32;
|
||||
i += lo0bits(zx);
|
||||
if (i) {
|
||||
rshift(z, i);
|
||||
__gdtoa_rshift(z, i);
|
||||
ex += i;
|
||||
}
|
||||
fpi.nbits = z->wds * 32 - hi0bits(z->x[j = z->wds-1]);
|
||||
|
@ -132,7 +132,7 @@ no_y:
|
|||
mode = 2;
|
||||
if (ndig <= 0) {
|
||||
if (bufsize < (size_t)(fpi.nbits * .301029995664) + 10) {
|
||||
Bfree(z);
|
||||
__gdtoa_Bfree(z);
|
||||
return 0;
|
||||
}
|
||||
mode = 0;
|
||||
|
@ -144,7 +144,7 @@ no_y:
|
|||
fpi.int_max = Int_max;
|
||||
i = STRTOG_Normal;
|
||||
s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
b = g__fmt(buf, s, se, decpt, z->sign, bufsize);
|
||||
Bfree(z);
|
||||
b = __gdtoa_g__fmt(buf, s, se, decpt, z->sign, bufsize);
|
||||
__gdtoa_Bfree(z);
|
||||
return b;
|
||||
}
|
||||
|
|
30
third_party/gdtoa/g_ddfmt_p.c
vendored
30
third_party/gdtoa/g_ddfmt_p.c
vendored
|
@ -59,7 +59,7 @@ g_ddfmt_p(char *buf, double *dd0, int ndig, size_t bufsize, int nik)
|
|||
b = buf;
|
||||
if (sign && nik < 18)
|
||||
*b++ = '-';
|
||||
b = stpcpy(b, NanName[nik%3]);
|
||||
b = stpcpy(b, __gdtoa_NanName[nik%3]);
|
||||
if (nik > 5 && (nik < 12
|
||||
|| L[0] != __gdtoa_NanDflt_d[0]
|
||||
|| (L[1] ^ __gdtoa_NanDflt_d[1]) & 0xfffff
|
||||
|
@ -69,7 +69,7 @@ g_ddfmt_p(char *buf, double *dd0, int ndig, size_t bufsize, int nik)
|
|||
bits0[1] = (L[2+1] & 0xfffff) | (L[0] << 20);
|
||||
bits0[2] = (L[0] >> 12) | (L[1] << 20);
|
||||
bits0[3] = (L[1] >> 12) & 0xff;
|
||||
b = add_nanbits(b, bufsize - (b-buf), bits0, 4);
|
||||
b = __gdtoa_add_nanbits(b, bufsize - (b-buf), bits0, 4);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ g_ddfmt_p(char *buf, double *dd0, int ndig, size_t bufsize, int nik)
|
|||
b = buf;
|
||||
if (L[1] & 0x80000000L)
|
||||
*b++ = '-';
|
||||
return stpcpy(b, InfName[nik%6]);
|
||||
return stpcpy(b, __gdtoa_InfName[nik%6]);
|
||||
}
|
||||
if ((L[2+1] & 0x7ff00000) == 0x7ff00000) {
|
||||
L += 2;
|
||||
|
@ -105,38 +105,38 @@ g_ddfmt_p(char *buf, double *dd0, int ndig, size_t bufsize, int nik)
|
|||
dd = ddx;
|
||||
L = dd->L;
|
||||
}
|
||||
z = d2b(dval(&dd[0]), &ex, &bx);
|
||||
z = __gdtoa_d2b(dval(&dd[0]), &ex, &bx);
|
||||
if (dval(&dd[1]) == 0.)
|
||||
goto no_y;
|
||||
x = z;
|
||||
y = d2b(dval(&dd[1]), &ey, &by);
|
||||
y = __gdtoa_d2b(dval(&dd[1]), &ey, &by);
|
||||
if ( (i = ex - ey) !=0) {
|
||||
if (i > 0) {
|
||||
x = lshift(x, i);
|
||||
x = __gdtoa_lshift(x, i);
|
||||
ex = ey;
|
||||
}
|
||||
else
|
||||
y = lshift(y, -i);
|
||||
y = __gdtoa_lshift(y, -i);
|
||||
}
|
||||
if ((L[1] ^ L[2+1]) & 0x80000000L) {
|
||||
z = diff(x, y);
|
||||
z = __gdtoa_diff(x, y);
|
||||
if (L[1] & 0x80000000L)
|
||||
z->sign = 1 - z->sign;
|
||||
}
|
||||
else {
|
||||
z = sum(x, y);
|
||||
z = __gdtoa_sum(x, y);
|
||||
if (L[1] & 0x80000000L)
|
||||
z->sign = 1;
|
||||
}
|
||||
Bfree(x);
|
||||
Bfree(y);
|
||||
__gdtoa_Bfree(x);
|
||||
__gdtoa_Bfree(y);
|
||||
no_y:
|
||||
bits = zx = z->x;
|
||||
for(i = 0; !*zx; zx++)
|
||||
i += 32;
|
||||
i += lo0bits(zx);
|
||||
if (i) {
|
||||
rshift(z, i);
|
||||
__gdtoa_rshift(z, i);
|
||||
ex += i;
|
||||
}
|
||||
fpi.nbits = z->wds * 32 - hi0bits(z->x[j = z->wds-1]);
|
||||
|
@ -153,7 +153,7 @@ no_y:
|
|||
mode = 2;
|
||||
if (ndig <= 0) {
|
||||
if (bufsize < (size_t)(fpi.nbits * .301029995664) + 10) {
|
||||
Bfree(z);
|
||||
__gdtoa_Bfree(z);
|
||||
return 0;
|
||||
}
|
||||
mode = 0;
|
||||
|
@ -165,7 +165,7 @@ no_y:
|
|||
fpi.int_max = Int_max;
|
||||
i = STRTOG_Normal;
|
||||
s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
b = g__fmt(buf, s, se, decpt, z->sign, bufsize);
|
||||
Bfree(z);
|
||||
b = __gdtoa_g__fmt(buf, s, se, decpt, z->sign, bufsize);
|
||||
__gdtoa_Bfree(z);
|
||||
return b;
|
||||
}
|
||||
|
|
2
third_party/gdtoa/g_dfmt.c
vendored
2
third_party/gdtoa/g_dfmt.c
vendored
|
@ -80,5 +80,5 @@ g_dfmt(char *buf, double *d, int ndig, size_t bufsize)
|
|||
if (sign)
|
||||
i = STRTOG_Normal | STRTOG_Neg;
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
8
third_party/gdtoa/g_dfmt_p.c
vendored
8
third_party/gdtoa/g_dfmt_p.c
vendored
|
@ -58,20 +58,20 @@ g_dfmt_p(char *buf, double *d, int ndig, size_t bufsize, int nik)
|
|||
b = buf;
|
||||
if (L[1] & 0x80000000L && nik < 18)
|
||||
*b++ = '-';
|
||||
b = stpcpy(b, NanName[nik%3]);
|
||||
b = stpcpy(b, __gdtoa_NanName[nik%3]);
|
||||
if (nik > 5 && (nik < 12
|
||||
|| bits[0] != __gdtoa_NanDflt_d[0]
|
||||
|| (bits[1] ^ __gdtoa_NanDflt_d[1]) & 0xfffff)) {
|
||||
bits[0] = L[0];
|
||||
bits[1] = L[1] & 0xfffff;
|
||||
b = add_nanbits(b, bufsize - (b-buf), bits, 2);
|
||||
b = __gdtoa_add_nanbits(b, bufsize - (b-buf), bits, 2);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
b = buf;
|
||||
if (sign)
|
||||
*b++ = '-';
|
||||
return stpcpy(b, InfName[nik%6]);
|
||||
return stpcpy(b, __gdtoa_InfName[nik%6]);
|
||||
}
|
||||
if (L[0] == 0 && (L[1] ^ sign) == 0 /*d == 0.*/) {
|
||||
b = buf;
|
||||
|
@ -95,5 +95,5 @@ g_dfmt_p(char *buf, double *d, int ndig, size_t bufsize, int nik)
|
|||
if (sign)
|
||||
i = STRTOG_Normal | STRTOG_Neg;
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
2
third_party/gdtoa/g_ffmt.c
vendored
2
third_party/gdtoa/g_ffmt.c
vendored
|
@ -78,5 +78,5 @@ g_ffmt(char *buf, float *f, int ndig, size_t bufsize)
|
|||
}
|
||||
i = STRTOG_Normal;
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
8
third_party/gdtoa/g_ffmt_p.c
vendored
8
third_party/gdtoa/g_ffmt_p.c
vendored
|
@ -56,16 +56,16 @@ g_ffmt_p(char *buf, float *f, int ndig, size_t bufsize, int nik)
|
|||
b = buf;
|
||||
if (sign && nik < 18)
|
||||
*b++ = '-';
|
||||
b = stpcpy(b, NanName[nik%3]);
|
||||
b = stpcpy(b, __gdtoa_NanName[nik%3]);
|
||||
if (nik > 5 && (nik < 12
|
||||
|| (bits[0] ^ __gdtoa_NanDflt_f[0]) & 0x7fffff))
|
||||
b = add_nanbits(b, bufsize - (b-buf), bits, 1);
|
||||
b = __gdtoa_add_nanbits(b, bufsize - (b-buf), bits, 1);
|
||||
return b;
|
||||
}
|
||||
b = buf;
|
||||
if (sign)
|
||||
*b++ = '-';
|
||||
return stpcpy(b, InfName[nik%6]);
|
||||
return stpcpy(b, __gdtoa_InfName[nik%6]);
|
||||
}
|
||||
if (*f == 0.) {
|
||||
b = buf;
|
||||
|
@ -89,5 +89,5 @@ g_ffmt_p(char *buf, float *f, int ndig, size_t bufsize, int nik)
|
|||
}
|
||||
i = STRTOG_Normal;
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
2
third_party/gdtoa/g_xfmt.c
vendored
2
third_party/gdtoa/g_xfmt.c
vendored
|
@ -84,5 +84,5 @@ g_xfmt(char *buf, void *V, int ndig, size_t bufsize)
|
|||
mode = 0;
|
||||
}
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
8
third_party/gdtoa/g_xfmt_p.c
vendored
8
third_party/gdtoa/g_xfmt_p.c
vendored
|
@ -60,20 +60,20 @@ g_xfmt_p(char *buf, void *V, int ndig, size_t bufsize, int nik)
|
|||
b = buf;
|
||||
if (sign)
|
||||
*b++ = '-';
|
||||
b = stpcpy(b, InfName[nik%6]);
|
||||
b = stpcpy(b, __gdtoa_InfName[nik%6]);
|
||||
}
|
||||
else {
|
||||
b = buf;
|
||||
if (sign && nik < 18)
|
||||
*b++ = '-';
|
||||
b = stpcpy(b, NanName[nik%3]);
|
||||
b = stpcpy(b, __gdtoa_NanName[nik%3]);
|
||||
if (nik > 5 && (nik < 12
|
||||
|| L[3] != __gdtoa_NanDflt_ldus[3]
|
||||
|| L[2] != __gdtoa_NanDflt_ldus[2]
|
||||
|| L[1] != __gdtoa_NanDflt_ldus[1]
|
||||
|| L[0] != __gdtoa_NanDflt_ldus[0])) {
|
||||
bits[1] &= 0x7fffffff;
|
||||
b = add_nanbits(b, bufsize - (b-buf), bits, 2);
|
||||
b = __gdtoa_add_nanbits(b, bufsize - (b-buf), bits, 2);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
|
@ -100,5 +100,5 @@ g_xfmt_p(char *buf, void *V, int ndig, size_t bufsize, int nik)
|
|||
mode = 0;
|
||||
}
|
||||
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
|
||||
return g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
|
||||
}
|
||||
|
|
132
third_party/gdtoa/gdtoa.c
vendored
132
third_party/gdtoa/gdtoa.c
vendored
|
@ -44,7 +44,7 @@ bitstob(ULong *bits, int nbits, int *bbits)
|
|||
i <<= 1;
|
||||
k++;
|
||||
}
|
||||
b = Balloc(k);
|
||||
b = __gdtoa_Balloc(k);
|
||||
be = bits + ((nbits - 1) >> kshift);
|
||||
x = x0 = b->x;
|
||||
do {
|
||||
|
@ -71,12 +71,12 @@ ret:
|
|||
* Modifications:
|
||||
* 1. Rather than iterating, we use a simple numeric overestimate
|
||||
* to determine k = floor(log10(d)). We scale relevant
|
||||
* quantities using O(log2(k)) rather than O(k) multiplications.
|
||||
* quantities using O(log2(k)) rather than O(k) __gdtoa_multiplications.
|
||||
* 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
|
||||
* try to generate digits strictly left to right. Instead, we
|
||||
* compute with fewer bits and propagate the carry if necessary
|
||||
* when rounding the final digit up. This is often faster.
|
||||
* 3. Under the assumption that input will be rounded nearest,
|
||||
* 3. Under the as__gdtoa_sumption that input will be rounded nearest,
|
||||
* mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
|
||||
* That is, we allow equality in stopping tests when the
|
||||
* round-nearest rule will give the same floating-point value
|
||||
|
@ -86,10 +86,10 @@ ret:
|
|||
* quantities.
|
||||
* 5. When converting floating-point integers less than 1e16,
|
||||
* we use floating-point arithmetic rather than resorting
|
||||
* to multiple-precision integers.
|
||||
* to __gdtoa_multiple-precision integers.
|
||||
* 6. When asked to produce fewer than 15 digits, we first try
|
||||
* to get by with floating-point arithmetic; we resort to
|
||||
* multiple-precision integer arithmetic only if we cannot
|
||||
* __gdtoa_multiple-precision integer arithmetic only if we cannot
|
||||
* guarantee that the floating-point calculation has given
|
||||
* the correctly rounded result. For k requested digits and
|
||||
* "uniformly" distributed input, the probability is
|
||||
|
@ -125,7 +125,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
2 + (mode & 1). These modes are mainly for
|
||||
debugging; often they run slower but sometimes
|
||||
faster than modes 2-3.
|
||||
4,5,8,9 ==> left-to-right digit generation.
|
||||
4,5,8,9 ==> left-to-right digit gene__gdtoa_ration.
|
||||
6-9 ==> don't try fast floating-point estimate
|
||||
(if applicable).
|
||||
|
||||
|
@ -153,27 +153,27 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
break;
|
||||
case STRTOG_Infinite:
|
||||
*decpt = -32768;
|
||||
return nrv_alloc("Infinity", rve, 8);
|
||||
return __gdtoa_nrv_alloc("Infinity", rve, 8);
|
||||
case STRTOG_NaN:
|
||||
*decpt = -32768;
|
||||
return nrv_alloc("NaN", rve, 3);
|
||||
return __gdtoa_nrv_alloc("NaN", rve, 3);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
b = bitstob(bits, nbits = fpi->nbits, &bbits);
|
||||
be0 = be;
|
||||
if ( (i = trailz(b)) !=0) {
|
||||
rshift(b, i);
|
||||
if ( (i = __gdtoa_trailz(b)) !=0) {
|
||||
__gdtoa_rshift(b, i);
|
||||
be += i;
|
||||
bbits -= i;
|
||||
}
|
||||
if (!b->wds) {
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
ret_zero:
|
||||
*decpt = 1;
|
||||
return nrv_alloc("0", rve, 1);
|
||||
return __gdtoa_nrv_alloc("0", rve, 1);
|
||||
}
|
||||
dval(&d) = b2d(b, &i);
|
||||
dval(&d) = __gdtoa_b2d(b, &i);
|
||||
i = be + bbits - 1;
|
||||
word0(&d) &= Frac_mask1;
|
||||
word0(&d) |= Exp_11;
|
||||
|
@ -190,7 +190,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
* We want k to be too large rather than too small.
|
||||
* The error in the first-order Taylor series approximation
|
||||
* is in our favor, so we just round up the constant enough
|
||||
* to compensate for any error in the multiplication of
|
||||
* to compensate for any error in the __gdtoa_multiplication of
|
||||
* (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
|
||||
* and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
|
||||
* adding 1e-13 to the constant term more than suffices.
|
||||
|
@ -199,7 +199,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
* but this is probably not worthwhile.)
|
||||
*/
|
||||
ds = (dval(&d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
|
||||
/* correct assumption about exponent range */
|
||||
/* correct as__gdtoa_sumption about exponent range */
|
||||
if ((j = i) < 0)
|
||||
j = -j;
|
||||
if ((j -= 1077) > 0)
|
||||
|
@ -226,7 +226,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
// 401173: _start at libc/crt/crt.S:67
|
||||
word0(&d) += (unsigned)(be + bbits - 1) << Exp_shift;
|
||||
if (k >= 0 && k <= Ten_pmax) {
|
||||
if (dval(&d) < tens[k])
|
||||
if (dval(&d) < __gdtoa_tens[k])
|
||||
k--;
|
||||
k_check = 0;
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
if (i <= 0)
|
||||
i = 1;
|
||||
}
|
||||
s = s0 = rv_alloc(i);
|
||||
s = s0 = __gdtoa_rv_alloc(i);
|
||||
if (mode <= 1)
|
||||
rdir = 0;
|
||||
else if ( (rdir = fpi->rounding - 1) !=0) {
|
||||
|
@ -303,28 +303,28 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
ilim0 = ilim;
|
||||
ieps = 2; /* conservative */
|
||||
if (k > 0) {
|
||||
ds = tens[k&0xf];
|
||||
ds = __gdtoa_tens[k&0xf];
|
||||
j = k >> 4;
|
||||
if (j & Bletch) {
|
||||
/* prevent overflows */
|
||||
j &= Bletch - 1;
|
||||
dval(&d) /= bigtens[n_bigtens-1];
|
||||
dval(&d) /= __gdtoa_bigtens[n___gdtoa_bigtens-1];
|
||||
ieps++;
|
||||
}
|
||||
for(; j; j >>= 1, i++)
|
||||
if (j & 1) {
|
||||
ieps++;
|
||||
ds *= bigtens[i];
|
||||
ds *= __gdtoa_bigtens[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
ds = 1.;
|
||||
if ( (j1 = -k) !=0) {
|
||||
dval(&d) *= tens[j1 & 0xf];
|
||||
dval(&d) *= __gdtoa_tens[j1 & 0xf];
|
||||
for(j = j1 >> 4; j; j >>= 1, i++)
|
||||
if (j & 1) {
|
||||
ieps++;
|
||||
dval(&d) *= bigtens[i];
|
||||
dval(&d) *= __gdtoa_bigtens[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
/* Use Steele & White method of only
|
||||
* generating digits needed.
|
||||
*/
|
||||
dval(&eps) = ds*0.5/tens[ilim-1] - dval(&eps);
|
||||
dval(&eps) = ds*0.5/__gdtoa_tens[ilim-1] - dval(&eps);
|
||||
for(i = 0;;) {
|
||||
L = (Long)(dval(&d)/ds);
|
||||
dval(&d) -= L*ds;
|
||||
|
@ -371,7 +371,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
}
|
||||
else {
|
||||
/* Generate ilim digits, then fix them up. */
|
||||
dval(&eps) *= tens[ilim-1];
|
||||
dval(&eps) *= __gdtoa_tens[ilim-1];
|
||||
for(i = 1;; i++, dval(&d) *= 10.) {
|
||||
if ( (L = (Long)(dval(&d)/ds)) !=0)
|
||||
dval(&d) -= L*ds;
|
||||
|
@ -398,7 +398,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
/* Do we have a "small" integer? */
|
||||
if (be >= 0 && k <= fpi->int_max) {
|
||||
/* Yes. */
|
||||
ds = tens[k];
|
||||
ds = __gdtoa_tens[k];
|
||||
if (ndigits < 0 && ilim <= 0) {
|
||||
S = mhi = 0;
|
||||
if (ilim < 0 || dval(&d) <= 5*ds)
|
||||
|
@ -471,7 +471,7 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
}
|
||||
b2 += i;
|
||||
s2 += i;
|
||||
mhi = i2b(1);
|
||||
mhi = __gdtoa_i2b(1);
|
||||
}
|
||||
if (m2 > 0 && s2 > 0) {
|
||||
i = m2 < s2 ? m2 : s2;
|
||||
|
@ -482,20 +482,20 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
if (b5 > 0) {
|
||||
if (leftright) {
|
||||
if (m5 > 0) {
|
||||
mhi = pow5mult(mhi, m5);
|
||||
b1 = mult(mhi, b);
|
||||
Bfree(b);
|
||||
mhi = __gdtoa_pow5mult(mhi, m5);
|
||||
b1 = __gdtoa_mult(mhi, b);
|
||||
__gdtoa_Bfree(b);
|
||||
b = b1;
|
||||
}
|
||||
if ( (j = b5 - m5) !=0)
|
||||
b = pow5mult(b, j);
|
||||
b = __gdtoa_pow5mult(b, j);
|
||||
}
|
||||
else
|
||||
b = pow5mult(b, b5);
|
||||
b = __gdtoa_pow5mult(b, b5);
|
||||
}
|
||||
S = i2b(1);
|
||||
S = __gdtoa_i2b(1);
|
||||
if (s5 > 0)
|
||||
S = pow5mult(S, s5);
|
||||
S = __gdtoa_pow5mult(S, s5);
|
||||
/* Check for special case that d is a normalized power of 2. */
|
||||
spec_case = 0;
|
||||
if (mode < 2) {
|
||||
|
@ -510,26 +510,26 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
* shift left if necessary so divisor has 4 leading 0 bits.
|
||||
*
|
||||
* Perhaps we should just compute leading 28 bits of S once
|
||||
* and for all and pass them and a shift to quorem, so it
|
||||
* and for all and pass them and a shift to __gdtoa_quorem, so it
|
||||
* can do shifts and ors to compute the numerator for q.
|
||||
*/
|
||||
i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask;
|
||||
m2 += i;
|
||||
if ((b2 += i) > 0)
|
||||
b = lshift(b, b2);
|
||||
b = __gdtoa_lshift(b, b2);
|
||||
if ((s2 += i) > 0)
|
||||
S = lshift(S, s2);
|
||||
S = __gdtoa_lshift(S, s2);
|
||||
if (k_check) {
|
||||
if (cmp(b,S) < 0) {
|
||||
if (__gdtoa_cmp(b,S) < 0) {
|
||||
k--;
|
||||
b = multadd(b, 10, 0); /* we botched the k estimate */
|
||||
b = __gdtoa_multadd(b, 10, 0); /* we botched the k estimate */
|
||||
if (leftright)
|
||||
mhi = multadd(mhi, 10, 0);
|
||||
mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
ilim = ilim1;
|
||||
}
|
||||
}
|
||||
if (ilim <= 0 && mode > 2) {
|
||||
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
|
||||
if (ilim < 0 || __gdtoa_cmp(b,S = __gdtoa_multadd(S,5,0)) <= 0) {
|
||||
/* no digits, fcvt style */
|
||||
no_digits:
|
||||
k = -1 - ndigits;
|
||||
|
@ -544,25 +544,25 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
}
|
||||
if (leftright) {
|
||||
if (m2 > 0)
|
||||
mhi = lshift(mhi, m2);
|
||||
mhi = __gdtoa_lshift(mhi, m2);
|
||||
/* Compute mlo -- check for special case
|
||||
* that d is a normalized power of 2.
|
||||
*/
|
||||
mlo = mhi;
|
||||
if (spec_case) {
|
||||
mhi = Balloc(mhi->k);
|
||||
mhi = __gdtoa_Balloc(mhi->k);
|
||||
Bcopy(mhi, mlo);
|
||||
mhi = lshift(mhi, 1);
|
||||
mhi = __gdtoa_lshift(mhi, 1);
|
||||
}
|
||||
for(i = 1;;i++) {
|
||||
dig = quorem(b,S) + '0';
|
||||
dig = __gdtoa_quorem(b,S) + '0';
|
||||
/* Do we yet have the shortest decimal string
|
||||
* that will round to d?
|
||||
*/
|
||||
j = cmp(b, mlo);
|
||||
delta = diff(S, mhi);
|
||||
j1 = delta->sign ? 1 : cmp(b, delta);
|
||||
Bfree(delta);
|
||||
j = __gdtoa_cmp(b, mlo);
|
||||
delta = __gdtoa_diff(S, mhi);
|
||||
j1 = delta->sign ? 1 : __gdtoa_cmp(b, delta);
|
||||
__gdtoa_Bfree(delta);
|
||||
if (j1 == 0 && !mode && !(bits[0] & 1) && !rdir) {
|
||||
if (dig == '9')
|
||||
goto round_9_up;
|
||||
|
@ -583,14 +583,14 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
inex = STRTOG_Inexlo;
|
||||
goto accept;
|
||||
}
|
||||
while (cmp(S,mhi) > 0) {
|
||||
while (__gdtoa_cmp(S,mhi) > 0) {
|
||||
*s++ = dig;
|
||||
mhi1 = multadd(mhi, 10, 0);
|
||||
mhi1 = __gdtoa_multadd(mhi, 10, 0);
|
||||
if (mlo == mhi)
|
||||
mlo = mhi1;
|
||||
mhi = mhi1;
|
||||
b = multadd(b, 10, 0);
|
||||
dig = quorem(b,S) + '0';
|
||||
b = __gdtoa_multadd(b, 10, 0);
|
||||
dig = __gdtoa_quorem(b,S) + '0';
|
||||
}
|
||||
if (dig++ == '9')
|
||||
goto round_9_up;
|
||||
|
@ -598,8 +598,8 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
goto accept;
|
||||
}
|
||||
if (j1 > 0) {
|
||||
b = lshift(b, 1);
|
||||
j1 = cmp(b, S);
|
||||
b = __gdtoa_lshift(b, 1);
|
||||
j1 = __gdtoa_cmp(b, S);
|
||||
if ((j1 > 0 || (j1 == 0 && dig & 1)) && dig++ == '9')
|
||||
goto round_9_up;
|
||||
inex = STRTOG_Inexhi;
|
||||
|
@ -624,21 +624,21 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
*s++ = dig;
|
||||
if (i == ilim)
|
||||
break;
|
||||
b = multadd(b, 10, 0);
|
||||
b = __gdtoa_multadd(b, 10, 0);
|
||||
if (mlo == mhi)
|
||||
mlo = mhi = multadd(mhi, 10, 0);
|
||||
mlo = mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
else {
|
||||
mlo = multadd(mlo, 10, 0);
|
||||
mhi = multadd(mhi, 10, 0);
|
||||
mlo = __gdtoa_multadd(mlo, 10, 0);
|
||||
mhi = __gdtoa_multadd(mhi, 10, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
for(i = 1;; i++) {
|
||||
*s++ = dig = quorem(b,S) + '0';
|
||||
*s++ = dig = __gdtoa_quorem(b,S) + '0';
|
||||
if (i >= ilim)
|
||||
break;
|
||||
b = multadd(b, 10, 0);
|
||||
b = __gdtoa_multadd(b, 10, 0);
|
||||
}
|
||||
/* Round off last digit */
|
||||
if (rdir) {
|
||||
|
@ -646,8 +646,8 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
goto chopzeros;
|
||||
goto roundoff;
|
||||
}
|
||||
b = lshift(b, 1);
|
||||
j = cmp(b, S);
|
||||
b = __gdtoa_lshift(b, 1);
|
||||
j = __gdtoa_cmp(b, S);
|
||||
if (j > 0 || (j == 0 && dig & 1))
|
||||
{
|
||||
roundoff:
|
||||
|
@ -666,16 +666,16 @@ gdtoa(const FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, in
|
|||
inex = STRTOG_Inexlo;
|
||||
}
|
||||
ret:
|
||||
Bfree(S);
|
||||
__gdtoa_Bfree(S);
|
||||
if (mhi) {
|
||||
if (mlo && mlo != mhi)
|
||||
Bfree(mlo);
|
||||
Bfree(mhi);
|
||||
__gdtoa_Bfree(mlo);
|
||||
__gdtoa_Bfree(mhi);
|
||||
}
|
||||
ret1:
|
||||
while(s > s0 && s[-1] == '0')
|
||||
--s;
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
*s = 0;
|
||||
*decpt = k + 1;
|
||||
if (rve)
|
||||
|
|
180
third_party/gdtoa/gdtoa.internal.h
vendored
180
third_party/gdtoa/gdtoa.internal.h
vendored
|
@ -169,9 +169,6 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* floating-point constants.
|
||||
* #define -DNO_ERRNO to suppress setting errno (in strtod.c and
|
||||
* strtodg.c).
|
||||
* #define NO_STRING_H to use private versions of memcpy.
|
||||
* On some K&R systems, it may also be necessary to
|
||||
* #define DECLARE_SIZE_T in this case.
|
||||
* #define USE_LOCALE to use the current locale's decimal_point value.
|
||||
*/
|
||||
|
||||
|
@ -197,24 +194,6 @@ typedef unsigned short UShort;
|
|||
}
|
||||
#endif
|
||||
|
||||
/* #ifdef KR_headers */
|
||||
/* #define Char char */
|
||||
/* #else */
|
||||
#define Char void
|
||||
/* #endif */
|
||||
|
||||
#ifdef MALLOC
|
||||
extern Char *MALLOC(size_t);
|
||||
#else
|
||||
#define MALLOC malloc
|
||||
#endif
|
||||
|
||||
#ifdef REALLOC
|
||||
extern Char *REALLOC(Char *, size_t);
|
||||
#else
|
||||
#define REALLOC realloc
|
||||
#endif
|
||||
|
||||
#undef IEEE_Arith
|
||||
#undef Avoid_Underflow
|
||||
#ifdef IEEE_MC68k
|
||||
|
@ -230,16 +209,8 @@ extern Char *REALLOC(Char *, size_t);
|
|||
#endif /* Bad_float_h */
|
||||
|
||||
#ifdef IEEE_Arith
|
||||
#define Scale_Bit 0x10
|
||||
#define n_bigtens 5
|
||||
#endif
|
||||
|
||||
#ifdef IBM
|
||||
#define n_bigtens 3
|
||||
#endif
|
||||
|
||||
#ifdef VAX
|
||||
#define n_bigtens 2
|
||||
#define Scale_Bit 0x10
|
||||
#define n___gdtoa_bigtens 5
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
|
@ -334,7 +305,7 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
|
|||
#define Pack_16
|
||||
/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
|
||||
* This makes some inner loops simpler and sometimes saves work
|
||||
* during multiplications, but it often seems to make things slightly
|
||||
* during __gdtoa_multiplications, but it often seems to make things slightly
|
||||
* slower. Hence the default is now to store 32 bits per Long.
|
||||
*/
|
||||
#endif
|
||||
|
@ -374,111 +345,56 @@ typedef struct ThInfo {
|
|||
Bigint *P5s;
|
||||
} ThInfo;
|
||||
|
||||
#ifdef NO_STRING_H
|
||||
#ifdef DECLARE_SIZE_T
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
extern void __gdtoa_memcpy(void *, const void *, size_t);
|
||||
#define Bcopy(x, y) \
|
||||
__gdtoa_memcpy(&x->sign, &y->sign, y->wds * sizeof(ULong) + 2 * sizeof(int))
|
||||
#else /* !NO_STRING_H */
|
||||
#define Bcopy(x, y) \
|
||||
memcpy(&x->sign, &y->sign, y->wds * sizeof(ULong) + 2 * sizeof(int))
|
||||
#endif /* NO_STRING_H */
|
||||
|
||||
#define Balloc __gdtoa_Balloc
|
||||
#define Bfree __gdtoa_Bfree
|
||||
#define InfName __gdtoa_InfName
|
||||
#define NanName __gdtoa_NanName
|
||||
#define ULtoQ __gdtoa_ULtoQ
|
||||
#define ULtof __gdtoa_ULtof
|
||||
#define ULtod __gdtoa_ULtod
|
||||
#define ULtodd __gdtoa_ULtodd
|
||||
#define ULtox __gdtoa_ULtox
|
||||
#define ULtoxL __gdtoa_ULtoxL
|
||||
#define add_nanbits __gdtoa_add_nanbits
|
||||
#define any_on __gdtoa_any_on
|
||||
#define b2d __gdtoa_b2d
|
||||
#define bigtens __gdtoa_bigtens
|
||||
#define cmp __gdtoa_cmp
|
||||
#define copybits __gdtoa_copybits
|
||||
#define d2b __gdtoa_d2b
|
||||
#define decrement __gdtoa_decrement
|
||||
#define diff __gdtoa_diff
|
||||
#define dtoa_result __gdtoa_dtoa_result
|
||||
#define g__fmt __gdtoa_g__fmt
|
||||
#define gethex __gdtoa_gethex
|
||||
#define hexdig __gdtoa_hexdig
|
||||
#define hexnan __gdtoa_hexnan
|
||||
#define i2b __gdtoa_i2b
|
||||
#define increment __gdtoa_increment
|
||||
#define lshift __gdtoa_lshift
|
||||
#define match __gdtoa_match
|
||||
#define mult __gdtoa_mult
|
||||
#define multadd __gdtoa_multadd
|
||||
#define nrv_alloc __gdtoa_nrv_alloc
|
||||
#define pow5mult __gdtoa_pow5mult
|
||||
#define quorem __gdtoa_quorem
|
||||
#define ratio __gdtoa_ratio
|
||||
#define rshift __gdtoa_rshift
|
||||
#define rv_alloc __gdtoa_rv_alloc
|
||||
#define s2b __gdtoa_s2b
|
||||
#define set_ones __gdtoa_set_ones
|
||||
#define strtoIg __gdtoa_strtoIg
|
||||
#define sum __gdtoa_sum
|
||||
#define tens __gdtoa_tens
|
||||
#define tinytens __gdtoa_tinytens
|
||||
#define tinytens __gdtoa_tinytens
|
||||
#define trailz __gdtoa_trailz
|
||||
#define ulp __gdtoa_ulp
|
||||
hidden extern char *__gdtoa_dtoa_result;
|
||||
hidden extern const double __gdtoa_bigtens[];
|
||||
hidden extern const double __gdtoa_tens[];
|
||||
hidden extern const double __gdtoa_tinytens[];
|
||||
hidden extern const unsigned char __gdtoa_hexdig[];
|
||||
hidden extern const char *const __gdtoa_InfName[6];
|
||||
hidden extern const char *const __gdtoa_NanName[3];
|
||||
|
||||
extern char *add_nanbits(char *, size_t, ULong *, int);
|
||||
|
||||
hidden extern char *dtoa_result;
|
||||
hidden extern const double bigtens[];
|
||||
hidden extern const double tens[];
|
||||
hidden extern const double tinytens[];
|
||||
hidden extern const unsigned char hexdig[];
|
||||
hidden extern const char *const InfName[6];
|
||||
hidden extern const char *const NanName[3];
|
||||
|
||||
Bigint *Balloc(int);
|
||||
void Bfree(Bigint *);
|
||||
void ULtof(ULong *, ULong *, Long, int);
|
||||
void ULtod(ULong *, ULong *, Long, int);
|
||||
void ULtodd(ULong *, ULong *, Long, int);
|
||||
void ULtoQ(ULong *, ULong *, Long, int);
|
||||
void ULtox(UShort *, ULong *, Long, int);
|
||||
void ULtoxL(ULong *, ULong *, Long, int);
|
||||
ULong any_on(Bigint *, int);
|
||||
double b2d(Bigint *, int *);
|
||||
int cmp(Bigint *, Bigint *);
|
||||
void copybits(ULong *, int, Bigint *);
|
||||
Bigint *d2b(double, int *, int *);
|
||||
void decrement(Bigint *);
|
||||
Bigint *diff(Bigint *, Bigint *);
|
||||
char *g__fmt(char *, char *, char *, int, ULong, size_t);
|
||||
int gethex(const char **, const FPI *, Long *, Bigint **, int);
|
||||
Bigint *__gdtoa_Balloc(int);
|
||||
Bigint *__gdtoa_d2b(double, int *, int *);
|
||||
Bigint *__gdtoa_diff(Bigint *, Bigint *);
|
||||
Bigint *__gdtoa_i2b(int);
|
||||
Bigint *__gdtoa_increment(Bigint *);
|
||||
Bigint *__gdtoa_lshift(Bigint *, int);
|
||||
Bigint *__gdtoa_mult(Bigint *, Bigint *);
|
||||
Bigint *__gdtoa_multadd(Bigint *, int, int);
|
||||
Bigint *__gdtoa_s2b(const char *, int, int, ULong, int);
|
||||
Bigint *__gdtoa_set_ones(Bigint *, int);
|
||||
Bigint *__gdtoa_sum(Bigint *, Bigint *);
|
||||
Bigint *__gdtoa_pow5mult(Bigint *, int);
|
||||
ULong __gdtoa_any_on(Bigint *, int);
|
||||
char *__gdtoa_add_nanbits(char *, size_t, ULong *, int);
|
||||
char *__gdtoa_g__fmt(char *, char *, char *, int, ULong, size_t);
|
||||
char *__gdtoa_nrv_alloc(char *, char **, int);
|
||||
char *__gdtoa_rv_alloc(int);
|
||||
double __gdtoa_b2d(Bigint *, int *);
|
||||
double __gdtoa_ratio(Bigint *, Bigint *);
|
||||
double __gdtoa_ulp(U *);
|
||||
int __gdtoa_cmp(Bigint *, Bigint *);
|
||||
int __gdtoa_gethex(const char **, const FPI *, Long *, Bigint **, int);
|
||||
int __gdtoa_hexnan(const char **, const FPI *, ULong *);
|
||||
int __gdtoa_match(const char **, char *);
|
||||
int __gdtoa_quorem(Bigint *, Bigint *);
|
||||
int __gdtoa_strtoIg(const char *, char **, const FPI *, Long *, Bigint **,
|
||||
int *);
|
||||
int __gdtoa_trailz(Bigint *);
|
||||
void __gdtoa_Bfree(Bigint *);
|
||||
void __gdtoa_ULtoQ(ULong *, ULong *, Long, int);
|
||||
void __gdtoa_ULtod(ULong *, ULong *, Long, int);
|
||||
void __gdtoa_ULtodd(ULong *, ULong *, Long, int);
|
||||
void __gdtoa_ULtof(ULong *, ULong *, Long, int);
|
||||
void __gdtoa_ULtox(UShort *, ULong *, Long, int);
|
||||
void __gdtoa_ULtoxL(ULong *, ULong *, Long, int);
|
||||
void __gdtoa_copybits(ULong *, int, Bigint *);
|
||||
void __gdtoa_decrement(Bigint *);
|
||||
void __gdtoa_hexdig_init(void);
|
||||
int hexnan(const char **, const FPI *, ULong *);
|
||||
Bigint *i2b(int);
|
||||
Bigint *increment(Bigint *);
|
||||
Bigint *lshift(Bigint *, int);
|
||||
int match(const char **, char *);
|
||||
Bigint *mult(Bigint *, Bigint *);
|
||||
Bigint *multadd(Bigint *, int, int);
|
||||
char *nrv_alloc(char *, char **, int);
|
||||
Bigint *pow5mult(Bigint *, int);
|
||||
int quorem(Bigint *, Bigint *);
|
||||
double ratio(Bigint *, Bigint *);
|
||||
void rshift(Bigint *, int);
|
||||
char *rv_alloc(int);
|
||||
Bigint *s2b(const char *, int, int, ULong, int);
|
||||
Bigint *set_ones(Bigint *, int);
|
||||
int strtoIg(const char *, char **, const FPI *, Long *, Bigint **, int *);
|
||||
Bigint *sum(Bigint *, Bigint *);
|
||||
int trailz(Bigint *);
|
||||
double ulp(U *);
|
||||
void __gdtoa_rshift(Bigint *, int);
|
||||
|
||||
forceinline int lo0bits(ULong *y) {
|
||||
int k;
|
||||
|
|
49
third_party/gdtoa/gethex.c
vendored
49
third_party/gdtoa/gethex.c
vendored
|
@ -34,14 +34,15 @@
|
|||
/* clang-format off */
|
||||
|
||||
int
|
||||
gethex( const char **sp, const FPI *fpi, Long *exp, Bigint **bp, int sign)
|
||||
__gdtoa_gethex(const char **sp, const FPI *fpi,
|
||||
Long *exp, Bigint **bp, int sign)
|
||||
{
|
||||
Bigint *b;
|
||||
const unsigned char *decpt, *s0, *s, *s1;
|
||||
int big, esign, havedig, irv, j, k, n, n0, nbits, up, zret;
|
||||
ULong L, lostbits, *x;
|
||||
Long e, e1;
|
||||
/**** if (!hexdig['0']) __gdtoa_hexdig_init(); ****/
|
||||
/**** if (!__gdtoa_hexdig['0']) __gdtoa_hexdig_init(); ****/
|
||||
*bp = 0;
|
||||
havedig = 0;
|
||||
s0 = *(const unsigned char **)sp + 2;
|
||||
|
@ -52,27 +53,27 @@ gethex( const char **sp, const FPI *fpi, Long *exp, Bigint **bp, int sign)
|
|||
decpt = 0;
|
||||
zret = 0;
|
||||
e = 0;
|
||||
if (hexdig[*s])
|
||||
if (__gdtoa_hexdig[*s])
|
||||
havedig++;
|
||||
else {
|
||||
zret = 1;
|
||||
if (*s != '.')
|
||||
goto pcheck;
|
||||
decpt = ++s;
|
||||
if (!hexdig[*s])
|
||||
if (!__gdtoa_hexdig[*s])
|
||||
goto pcheck;
|
||||
while(*s == '0')
|
||||
s++;
|
||||
if (hexdig[*s])
|
||||
if (__gdtoa_hexdig[*s])
|
||||
zret = 0;
|
||||
havedig = 1;
|
||||
s0 = s;
|
||||
}
|
||||
while(hexdig[*s])
|
||||
while(__gdtoa_hexdig[*s])
|
||||
s++;
|
||||
if (*s == '.' && !decpt) {
|
||||
decpt = ++s;
|
||||
while(hexdig[*s])
|
||||
while(__gdtoa_hexdig[*s])
|
||||
s++;
|
||||
}/*}*/
|
||||
if (decpt)
|
||||
|
@ -90,12 +91,12 @@ pcheck:
|
|||
case '+':
|
||||
s++;
|
||||
}
|
||||
if ((n = hexdig[*s]) == 0 || n > 0x19) {
|
||||
if ((n = __gdtoa_hexdig[*s]) == 0 || n > 0x19) {
|
||||
s = s1;
|
||||
break;
|
||||
}
|
||||
e1 = n - 0x10;
|
||||
while((n = hexdig[*++s]) !=0 && n <= 0x19) {
|
||||
while((n = __gdtoa_hexdig[*++s]) !=0 && n <= 0x19) {
|
||||
if (e1 & 0xf8000000)
|
||||
big = 1;
|
||||
e1 = 10*e1 + n - 0x10;
|
||||
|
@ -123,7 +124,7 @@ pcheck:
|
|||
}
|
||||
goto retz;
|
||||
ret_tiny:
|
||||
b = Balloc(0);
|
||||
b = __gdtoa_Balloc(0);
|
||||
b->wds = 1;
|
||||
b->x[0] = 1;
|
||||
goto dret;
|
||||
|
@ -145,7 +146,7 @@ pcheck:
|
|||
if (nbits & kmask)
|
||||
++n;
|
||||
for(j = n, k = 0; j >>= 1; ++k);
|
||||
*bp = b = Balloc(k);
|
||||
*bp = b = __gdtoa_Balloc(k);
|
||||
b->wds = n;
|
||||
for(j = 0; j < n0; ++j)
|
||||
b->x[j] = ALL_ON;
|
||||
|
@ -157,7 +158,7 @@ pcheck:
|
|||
n = s1 - s0 - 1;
|
||||
for(k = 0; n > (1 << (kshift-2)) - 1; n >>= 1)
|
||||
k++;
|
||||
b = Balloc(k);
|
||||
b = __gdtoa_Balloc(k);
|
||||
x = b->x;
|
||||
n = 0;
|
||||
L = 0;
|
||||
|
@ -169,7 +170,7 @@ pcheck:
|
|||
L = 0;
|
||||
n = 0;
|
||||
}
|
||||
L |= (hexdig[*s1] & 0x0f) << n;
|
||||
L |= (__gdtoa_hexdig[*s1] & 0x0f) << n;
|
||||
n += 4;
|
||||
}
|
||||
*x++ = L;
|
||||
|
@ -180,27 +181,27 @@ pcheck:
|
|||
x = b->x;
|
||||
if (n > nbits) {
|
||||
n -= nbits;
|
||||
if (any_on(b,n)) {
|
||||
if (__gdtoa_any_on(b,n)) {
|
||||
lostbits = 1;
|
||||
k = n - 1;
|
||||
if (x[k>>kshift] & 1 << (k & kmask)) {
|
||||
lostbits = 2;
|
||||
if (k > 0 && any_on(b,k))
|
||||
if (k > 0 && __gdtoa_any_on(b,k))
|
||||
lostbits = 3;
|
||||
}
|
||||
}
|
||||
rshift(b, n);
|
||||
__gdtoa_rshift(b, n);
|
||||
e += n;
|
||||
}
|
||||
else if (n < nbits) {
|
||||
n = nbits - n;
|
||||
b = lshift(b, n);
|
||||
b = __gdtoa_lshift(b, n);
|
||||
e -= n;
|
||||
x = b->x;
|
||||
}
|
||||
if (e > fpi->emax) {
|
||||
ovfl:
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
ovfl1:
|
||||
errno = ERANGE;
|
||||
switch (fpi->rounding) {
|
||||
|
@ -223,7 +224,7 @@ pcheck:
|
|||
if (n >= nbits) {
|
||||
switch (fpi->rounding) {
|
||||
case FPI_Round_near:
|
||||
if (n == nbits && (n < 2 || lostbits || any_on(b,n-1)))
|
||||
if (n == nbits && (n < 2 || lostbits || __gdtoa_any_on(b,n-1)))
|
||||
goto one_bit;
|
||||
break;
|
||||
case FPI_Round_up:
|
||||
|
@ -242,7 +243,7 @@ pcheck:
|
|||
| STRTOG_Underflow;
|
||||
}
|
||||
}
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
retz:
|
||||
errno = ERANGE;
|
||||
return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;
|
||||
|
@ -251,11 +252,11 @@ pcheck:
|
|||
if (lostbits)
|
||||
lostbits = 1;
|
||||
else if (k > 0)
|
||||
lostbits = any_on(b,k);
|
||||
lostbits = __gdtoa_any_on(b,k);
|
||||
if (x[k>>kshift] & 1 << (k & kmask))
|
||||
lostbits |= 2;
|
||||
nbits -= n;
|
||||
rshift(b,n);
|
||||
__gdtoa_rshift(b,n);
|
||||
e = fpi->emin;
|
||||
}
|
||||
if (lostbits) {
|
||||
|
@ -276,7 +277,7 @@ pcheck:
|
|||
}
|
||||
if (up) {
|
||||
k = b->wds;
|
||||
b = increment(b);
|
||||
b = __gdtoa_increment(b);
|
||||
x = b->x;
|
||||
if (irv == STRTOG_Denormal) {
|
||||
if (nbits == fpi->nbits - 1
|
||||
|
@ -286,7 +287,7 @@ pcheck:
|
|||
else if (b->wds > k
|
||||
|| ((n = nbits & kmask) !=0
|
||||
&& hi0bits(x[k-1]) < 32-n)) {
|
||||
rshift(b,1);
|
||||
__gdtoa_rshift(b,1);
|
||||
if (++e > fpi->emax)
|
||||
goto ovfl;
|
||||
}
|
||||
|
|
4
third_party/gdtoa/gmisc.c
vendored
4
third_party/gdtoa/gmisc.c
vendored
|
@ -33,7 +33,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
void
|
||||
rshift(Bigint *b, int k)
|
||||
__gdtoa_rshift(Bigint *b, int k)
|
||||
{
|
||||
ULong *x, *x1, *xe, y;
|
||||
int n;
|
||||
|
@ -61,7 +61,7 @@ rshift(Bigint *b, int k)
|
|||
}
|
||||
|
||||
int
|
||||
trailz(Bigint *b)
|
||||
__gdtoa_trailz(Bigint *b)
|
||||
{
|
||||
ULong L, *x, *xe;
|
||||
int n = 0;
|
||||
|
|
59
third_party/gdtoa/hd_init.c
vendored
59
third_party/gdtoa/hd_init.c
vendored
|
@ -30,45 +30,22 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/gdtoa/gdtoa.internal.h"
|
||||
/* clang-format off */
|
||||
|
||||
#if 0
|
||||
unsigned char hexdig[256];
|
||||
|
||||
static void
|
||||
htinit(unsigned char *h, unsigned char *s, int inc)
|
||||
{
|
||||
int i, j;
|
||||
for(i = 0; (j = s[i]) !=0; i++)
|
||||
h[j] = i + inc;
|
||||
}
|
||||
|
||||
void
|
||||
__gdtoa_hexdig_init(Void) /* Use of hexdig_init omitted 20121220 to avoid a */
|
||||
/* race condition when multiple threads are used. */
|
||||
{
|
||||
#define USC (unsigned char *)
|
||||
htinit(hexdig, USC "0123456789", 0x10);
|
||||
htinit(hexdig, USC "abcdef", 0x10 + 10);
|
||||
htinit(hexdig, USC "ABCDEF", 0x10 + 10);
|
||||
}
|
||||
#else
|
||||
const unsigned char hexdig[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,
|
||||
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
#endif
|
||||
const unsigned char __gdtoa_hexdig[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, //
|
||||
0, 26, 27, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 26, 27, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
};
|
||||
|
|
6
third_party/gdtoa/hexnan.c
vendored
6
third_party/gdtoa/hexnan.c
vendored
|
@ -46,12 +46,12 @@ L_shift(ULong *x, ULong *x1, int i)
|
|||
}
|
||||
|
||||
int
|
||||
hexnan( const char **sp, const FPI *fpi, ULong *x0)
|
||||
__gdtoa_hexnan( const char **sp, const FPI *fpi, ULong *x0)
|
||||
{
|
||||
ULong c, h, *x, *x1, *xe;
|
||||
const char *s;
|
||||
int havedig, hd0, i, nbits;
|
||||
/**** if (!hexdig['0']) __gdtoa_hexdig_init(); ****/
|
||||
/**** if (!__gdtoa_hexdig['0']) __gdtoa_hexdig_init(); ****/
|
||||
nbits = fpi->nbits;
|
||||
x = x0 + (nbits >> kshift);
|
||||
if (nbits & kmask)
|
||||
|
@ -70,7 +70,7 @@ hexnan( const char **sp, const FPI *fpi, ULong *x0)
|
|||
&& *(const unsigned char*)(s+3) > ' ')
|
||||
s += 2;
|
||||
while((c = *(const unsigned char*)++s)) {
|
||||
if (!(h = hexdig[c])) {
|
||||
if (!(h = __gdtoa_hexdig[c])) {
|
||||
if (c <= ' ') {
|
||||
if (hd0 < havedig) {
|
||||
if (x < x1 && i < 8)
|
||||
|
|
130
third_party/gdtoa/misc.c
vendored
130
third_party/gdtoa/misc.c
vendored
|
@ -29,43 +29,85 @@
|
|||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "third_party/gdtoa/gdtoa.internal.h"
|
||||
/* clang-format off */
|
||||
|
||||
static ThInfo TI0;
|
||||
|
||||
Bigint *
|
||||
Balloc(int k)
|
||||
static void
|
||||
__gdtoa_Brelease(Bigint *rv)
|
||||
{
|
||||
if (!rv) return;
|
||||
__gdtoa_Brelease(rv->next);
|
||||
free(rv);
|
||||
}
|
||||
|
||||
static void
|
||||
Bclear(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ARRAYLEN(TI0.Freelist); ++i)
|
||||
__gdtoa_Brelease(TI0.Freelist[i]);
|
||||
bzero(&TI0.Freelist, sizeof(TI0.Freelist));
|
||||
}
|
||||
|
||||
Bigint *
|
||||
__gdtoa_Balloc(int k)
|
||||
{
|
||||
#if 0
|
||||
int x;
|
||||
Bigint *rv;
|
||||
if (k <= Kmax && (rv = TI0.Freelist[k]) != 0)
|
||||
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;
|
||||
}
|
||||
if (k <= Kmax && (rv = TI0.Freelist[k]) != 0) {
|
||||
TI0.Freelist[k] = rv->next;
|
||||
else {
|
||||
} else {
|
||||
x = 1 << k;
|
||||
rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(ULong));
|
||||
rv->k = k;
|
||||
rv->maxwds = x;
|
||||
}
|
||||
rv->sign = rv->wds = 0;
|
||||
rv->sign = 0;
|
||||
rv->wds = 0;
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Bfree(Bigint *v)
|
||||
__gdtoa_Bfree(Bigint *v)
|
||||
{
|
||||
#if 0
|
||||
free(v);
|
||||
#else
|
||||
if (v) {
|
||||
if (v->k > Kmax)
|
||||
if (v->k > Kmax) {
|
||||
free((void*)v);
|
||||
else {
|
||||
} else {
|
||||
v->next = TI0.Freelist[v->k];
|
||||
TI0.Freelist[v->k] = v;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Bigint *
|
||||
multadd(Bigint *b, int m, int a) /* multiply by m and add a */
|
||||
__gdtoa_multadd(Bigint *b, int m, int a) /* multiply by m and add a */
|
||||
{
|
||||
int i, wds;
|
||||
ULong *x;
|
||||
|
@ -83,9 +125,9 @@ multadd(Bigint *b, int m, int a) /* multiply by m and add a */
|
|||
while(++i < wds);
|
||||
if (carry) {
|
||||
if (wds >= b->maxwds) {
|
||||
b1 = Balloc(b->k+1);
|
||||
b1 = __gdtoa_Balloc(b->k+1);
|
||||
Bcopy(b1, b);
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
b = b1;
|
||||
}
|
||||
b->x[wds++] = carry;
|
||||
|
@ -95,17 +137,17 @@ multadd(Bigint *b, int m, int a) /* multiply by m and add a */
|
|||
}
|
||||
|
||||
Bigint *
|
||||
i2b(int i)
|
||||
__gdtoa_i2b(int i)
|
||||
{
|
||||
Bigint *b;
|
||||
b = Balloc(1);
|
||||
b = __gdtoa_Balloc(1);
|
||||
b->x[0] = i;
|
||||
b->wds = 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
Bigint *
|
||||
mult(Bigint *a, Bigint *b)
|
||||
__gdtoa_mult(Bigint *a, Bigint *b)
|
||||
{
|
||||
Bigint *c;
|
||||
int k, wa, wb, wc;
|
||||
|
@ -123,7 +165,7 @@ mult(Bigint *a, Bigint *b)
|
|||
wc = wa + wb;
|
||||
if (wc > a->maxwds)
|
||||
k++;
|
||||
c = Balloc(k);
|
||||
c = __gdtoa_Balloc(k);
|
||||
for(x = c->x, xa = x + wc; x < xa; x++)
|
||||
*x = 0;
|
||||
xa = a->x;
|
||||
|
@ -150,31 +192,37 @@ mult(Bigint *a, Bigint *b)
|
|||
return c;
|
||||
}
|
||||
|
||||
static void
|
||||
__gdtoa_pow5mult_destroy(void) {
|
||||
__gdtoa_Brelease(TI0.P5s);
|
||||
TI0.P5s = 0;
|
||||
}
|
||||
|
||||
Bigint *
|
||||
pow5mult(Bigint *b, int k)
|
||||
__gdtoa_pow5mult(Bigint *b, int k)
|
||||
{
|
||||
Bigint *b1, *p5, *p51;
|
||||
int i;
|
||||
static const int p05[3] = { 5, 25, 125 };
|
||||
if ( (i = k & 3) !=0)
|
||||
b = multadd(b, p05[i-1], 0);
|
||||
if ((i = k & 3))
|
||||
b = __gdtoa_multadd(b, p05[i-1], 0);
|
||||
if (!(k >>= 2))
|
||||
return b;
|
||||
if ((p5 = TI0.P5s) == 0) {
|
||||
/* first time */
|
||||
p5 = TI0.P5s = i2b(625);
|
||||
if (!(p5 = TI0.P5s)) {
|
||||
p5 = TI0.P5s = __gdtoa_i2b(625);
|
||||
p5->next = 0;
|
||||
atexit(__gdtoa_pow5mult_destroy);
|
||||
}
|
||||
for(;;) {
|
||||
if (k & 1) {
|
||||
b1 = mult(b, p5);
|
||||
Bfree(b);
|
||||
b1 = __gdtoa_mult(b, p5);
|
||||
__gdtoa_Bfree(b);
|
||||
b = b1;
|
||||
}
|
||||
if (!(k >>= 1))
|
||||
break;
|
||||
if ((p51 = p5->next) == 0) {
|
||||
p51 = p5->next = mult(p5,p5);
|
||||
p51 = p5->next = __gdtoa_mult(p5,p5);
|
||||
p51->next = 0;
|
||||
}
|
||||
p5 = p51;
|
||||
|
@ -183,7 +231,7 @@ pow5mult(Bigint *b, int k)
|
|||
}
|
||||
|
||||
Bigint *
|
||||
lshift(Bigint *b, int k)
|
||||
__gdtoa_lshift(Bigint *b, int k)
|
||||
{
|
||||
int i, k1, n, n1;
|
||||
Bigint *b1;
|
||||
|
@ -193,7 +241,7 @@ lshift(Bigint *b, int k)
|
|||
n1 = n + b->wds + 1;
|
||||
for(i = b->maxwds; n1 > i; i <<= 1)
|
||||
k1++;
|
||||
b1 = Balloc(k1);
|
||||
b1 = __gdtoa_Balloc(k1);
|
||||
x1 = b1->x;
|
||||
for(i = 0; i < n; i++)
|
||||
*x1++ = 0;
|
||||
|
@ -214,12 +262,12 @@ lshift(Bigint *b, int k)
|
|||
*x1++ = *x++;
|
||||
while(x < xe);
|
||||
b1->wds = n1 - 1;
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
return b1;
|
||||
}
|
||||
|
||||
int
|
||||
cmp(Bigint *a, Bigint *b)
|
||||
__gdtoa_cmp(Bigint *a, Bigint *b)
|
||||
{
|
||||
ULong *xa, *xa0, *xb, *xb0;
|
||||
int i, j;
|
||||
|
@ -227,9 +275,9 @@ cmp(Bigint *a, Bigint *b)
|
|||
j = b->wds;
|
||||
#ifdef DEBUG
|
||||
if (i > 1 && !a->x[i-1])
|
||||
Bug("cmp called with a->x[a->wds-1] == 0");
|
||||
Bug("__gdtoa_cmp called with a->x[a->wds-1] == 0");
|
||||
if (j > 1 && !b->x[j-1])
|
||||
Bug("cmp called with b->x[b->wds-1] == 0");
|
||||
Bug("__gdtoa_cmp called with b->x[b->wds-1] == 0");
|
||||
#endif
|
||||
if (i -= j)
|
||||
return i;
|
||||
|
@ -247,15 +295,15 @@ cmp(Bigint *a, Bigint *b)
|
|||
}
|
||||
|
||||
Bigint *
|
||||
diff(Bigint *a, Bigint *b)
|
||||
__gdtoa_diff(Bigint *a, Bigint *b)
|
||||
{
|
||||
Bigint *c;
|
||||
int i, wa, wb;
|
||||
ULong *xa, *xae, *xb, *xbe, *xc;
|
||||
ULLong borrow, y;
|
||||
i = cmp(a,b);
|
||||
i = __gdtoa_cmp(a,b);
|
||||
if (!i) {
|
||||
c = Balloc(0);
|
||||
c = __gdtoa_Balloc(0);
|
||||
c->wds = 1;
|
||||
c->x[0] = 0;
|
||||
return c;
|
||||
|
@ -268,7 +316,7 @@ diff(Bigint *a, Bigint *b)
|
|||
}
|
||||
else
|
||||
i = 0;
|
||||
c = Balloc(a->k);
|
||||
c = __gdtoa_Balloc(a->k);
|
||||
c->sign = i;
|
||||
wa = a->wds;
|
||||
xa = a->x;
|
||||
|
@ -296,7 +344,7 @@ diff(Bigint *a, Bigint *b)
|
|||
}
|
||||
|
||||
double
|
||||
b2d(Bigint *a, int *e)
|
||||
__gdtoa_b2d(Bigint *a, int *e)
|
||||
{
|
||||
ULong *xa, *xa0, w, y, z;
|
||||
int k;
|
||||
|
@ -305,7 +353,7 @@ b2d(Bigint *a, int *e)
|
|||
xa = xa0 + a->wds;
|
||||
y = *--xa;
|
||||
#ifdef DEBUG
|
||||
if (!y) Bug("zero y in b2d");
|
||||
if (!y) Bug("zero y in __gdtoa_b2d");
|
||||
#endif
|
||||
k = hi0bits(y);
|
||||
*e = 32 - k;
|
||||
|
@ -330,7 +378,7 @@ ret_d:
|
|||
}
|
||||
|
||||
Bigint *
|
||||
d2b(double dd, int *e, int *bits)
|
||||
__gdtoa_d2b(double dd, int *e, int *bits)
|
||||
{
|
||||
Bigint *b;
|
||||
U d;
|
||||
|
@ -338,7 +386,7 @@ d2b(double dd, int *e, int *bits)
|
|||
int de, k;
|
||||
ULong *x, y, z;
|
||||
d.d = dd;
|
||||
b = Balloc(1);
|
||||
b = __gdtoa_Balloc(1);
|
||||
x = b->x;
|
||||
z = word0(&d) & Frac_mask;
|
||||
word0(&d) &= 0x7fffffff; /* clear sign bit, which we ignore */
|
||||
|
@ -371,13 +419,13 @@ d2b(double dd, int *e, int *bits)
|
|||
}
|
||||
|
||||
const double
|
||||
bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
|
||||
__gdtoa_bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
|
||||
|
||||
const double
|
||||
tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 };
|
||||
__gdtoa_tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 };
|
||||
|
||||
const double
|
||||
tens[] = {
|
||||
__gdtoa_tens[] = {
|
||||
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
||||
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
||||
1e20, 1e21, 1e22
|
||||
|
|
20
third_party/gdtoa/smisc.c
vendored
20
third_party/gdtoa/smisc.c
vendored
|
@ -33,37 +33,37 @@
|
|||
/* clang-format off */
|
||||
|
||||
Bigint *
|
||||
s2b(const char *s, int nd0, int nd, ULong y9, int dplen)
|
||||
__gdtoa_s2b(const char *s, int nd0, int nd, ULong y9, int dplen)
|
||||
{
|
||||
Bigint *b;
|
||||
int i, k;
|
||||
Long x, y;
|
||||
x = (nd + 8) / 9;
|
||||
for(k = 0, y = 1; x > y; y <<= 1, k++) ;
|
||||
b = Balloc(k);
|
||||
b = __gdtoa_Balloc(k);
|
||||
b->x[0] = y9;
|
||||
b->wds = 1;
|
||||
i = 9;
|
||||
if (9 < nd0) {
|
||||
s += 9;
|
||||
do b = multadd(b, 10, *s++ - '0');
|
||||
do b = __gdtoa_multadd(b, 10, *s++ - '0');
|
||||
while(++i < nd0);
|
||||
s += dplen;
|
||||
}
|
||||
else
|
||||
s += dplen + 9;
|
||||
for(; i < nd; i++)
|
||||
b = multadd(b, 10, *s++ - '0');
|
||||
b = __gdtoa_multadd(b, 10, *s++ - '0');
|
||||
return b;
|
||||
}
|
||||
|
||||
double
|
||||
ratio(Bigint *a, Bigint *b)
|
||||
__gdtoa_ratio(Bigint *a, Bigint *b)
|
||||
{
|
||||
U da, db;
|
||||
int k, ka, kb;
|
||||
dval(&da) = b2d(a, &ka);
|
||||
dval(&db) = b2d(b, &kb);
|
||||
dval(&da) = __gdtoa_b2d(a, &ka);
|
||||
dval(&db) = __gdtoa_b2d(b, &kb);
|
||||
k = ka - kb + ULbits*(a->wds - b->wds);
|
||||
if (k > 0)
|
||||
word0(&da) += k*Exp_msk1;
|
||||
|
@ -75,7 +75,7 @@ ratio(Bigint *a, Bigint *b)
|
|||
}
|
||||
|
||||
int
|
||||
match(const char **sp, char *t)
|
||||
__gdtoa_match(const char **sp, char *t)
|
||||
{
|
||||
int c, d;
|
||||
const char *s = *sp;
|
||||
|
@ -90,7 +90,7 @@ match(const char **sp, char *t)
|
|||
}
|
||||
|
||||
void
|
||||
copybits(ULong *c, int n, Bigint *b)
|
||||
__gdtoa_copybits(ULong *c, int n, Bigint *b)
|
||||
{
|
||||
ULong *ce, *x, *xe;
|
||||
ce = c + ((n-1) >> kshift) + 1;
|
||||
|
@ -103,7 +103,7 @@ copybits(ULong *c, int n, Bigint *b)
|
|||
}
|
||||
|
||||
ULong
|
||||
any_on(Bigint *b, int k)
|
||||
__gdtoa_any_on(Bigint *b, int k)
|
||||
{
|
||||
int n, nwds;
|
||||
ULong *x, *x0, x1, x2;
|
||||
|
|
12
third_party/gdtoa/strtoId.c
vendored
12
third_party/gdtoa/strtoId.c
vendored
|
@ -39,14 +39,14 @@ strtoId(const char *s, char **sp, double *f0, double *f1)
|
|||
Long exp[2];
|
||||
Bigint *B[2];
|
||||
int k, rv[2];
|
||||
B[0] = Balloc(1);
|
||||
B[0] = __gdtoa_Balloc(1);
|
||||
B[0]->wds = 2;
|
||||
k = strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
ULtod((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
Bfree(B[0]);
|
||||
k = __gdtoa_strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
__gdtoa_ULtod((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
__gdtoa_Bfree(B[0]);
|
||||
if (B[1]) {
|
||||
ULtod((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
Bfree(B[1]);
|
||||
__gdtoa_ULtod((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
__gdtoa_Bfree(B[1]);
|
||||
}
|
||||
else {
|
||||
((ULong*)f1)[0] = ((ULong*)f0)[0];
|
||||
|
|
12
third_party/gdtoa/strtoIdd.c
vendored
12
third_party/gdtoa/strtoIdd.c
vendored
|
@ -39,14 +39,14 @@ strtoIdd(const char *s, char **sp, double *f0, double *f1)
|
|||
Long exp[2];
|
||||
Bigint *B[2];
|
||||
int k, rv[2];
|
||||
B[0] = Balloc(2);
|
||||
B[0] = __gdtoa_Balloc(2);
|
||||
B[0]->wds = 4;
|
||||
k = strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
ULtodd((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
Bfree(B[0]);
|
||||
k = __gdtoa_strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
__gdtoa_ULtodd((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
__gdtoa_Bfree(B[0]);
|
||||
if (B[1]) {
|
||||
ULtodd((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
Bfree(B[1]);
|
||||
__gdtoa_ULtodd((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
__gdtoa_Bfree(B[1]);
|
||||
}
|
||||
else {
|
||||
((ULong*)f1)[0] = ((ULong*)f0)[0];
|
||||
|
|
12
third_party/gdtoa/strtoIf.c
vendored
12
third_party/gdtoa/strtoIf.c
vendored
|
@ -39,14 +39,14 @@ strtoIf(const char *s, char **sp, float *f0, float *f1)
|
|||
Long exp[2];
|
||||
Bigint *B[2];
|
||||
int k, rv[2];
|
||||
B[0] = Balloc(0);
|
||||
B[0] = __gdtoa_Balloc(0);
|
||||
B[0]->wds = 1;
|
||||
k = strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
ULtof((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
Bfree(B[0]);
|
||||
k = __gdtoa_strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
__gdtoa_ULtof((ULong*)f0, B[0]->x, exp[0], rv[0]);
|
||||
__gdtoa_Bfree(B[0]);
|
||||
if (B[1]) {
|
||||
ULtof((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
Bfree(B[1]);
|
||||
__gdtoa_ULtof((ULong*)f1, B[1]->x, exp[1], rv[1]);
|
||||
__gdtoa_Bfree(B[1]);
|
||||
}
|
||||
else
|
||||
*(ULong*)f1 = *(ULong*)f0;
|
||||
|
|
14
third_party/gdtoa/strtoIg.c
vendored
14
third_party/gdtoa/strtoIg.c
vendored
|
@ -33,7 +33,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
int
|
||||
strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *rvp)
|
||||
__gdtoa_strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *rvp)
|
||||
{
|
||||
Bigint *b, *b1;
|
||||
int i, nb, nw, nw1, rv, rv1, swap;
|
||||
|
@ -47,7 +47,7 @@ strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *
|
|||
}
|
||||
e1 = exp[0];
|
||||
rv1 = rv ^ STRTOG_Inexact;
|
||||
b1 = Balloc(b->k);
|
||||
b1 = __gdtoa_Balloc(b->k);
|
||||
Bcopy(b1, b);
|
||||
nb = fpi->nbits;
|
||||
nb1 = nb & 31;
|
||||
|
@ -56,7 +56,7 @@ strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *
|
|||
nw1 = nw - 1;
|
||||
if (rv & STRTOG_Inexlo) {
|
||||
swap = 0;
|
||||
b1 = increment(b1);
|
||||
b1 = __gdtoa_increment(b1);
|
||||
if ((rv & STRTOG_Retmask) == STRTOG_Zero) {
|
||||
if (fpi->sudden_underflow) {
|
||||
b1->x[0] = 0;
|
||||
|
@ -73,7 +73,7 @@ strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *
|
|||
|| (nb1 && b1->x[nw1] & 1L << nb1)) {
|
||||
if (++e1 > fpi->emax)
|
||||
rv1 = STRTOG_Infinite | STRTOG_Inexhi;
|
||||
rshift(b1, 1);
|
||||
__gdtoa_rshift(b1, 1);
|
||||
}
|
||||
else if ((rv & STRTOG_Retmask) == STRTOG_Denormal) {
|
||||
if (b1->x[nw1] & 1L << nb11) {
|
||||
|
@ -85,12 +85,12 @@ strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *
|
|||
else {
|
||||
swap = STRTOG_Neg;
|
||||
if ((rv & STRTOG_Retmask) == STRTOG_Infinite) {
|
||||
b1 = set_ones(b1, nb);
|
||||
b1 = __gdtoa_set_ones(b1, nb);
|
||||
e1 = fpi->emax;
|
||||
rv1 = STRTOG_Normal | STRTOG_Inexlo | (rv & STRTOG_Neg);
|
||||
goto swapcheck;
|
||||
}
|
||||
decrement(b1);
|
||||
__gdtoa_decrement(b1);
|
||||
if ((rv & STRTOG_Retmask) == STRTOG_Denormal) {
|
||||
for(i = nw1; !b1->x[i]; --i)
|
||||
if (!i) {
|
||||
|
@ -108,7 +108,7 @@ strtoIg(const char *s00, char **se, const FPI *fpi, Long *exp, Bigint **B, int *
|
|||
rv1 |= STRTOG_Underflow;
|
||||
}
|
||||
else {
|
||||
b1 = lshift(b1, 1);
|
||||
b1 = __gdtoa_lshift(b1, 1);
|
||||
b1->x[0] |= 1;
|
||||
--e1;
|
||||
}
|
||||
|
|
12
third_party/gdtoa/strtoIx.c
vendored
12
third_party/gdtoa/strtoIx.c
vendored
|
@ -40,14 +40,14 @@ strtoIx(const char *s, char **sp, void *a, void *b)
|
|||
Bigint *B[2];
|
||||
int k, rv[2];
|
||||
UShort *L = (UShort *)a, *M = (UShort *)b;
|
||||
B[0] = Balloc(1);
|
||||
B[0] = __gdtoa_Balloc(1);
|
||||
B[0]->wds = 2;
|
||||
k = strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
ULtox(L, B[0]->x, exp[0], rv[0]);
|
||||
Bfree(B[0]);
|
||||
k = __gdtoa_strtoIg(s, sp, &fpi, exp, B, rv);
|
||||
__gdtoa_ULtox(L, B[0]->x, exp[0], rv[0]);
|
||||
__gdtoa_Bfree(B[0]);
|
||||
if (B[1]) {
|
||||
ULtox(M, B[1]->x, exp[1], rv[1]);
|
||||
Bfree(B[1]);
|
||||
__gdtoa_ULtox(M, B[1]->x, exp[1], rv[1]);
|
||||
__gdtoa_Bfree(B[1]);
|
||||
}
|
||||
else {
|
||||
M[0] = L[0];
|
||||
|
|
135
third_party/gdtoa/strtod.c
vendored
135
third_party/gdtoa/strtod.c
vendored
|
@ -36,22 +36,21 @@
|
|||
|
||||
#define Avoid_Underflow
|
||||
#define dplen 1
|
||||
#undef tinytens
|
||||
|
||||
/* The factor of 2^106 in tinytens[4] helps us avoid setting the underflow */
|
||||
/* The factor of 2^106 in tiny__gdtoa_tens[4] helps us avoid setting the underflow */
|
||||
/* flag unnecessarily. It leads to a song and dance at the end of strtod. */
|
||||
static const double tinytens[] = {
|
||||
static const double tiny__gdtoa_tens[] = {
|
||||
1e-16, 1e-32, 1e-64, 1e-128,
|
||||
9007199254740992.*9007199254740992.e-256
|
||||
};
|
||||
|
||||
static double
|
||||
sulp(U *x, int scale)
|
||||
s__gdtoa_ulp(U *x, int scale)
|
||||
{
|
||||
U u;
|
||||
int i;
|
||||
double rv;
|
||||
rv = ulp(x);
|
||||
rv = __gdtoa_ulp(x);
|
||||
if (!scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0)
|
||||
return rv; /* Is there an example where i <= 0 ? */
|
||||
word0(&u) = Exp_1 + (i << Exp_shift);
|
||||
|
@ -108,7 +107,7 @@ break2:
|
|||
{
|
||||
FPI fpi1 = fpi;
|
||||
fpi1.rounding = Rounding;
|
||||
switch((i = gethex(&s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
|
||||
switch((i = __gdtoa_gethex(&s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
|
||||
case STRTOG_NoNumber:
|
||||
s = s00;
|
||||
sign = 0;
|
||||
|
@ -116,10 +115,10 @@ break2:
|
|||
break;
|
||||
default:
|
||||
if (bb) {
|
||||
copybits(bits, fpi.nbits, bb);
|
||||
Bfree(bb);
|
||||
__gdtoa_copybits(bits, fpi.nbits, bb);
|
||||
__gdtoa_Bfree(bb);
|
||||
}
|
||||
ULtod(((U*)&rv)->L, bits, exp, i);
|
||||
__gdtoa_ULtod(((U*)&rv)->L, bits, exp, i);
|
||||
}}
|
||||
goto ret;
|
||||
}
|
||||
|
@ -217,9 +216,9 @@ dig_done:
|
|||
switch(c) {
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (match(&s,"nf")) {
|
||||
if (__gdtoa_match(&s,"nf")) {
|
||||
--s;
|
||||
if (!match(&s,"inity"))
|
||||
if (!__gdtoa_match(&s,"inity"))
|
||||
++s;
|
||||
word0(&rv) = 0x7ff00000;
|
||||
word1(&rv) = 0;
|
||||
|
@ -228,9 +227,9 @@ dig_done:
|
|||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
if (match(&s, "an")) {
|
||||
if (__gdtoa_match(&s, "an")) {
|
||||
if (*s == '(' /*)*/
|
||||
&& hexnan(&s, &fpinan, bits)
|
||||
&& __gdtoa_hexnan(&s, &fpinan, bits)
|
||||
== STRTOG_NaNbits) {
|
||||
word0(&rv) = 0x7ff00000 | bits[1];
|
||||
word1(&rv) = bits[0];
|
||||
|
@ -258,7 +257,7 @@ dig_done:
|
|||
k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2;
|
||||
dval(&rv) = y;
|
||||
if (k > 9) {
|
||||
dval(&rv) = tens[k - 9] * dval(&rv) + z;
|
||||
dval(&rv) = __gdtoa_tens[k - 9] * dval(&rv) + z;
|
||||
}
|
||||
bd0 = 0;
|
||||
if (nd <= DBL_DIG) {
|
||||
|
@ -271,7 +270,7 @@ dig_done:
|
|||
rv.d = -rv.d;
|
||||
sign = 0;
|
||||
}
|
||||
/* rv = */ rounded_product(dval(&rv), tens[e]);
|
||||
/* rv = */ rounded_product(dval(&rv), __gdtoa_tens[e]);
|
||||
goto ret;
|
||||
}
|
||||
i = DBL_DIG - nd;
|
||||
|
@ -285,8 +284,8 @@ dig_done:
|
|||
sign = 0;
|
||||
}
|
||||
e -= i;
|
||||
dval(&rv) *= tens[i];
|
||||
/* rv = */ rounded_product(dval(&rv), tens[e]);
|
||||
dval(&rv) *= __gdtoa_tens[i];
|
||||
/* rv = */ rounded_product(dval(&rv), __gdtoa_tens[e]);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
@ -296,7 +295,7 @@ dig_done:
|
|||
rv.d = -rv.d;
|
||||
sign = 0;
|
||||
}
|
||||
/* rv = */ rounded_quotient(dval(&rv), tens[-e]);
|
||||
/* rv = */ rounded_quotient(dval(&rv), __gdtoa_tens[-e]);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +311,7 @@ dig_done:
|
|||
/* Get starting approximation = rv * 10**e1 */
|
||||
if (e1 > 0) {
|
||||
if ( (i = e1 & 15) !=0)
|
||||
dval(&rv) *= tens[i];
|
||||
dval(&rv) *= __gdtoa_tens[i];
|
||||
if (e1 &= ~15) {
|
||||
if (e1 > DBL_MAX_10_EXP) {
|
||||
ovfl:
|
||||
|
@ -329,11 +328,11 @@ dig_done:
|
|||
}
|
||||
range_err:
|
||||
if (bd0) {
|
||||
Bfree(bb);
|
||||
Bfree(bd);
|
||||
Bfree(bs);
|
||||
Bfree(bd0);
|
||||
Bfree(delta);
|
||||
__gdtoa_Bfree(bb);
|
||||
__gdtoa_Bfree(bd);
|
||||
__gdtoa_Bfree(bs);
|
||||
__gdtoa_Bfree(bd0);
|
||||
__gdtoa_Bfree(delta);
|
||||
}
|
||||
errno = ERANGE;
|
||||
goto ret;
|
||||
|
@ -341,10 +340,10 @@ dig_done:
|
|||
e1 >>= 4;
|
||||
for(j = 0; e1 > 1; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
dval(&rv) *= bigtens[j];
|
||||
/* The last multiplication could overflow. */
|
||||
dval(&rv) *= __gdtoa_bigtens[j];
|
||||
/* The last __gdtoa_multiplication could overflow. */
|
||||
word0(&rv) -= P*Exp_msk1;
|
||||
dval(&rv) *= bigtens[j];
|
||||
dval(&rv) *= __gdtoa_bigtens[j];
|
||||
if ((z = word0(&rv) & Exp_mask)
|
||||
> Exp_msk1*(DBL_MAX_EXP+Bias-P))
|
||||
goto ovfl;
|
||||
|
@ -361,15 +360,15 @@ dig_done:
|
|||
else if (e1 < 0) {
|
||||
e1 = -e1;
|
||||
if ( (i = e1 & 15) !=0)
|
||||
dval(&rv) /= tens[i];
|
||||
dval(&rv) /= __gdtoa_tens[i];
|
||||
if (e1 >>= 4) {
|
||||
if (e1 >= 1 << n_bigtens)
|
||||
if (e1 >= 1 << n___gdtoa_bigtens)
|
||||
goto undfl;
|
||||
if (e1 & Scale_Bit)
|
||||
scale = 2*P;
|
||||
for(j = 0; e1 > 0; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
dval(&rv) *= tinytens[j];
|
||||
dval(&rv) *= tiny__gdtoa_tens[j];
|
||||
if (scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask)
|
||||
>> Exp_shift)) > 0) {
|
||||
/* scaled rv is denormal; zap j low bits */
|
||||
|
@ -394,12 +393,12 @@ dig_done:
|
|||
}
|
||||
/* Now the hard part -- adjusting rv to the correct value.*/
|
||||
/* Put digits into bd: true value = bd * 10^e */
|
||||
bd0 = s2b(s0, nd0, nd, y, dplen);
|
||||
bd0 = __gdtoa_s2b(s0, nd0, nd, y, dplen);
|
||||
for(;;) {
|
||||
bd = Balloc(bd0->k);
|
||||
bd = __gdtoa_Balloc(bd0->k);
|
||||
Bcopy(bd, bd0);
|
||||
bb = d2b(dval(&rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
|
||||
bs = i2b(1);
|
||||
bb = __gdtoa_d2b(dval(&rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
|
||||
bs = __gdtoa_i2b(1);
|
||||
if (e >= 0) {
|
||||
bb2 = bb5 = 0;
|
||||
bd2 = bd5 = e;
|
||||
|
@ -440,26 +439,26 @@ dig_done:
|
|||
bs2 -= i;
|
||||
}
|
||||
if (bb5 > 0) {
|
||||
bs = pow5mult(bs, bb5);
|
||||
bb1 = mult(bs, bb);
|
||||
Bfree(bb);
|
||||
bs = __gdtoa_pow5mult(bs, bb5);
|
||||
bb1 = __gdtoa_mult(bs, bb);
|
||||
__gdtoa_Bfree(bb);
|
||||
bb = bb1;
|
||||
}
|
||||
if (bb2 > 0)
|
||||
bb = lshift(bb, bb2);
|
||||
bb = __gdtoa_lshift(bb, bb2);
|
||||
if (bd5 > 0)
|
||||
bd = pow5mult(bd, bd5);
|
||||
bd = __gdtoa_pow5mult(bd, bd5);
|
||||
if (bd2 > 0)
|
||||
bd = lshift(bd, bd2);
|
||||
bd = __gdtoa_lshift(bd, bd2);
|
||||
if (bs2 > 0)
|
||||
bs = lshift(bs, bs2);
|
||||
delta = diff(bb, bd);
|
||||
bs = __gdtoa_lshift(bs, bs2);
|
||||
delta = __gdtoa_diff(bb, bd);
|
||||
dsign = delta->sign;
|
||||
delta->sign = 0;
|
||||
i = cmp(delta, bs);
|
||||
i = __gdtoa_cmp(delta, bs);
|
||||
if (Rounding != 1) {
|
||||
if (i < 0) {
|
||||
/* Error is less than an ulp */
|
||||
/* Error is less than an __gdtoa_ulp */
|
||||
if (!delta->x[0] && delta->wds <= 1) {
|
||||
/* exact */
|
||||
break;
|
||||
|
@ -477,8 +476,8 @@ dig_done:
|
|||
y = word0(&rv) & Exp_mask;
|
||||
if (!scale || y > 2*P*Exp_msk1)
|
||||
{
|
||||
delta = lshift(delta,Log2P);
|
||||
if (cmp(delta, bs) <= 0)
|
||||
delta = __gdtoa_lshift(delta,Log2P);
|
||||
if (__gdtoa_cmp(delta, bs) <= 0)
|
||||
dval(&adj) = -0.5;
|
||||
}
|
||||
}
|
||||
|
@ -486,11 +485,11 @@ dig_done:
|
|||
if (scale && (y = word0(&rv) & Exp_mask)
|
||||
<= 2*P*Exp_msk1)
|
||||
word0(&adj) += (2*P+1)*Exp_msk1 - y;
|
||||
dval(&rv) += adj.d*ulp(&rv);
|
||||
dval(&rv) += adj.d*__gdtoa_ulp(&rv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
dval(&adj) = ratio(delta, bs);
|
||||
dval(&adj) = __gdtoa_ratio(delta, bs);
|
||||
if (adj.d < 1.)
|
||||
dval(&adj) = 1.;
|
||||
if (adj.d <= 0x7ffffffe) {
|
||||
|
@ -504,7 +503,7 @@ dig_done:
|
|||
}
|
||||
if (scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
|
||||
word0(&adj) += (2*P+1)*Exp_msk1 - y;
|
||||
dval(&adj) *= ulp(&rv); /* XXX */
|
||||
dval(&adj) *= __gdtoa_ulp(&rv); /* XXX */
|
||||
if (dsign) {
|
||||
if (word0(&rv) == Big0 && word1(&rv) == Big1)
|
||||
goto ovfl;
|
||||
|
@ -515,7 +514,7 @@ dig_done:
|
|||
goto cont;
|
||||
}
|
||||
if (i < 0) {
|
||||
/* Error is less than half an ulp -- check for
|
||||
/* Error is less than half an __gdtoa_ulp -- check for
|
||||
* special case of mantissa a power of two.
|
||||
*/
|
||||
if (dsign || word1(&rv) || word0(&rv) & Bndry_mask ||
|
||||
|
@ -526,8 +525,8 @@ dig_done:
|
|||
/* exact result */
|
||||
break;
|
||||
}
|
||||
delta = lshift(delta,Log2P);
|
||||
if (cmp(delta, bs) > 0)
|
||||
delta = __gdtoa_lshift(delta,Log2P);
|
||||
if (__gdtoa_cmp(delta, bs) > 0)
|
||||
goto drop_down;
|
||||
break;
|
||||
}
|
||||
|
@ -539,7 +538,7 @@ dig_done:
|
|||
(scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
|
||||
? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
|
||||
0xffffffff)) {
|
||||
/*boundary case -- increment exponent*/
|
||||
/*boundary case -- __gdtoa_increment exponent*/
|
||||
if (word0(&rv) == Big0 && word1(&rv) == Big1)
|
||||
goto ovfl;
|
||||
word0(&rv) = (word0(&rv) & Exp_mask)
|
||||
|
@ -552,7 +551,7 @@ dig_done:
|
|||
}
|
||||
else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {
|
||||
drop_down:
|
||||
/* boundary case -- decrement exponent */
|
||||
/* boundary case -- __gdtoa_decrement exponent */
|
||||
if (scale) {
|
||||
L = word0(&rv) & Exp_mask;
|
||||
if (L <= (2*P+1)*Exp_msk1) {
|
||||
|
@ -576,16 +575,16 @@ dig_done:
|
|||
else if (!(word1(&rv) & Lsb))
|
||||
break;
|
||||
if (dsign)
|
||||
dval(&rv) += sulp(&rv, scale);
|
||||
dval(&rv) += s__gdtoa_ulp(&rv, scale);
|
||||
else {
|
||||
dval(&rv) -= sulp(&rv, scale);
|
||||
dval(&rv) -= s__gdtoa_ulp(&rv, scale);
|
||||
if (!dval(&rv))
|
||||
goto undfl;
|
||||
}
|
||||
dsign = 1 - dsign;
|
||||
break;
|
||||
}
|
||||
if ((aadj = ratio(delta, bs)) <= 2.) {
|
||||
if ((aadj = __gdtoa_ratio(delta, bs)) <= 2.) {
|
||||
if (dsign)
|
||||
aadj = dval(&aadj1) = 1.;
|
||||
else if (word1(&rv) || word0(&rv) & Bndry_mask) {
|
||||
|
@ -621,7 +620,7 @@ dig_done:
|
|||
if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
|
||||
dval(&rv0) = dval(&rv);
|
||||
word0(&rv) -= P*Exp_msk1;
|
||||
dval(&adj) = dval(&aadj1) * ulp(&rv);
|
||||
dval(&adj) = dval(&aadj1) * __gdtoa_ulp(&rv);
|
||||
dval(&rv) += dval(&adj);
|
||||
if ((word0(&rv) & Exp_mask) >=
|
||||
Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
|
||||
|
@ -644,7 +643,7 @@ dig_done:
|
|||
}
|
||||
word0(&aadj1) += (2*P+1)*Exp_msk1 - y;
|
||||
}
|
||||
dval(&adj) = dval(&aadj1) * ulp(&rv);
|
||||
dval(&adj) = dval(&aadj1) * __gdtoa_ulp(&rv);
|
||||
dval(&rv) += dval(&adj);
|
||||
}
|
||||
z = word0(&rv) & Exp_mask;
|
||||
|
@ -662,16 +661,16 @@ dig_done:
|
|||
break;
|
||||
}
|
||||
cont:
|
||||
Bfree(bb);
|
||||
Bfree(bd);
|
||||
Bfree(bs);
|
||||
Bfree(delta);
|
||||
__gdtoa_Bfree(bb);
|
||||
__gdtoa_Bfree(bd);
|
||||
__gdtoa_Bfree(bs);
|
||||
__gdtoa_Bfree(delta);
|
||||
}
|
||||
Bfree(bb);
|
||||
Bfree(bd);
|
||||
Bfree(bs);
|
||||
Bfree(bd0);
|
||||
Bfree(delta);
|
||||
__gdtoa_Bfree(bb);
|
||||
__gdtoa_Bfree(bd);
|
||||
__gdtoa_Bfree(bs);
|
||||
__gdtoa_Bfree(bd0);
|
||||
__gdtoa_Bfree(delta);
|
||||
if (scale) {
|
||||
word0(&rv0) = Exp_1 - 2*P*Exp_msk1;
|
||||
word1(&rv0) = 0;
|
||||
|
|
8
third_party/gdtoa/strtodI.c
vendored
8
third_party/gdtoa/strtodI.c
vendored
|
@ -33,11 +33,11 @@
|
|||
/* clang-format off */
|
||||
|
||||
static double
|
||||
ulpdown(U *d)
|
||||
__gdtoa_ulpdown(U *d)
|
||||
{
|
||||
double u;
|
||||
ULong *L = d->L;
|
||||
u = ulp(d);
|
||||
u = __gdtoa_ulp(d);
|
||||
if (!(L[0] | (L[1] & 0xfffff))
|
||||
&& (L[1] & 0x7ff00000) > 0x00100000)
|
||||
u *= 0.5;
|
||||
|
@ -77,11 +77,11 @@ strtodI(const char *s, char **sp, double *dd)
|
|||
}
|
||||
switch(j) {
|
||||
case STRTOG_Inexlo:
|
||||
dval(&u[1]) = dval(&u[0]) + ulp(&u[0]);
|
||||
dval(&u[1]) = dval(&u[0]) + __gdtoa_ulp(&u[0]);
|
||||
break;
|
||||
case STRTOG_Inexhi:
|
||||
dval(&u[1]) = dval(&u[0]);
|
||||
dval(&u[0]) -= ulpdown(u);
|
||||
dval(&u[0]) -= __gdtoa_ulpdown(u);
|
||||
break;
|
||||
default:
|
||||
dval(&u[1]) = dval(&u[0]);
|
||||
|
|
184
third_party/gdtoa/strtodg.c
vendored
184
third_party/gdtoa/strtodg.c
vendored
|
@ -39,7 +39,7 @@ fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
|
|||
47, 49, 52 };
|
||||
|
||||
Bigint *
|
||||
increment(Bigint *b)
|
||||
__gdtoa_increment(Bigint *b)
|
||||
{
|
||||
ULong *x, *xe;
|
||||
Bigint *b1;
|
||||
|
@ -54,9 +54,9 @@ increment(Bigint *b)
|
|||
} while(x < xe);
|
||||
{
|
||||
if (b->wds >= b->maxwds) {
|
||||
b1 = Balloc(b->k+1);
|
||||
b1 = __gdtoa_Balloc(b->k+1);
|
||||
Bcopy(b1,b);
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
b = b1;
|
||||
}
|
||||
b->x[b->wds++] = 1;
|
||||
|
@ -65,7 +65,7 @@ increment(Bigint *b)
|
|||
}
|
||||
|
||||
void
|
||||
decrement(Bigint *b)
|
||||
__gdtoa_decrement(Bigint *b)
|
||||
{
|
||||
ULong *x, *xe;
|
||||
x = b->x;
|
||||
|
@ -95,14 +95,14 @@ all_on(Bigint *b, int n)
|
|||
}
|
||||
|
||||
Bigint *
|
||||
set_ones(Bigint *b, int n)
|
||||
__gdtoa_set_ones(Bigint *b, int n)
|
||||
{
|
||||
int k;
|
||||
ULong *x, *xe;
|
||||
k = (n + ((1 << kshift) - 1)) >> kshift;
|
||||
if (b->k < k) {
|
||||
Bfree(b);
|
||||
b = Balloc(k);
|
||||
__gdtoa_Bfree(b);
|
||||
b = __gdtoa_Balloc(k);
|
||||
}
|
||||
k = n >> kshift;
|
||||
if (n &= kmask)
|
||||
|
@ -124,7 +124,7 @@ rvOK(U *d, const FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv)
|
|||
ULong carry, inex, lostbits;
|
||||
int bdif, e, j, k, k1, nb, rv;
|
||||
carry = rv = 0;
|
||||
b = d2b(dval(d), &e, &bdif);
|
||||
b = __gdtoa_d2b(dval(d), &e, &bdif);
|
||||
bdif -= nb = fpi->nbits;
|
||||
e += bdif;
|
||||
if (bdif <= 0) {
|
||||
|
@ -161,24 +161,24 @@ rvOK(U *d, const FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv)
|
|||
trunc:
|
||||
inex = lostbits = 0;
|
||||
if (bdif > 0) {
|
||||
if ( (lostbits = any_on(b, bdif)) !=0)
|
||||
if ( (lostbits = __gdtoa_any_on(b, bdif)) !=0)
|
||||
inex = STRTOG_Inexlo;
|
||||
rshift(b, bdif);
|
||||
__gdtoa_rshift(b, bdif);
|
||||
if (carry) {
|
||||
inex = STRTOG_Inexhi;
|
||||
b = increment(b);
|
||||
b = __gdtoa_increment(b);
|
||||
if ( (j = nb & kmask) !=0)
|
||||
j = ULbits - j;
|
||||
if (hi0bits(b->x[b->wds - 1]) != j) {
|
||||
if (!lostbits)
|
||||
lostbits = b->x[0] & 1;
|
||||
rshift(b, 1);
|
||||
__gdtoa_rshift(b, 1);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bdif < 0)
|
||||
b = lshift(b, -bdif);
|
||||
b = __gdtoa_lshift(b, -bdif);
|
||||
if (e < fpi->emin) {
|
||||
k = fpi->emin - e;
|
||||
e = fpi->emin;
|
||||
|
@ -189,15 +189,15 @@ trunc:
|
|||
else {
|
||||
k1 = k - 1;
|
||||
if (k1 > 0 && !lostbits)
|
||||
lostbits = any_on(b, k1);
|
||||
lostbits = __gdtoa_any_on(b, k1);
|
||||
if (!lostbits && !exact)
|
||||
goto ret;
|
||||
lostbits |=
|
||||
carry = b->x[k1>>kshift] & (1 << (k1 & kmask));
|
||||
rshift(b, k);
|
||||
__gdtoa_rshift(b, k);
|
||||
*irv = STRTOG_Denormal;
|
||||
if (carry) {
|
||||
b = increment(b);
|
||||
b = __gdtoa_increment(b);
|
||||
inex = STRTOG_Inexhi | STRTOG_Underflow;
|
||||
}
|
||||
else if (lostbits)
|
||||
|
@ -211,11 +211,11 @@ trunc:
|
|||
b->wds = inex = 0;
|
||||
}
|
||||
*exp = e;
|
||||
copybits(bits, nb, b);
|
||||
__gdtoa_copybits(bits, nb, b);
|
||||
*irv |= inex;
|
||||
rv = 1;
|
||||
ret:
|
||||
Bfree(b);
|
||||
__gdtoa_Bfree(b);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ break2:
|
|||
switch(s[1]) {
|
||||
case 'x':
|
||||
case 'X':
|
||||
irv = gethex(&s, fpi, exp, &rvb, sign);
|
||||
irv = __gdtoa_gethex(&s, fpi, exp, &rvb, sign);
|
||||
if (irv == STRTOG_NoNumber) {
|
||||
s = s00;
|
||||
sign = 0;
|
||||
|
@ -376,9 +376,9 @@ dig_done:
|
|||
switch(c) {
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (match(&s,"nf")) {
|
||||
if (__gdtoa_match(&s,"nf")) {
|
||||
--s;
|
||||
if (!match(&s,"inity"))
|
||||
if (!__gdtoa_match(&s,"inity"))
|
||||
++s;
|
||||
irv = STRTOG_Infinite;
|
||||
goto infnanexp;
|
||||
|
@ -386,11 +386,11 @@ dig_done:
|
|||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
if (match(&s, "an")) {
|
||||
if (__gdtoa_match(&s, "an")) {
|
||||
irv = STRTOG_NaN;
|
||||
*exp = fpi->emax + 1;
|
||||
if (*s == '(')
|
||||
irv = hexnan(&s, fpi, bits);
|
||||
irv = __gdtoa_hexnan(&s, fpi, bits);
|
||||
goto infnanexp;
|
||||
}
|
||||
}
|
||||
|
@ -421,7 +421,7 @@ dig_done:
|
|||
k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2;
|
||||
dval(&rv) = y;
|
||||
if (k > 9)
|
||||
dval(&rv) = tens[k - 9] * dval(&rv) + z;
|
||||
dval(&rv) = __gdtoa_tens[k - 9] * dval(&rv) + z;
|
||||
bd0 = 0;
|
||||
if (nbits <= P && nd <= DBL_DIG) {
|
||||
if (!e) {
|
||||
|
@ -431,7 +431,7 @@ dig_done:
|
|||
else if (e > 0) {
|
||||
if (e <= Ten_pmax) {
|
||||
i = fivesbits[e] + mantbits(&rv) <= P;
|
||||
/* rv = */ rounded_product(dval(&rv), tens[e]);
|
||||
/* rv = */ rounded_product(dval(&rv), __gdtoa_tens[e]);
|
||||
if (rvOK(&rv, fpi, exp, bits, i, rd, &irv))
|
||||
goto ret;
|
||||
e1 -= e;
|
||||
|
@ -444,15 +444,15 @@ dig_done:
|
|||
*/
|
||||
e2 = e - i;
|
||||
e1 -= i;
|
||||
dval(&rv) *= tens[i];
|
||||
/* rv = */ rounded_product(dval(&rv), tens[e2]);
|
||||
dval(&rv) *= __gdtoa_tens[i];
|
||||
/* rv = */ rounded_product(dval(&rv), __gdtoa_tens[e2]);
|
||||
if (rvOK(&rv, fpi, exp, bits, 0, rd, &irv))
|
||||
goto ret;
|
||||
e1 -= e2;
|
||||
}
|
||||
}
|
||||
else if (e >= -Ten_pmax) {
|
||||
/* rv = */ rounded_quotient(dval(&rv), tens[-e]);
|
||||
/* rv = */ rounded_quotient(dval(&rv), __gdtoa_tens[-e]);
|
||||
if (rvOK(&rv, fpi, exp, bits, 0, rd, &irv))
|
||||
goto ret;
|
||||
e1 -= e;
|
||||
|
@ -464,51 +464,51 @@ rv_notOK:
|
|||
e2 = 0;
|
||||
if (e1 > 0) {
|
||||
if ( (i = e1 & 15) !=0)
|
||||
dval(&rv) *= tens[i];
|
||||
dval(&rv) *= __gdtoa_tens[i];
|
||||
if (e1 &= ~15) {
|
||||
e1 >>= 4;
|
||||
while(e1 >= (1 << (n_bigtens-1))) {
|
||||
while(e1 >= (1 << (n___gdtoa_bigtens-1))) {
|
||||
e2 += ((word0(&rv) & Exp_mask)
|
||||
>> Exp_shift1) - Bias;
|
||||
word0(&rv) &= ~Exp_mask;
|
||||
word0(&rv) |= Bias << Exp_shift1;
|
||||
dval(&rv) *= bigtens[n_bigtens-1];
|
||||
e1 -= 1 << (n_bigtens-1);
|
||||
dval(&rv) *= __gdtoa_bigtens[n___gdtoa_bigtens-1];
|
||||
e1 -= 1 << (n___gdtoa_bigtens-1);
|
||||
}
|
||||
e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias;
|
||||
word0(&rv) &= ~Exp_mask;
|
||||
word0(&rv) |= Bias << Exp_shift1;
|
||||
for(j = 0; e1 > 0; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
dval(&rv) *= bigtens[j];
|
||||
dval(&rv) *= __gdtoa_bigtens[j];
|
||||
}
|
||||
}
|
||||
else if (e1 < 0) {
|
||||
e1 = -e1;
|
||||
if ( (i = e1 & 15) !=0)
|
||||
dval(&rv) /= tens[i];
|
||||
dval(&rv) /= __gdtoa_tens[i];
|
||||
if (e1 &= ~15) {
|
||||
e1 >>= 4;
|
||||
while(e1 >= (1 << (n_bigtens-1))) {
|
||||
while(e1 >= (1 << (n___gdtoa_bigtens-1))) {
|
||||
e2 += ((word0(&rv) & Exp_mask)
|
||||
>> Exp_shift1) - Bias;
|
||||
word0(&rv) &= ~Exp_mask;
|
||||
word0(&rv) |= Bias << Exp_shift1;
|
||||
dval(&rv) *= tinytens[n_bigtens-1];
|
||||
e1 -= 1 << (n_bigtens-1);
|
||||
dval(&rv) *= __gdtoa_tinytens[n___gdtoa_bigtens-1];
|
||||
e1 -= 1 << (n___gdtoa_bigtens-1);
|
||||
}
|
||||
e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias;
|
||||
word0(&rv) &= ~Exp_mask;
|
||||
word0(&rv) |= Bias << Exp_shift1;
|
||||
for(j = 0; e1 > 0; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
dval(&rv) *= tinytens[j];
|
||||
dval(&rv) *= __gdtoa_tinytens[j];
|
||||
}
|
||||
}
|
||||
rvb = d2b(dval(&rv), &rve, &rvbits); /* rv = rvb * 2^rve */
|
||||
rvb = __gdtoa_d2b(dval(&rv), &rve, &rvbits); /* rv = rvb * 2^rve */
|
||||
rve += e2;
|
||||
if ((j = rvbits - nbits) > 0) {
|
||||
rshift(rvb, j);
|
||||
__gdtoa_rshift(rvb, j);
|
||||
rvbits = nbits;
|
||||
rve += j;
|
||||
}
|
||||
|
@ -521,7 +521,7 @@ rv_notOK:
|
|||
denorm = 1;
|
||||
j = rve - emin;
|
||||
if (j > 0) {
|
||||
rvb = lshift(rvb, j);
|
||||
rvb = __gdtoa_lshift(rvb, j);
|
||||
rvbits += j;
|
||||
}
|
||||
else if (j < 0) {
|
||||
|
@ -549,7 +549,7 @@ rv_notOK:
|
|||
rvb->x[0] = rvb->wds = rvbits = 1;
|
||||
}
|
||||
else
|
||||
rshift(rvb, -j);
|
||||
__gdtoa_rshift(rvb, -j);
|
||||
}
|
||||
rve = rve1 = emin;
|
||||
if (sudden_underflow && e2 + 1 < emin)
|
||||
|
@ -557,15 +557,15 @@ rv_notOK:
|
|||
}
|
||||
/* Now the hard part -- adjusting rv to the correct value.*/
|
||||
/* Put digits into bd: true value = bd * 10^e */
|
||||
bd0 = s2b(s0, nd0, nd, y, 1);
|
||||
bd0 = __gdtoa_s2b(s0, nd0, nd, y, 1);
|
||||
for(;;) {
|
||||
bd = Balloc(bd0->k);
|
||||
bd = __gdtoa_Balloc(bd0->k);
|
||||
Bcopy(bd, bd0);
|
||||
bb = Balloc(rvb->k);
|
||||
bb = __gdtoa_Balloc(rvb->k);
|
||||
Bcopy(bb, rvb);
|
||||
bbbits = rvbits - bb0;
|
||||
bbe = rve + bb0;
|
||||
bs = i2b(1);
|
||||
bs = __gdtoa_i2b(1);
|
||||
if (e >= 0) {
|
||||
bb2 = bb5 = 0;
|
||||
bd2 = bd5 = e;
|
||||
|
@ -594,31 +594,31 @@ rv_notOK:
|
|||
bs2 -= i;
|
||||
}
|
||||
if (bb5 > 0) {
|
||||
bs = pow5mult(bs, bb5);
|
||||
bb1 = mult(bs, bb);
|
||||
Bfree(bb);
|
||||
bs = __gdtoa_pow5mult(bs, bb5);
|
||||
bb1 = __gdtoa_mult(bs, bb);
|
||||
__gdtoa_Bfree(bb);
|
||||
bb = bb1;
|
||||
}
|
||||
bb2 -= bb0;
|
||||
if (bb2 > 0)
|
||||
bb = lshift(bb, bb2);
|
||||
bb = __gdtoa_lshift(bb, bb2);
|
||||
else if (bb2 < 0)
|
||||
rshift(bb, -bb2);
|
||||
__gdtoa_rshift(bb, -bb2);
|
||||
if (bd5 > 0)
|
||||
bd = pow5mult(bd, bd5);
|
||||
bd = __gdtoa_pow5mult(bd, bd5);
|
||||
if (bd2 > 0)
|
||||
bd = lshift(bd, bd2);
|
||||
bd = __gdtoa_lshift(bd, bd2);
|
||||
if (bs2 > 0)
|
||||
bs = lshift(bs, bs2);
|
||||
bs = __gdtoa_lshift(bs, bs2);
|
||||
asub = 1;
|
||||
inex = STRTOG_Inexhi;
|
||||
delta = diff(bb, bd);
|
||||
delta = __gdtoa_diff(bb, bd);
|
||||
if (delta->wds <= 1 && !delta->x[0])
|
||||
break;
|
||||
dsign = delta->sign;
|
||||
delta->sign = finished = 0;
|
||||
L = 0;
|
||||
i = cmp(delta, bs);
|
||||
i = __gdtoa_cmp(delta, bs);
|
||||
if (rd && i <= 0) {
|
||||
irv = STRTOG_Normal;
|
||||
if ( (finished = dsign ^ (rd&1)) !=0) {
|
||||
|
@ -637,14 +637,14 @@ rv_notOK:
|
|||
if (j > 1 && lo0bits(rvb->x + i) < j - 1)
|
||||
goto adj1;
|
||||
rve = rve1 - 1;
|
||||
rvb = set_ones(rvb, rvbits = nbits);
|
||||
rvb = __gdtoa_set_ones(rvb, rvbits = nbits);
|
||||
break;
|
||||
}
|
||||
irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;
|
||||
break;
|
||||
}
|
||||
if (i < 0) {
|
||||
/* Error is less than half an ulp -- check for
|
||||
/* Error is less than half an __gdtoa_ulp -- check for
|
||||
* special case of mantissa a power of two.
|
||||
*/
|
||||
irv = dsign
|
||||
|
@ -652,8 +652,8 @@ rv_notOK:
|
|||
: STRTOG_Normal | STRTOG_Inexhi;
|
||||
if (dsign || bbbits > 1 || denorm || rve1 == emin)
|
||||
break;
|
||||
delta = lshift(delta,1);
|
||||
if (cmp(delta, bs) > 0) {
|
||||
delta = __gdtoa_lshift(delta,1);
|
||||
if (__gdtoa_cmp(delta, bs) > 0) {
|
||||
irv = STRTOG_Normal | STRTOG_Inexlo;
|
||||
goto drop_down;
|
||||
}
|
||||
|
@ -663,7 +663,7 @@ rv_notOK:
|
|||
/* exactly half-way between */
|
||||
if (dsign) {
|
||||
if (denorm && all_on(rvb, rvbits)) {
|
||||
/*boundary case -- increment exponent*/
|
||||
/*boundary case -- __gdtoa_increment exponent*/
|
||||
rvb->wds = 1;
|
||||
rvb->x[0] = 1;
|
||||
rve = emin + nbits - (rvbits = 1);
|
||||
|
@ -676,7 +676,7 @@ rv_notOK:
|
|||
else if (bbbits == 1) {
|
||||
irv = STRTOG_Normal;
|
||||
drop_down:
|
||||
/* boundary case -- decrement exponent */
|
||||
/* boundary case -- __gdtoa_decrement exponent */
|
||||
if (rve1 == emin) {
|
||||
irv = STRTOG_Normal | STRTOG_Inexhi;
|
||||
if (rvb->wds == 1 && rvb->x[0] == 1)
|
||||
|
@ -684,7 +684,7 @@ rv_notOK:
|
|||
break;
|
||||
}
|
||||
rve -= nbits;
|
||||
rvb = set_ones(rvb, rvbits = nbits);
|
||||
rvb = __gdtoa_set_ones(rvb, rvbits = nbits);
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -692,7 +692,7 @@ rv_notOK:
|
|||
if ((bbbits < nbits && !denorm) || !(rvb->x[0] & 1))
|
||||
break;
|
||||
if (dsign) {
|
||||
rvb = increment(rvb);
|
||||
rvb = __gdtoa_increment(rvb);
|
||||
j = kmask & (ULbits - (rvbits & kmask));
|
||||
if (hi0bits(rvb->x[rvb->wds - 1]) != j)
|
||||
rvbits++;
|
||||
|
@ -701,12 +701,12 @@ rv_notOK:
|
|||
else {
|
||||
if (bbbits == 1)
|
||||
goto undfl;
|
||||
decrement(rvb);
|
||||
__gdtoa_decrement(rvb);
|
||||
irv = STRTOG_Normal | STRTOG_Inexlo;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((dval(&adj) = ratio(delta, bs)) <= 2.) {
|
||||
if ((dval(&adj) = __gdtoa_ratio(delta, bs)) <= 2.) {
|
||||
adj1:
|
||||
inex = STRTOG_Inexlo;
|
||||
if (dsign) {
|
||||
|
@ -756,23 +756,23 @@ rv_notOK:
|
|||
}
|
||||
}
|
||||
y = rve + rvbits;
|
||||
/* adj *= ulp(dval(&rv)); */
|
||||
/* adj *= __gdtoa_ulp(dval(&rv)); */
|
||||
/* if (asub) rv -= adj; else rv += adj; */
|
||||
if (!denorm && rvbits < nbits) {
|
||||
rvb = lshift(rvb, j = nbits - rvbits);
|
||||
rvb = __gdtoa_lshift(rvb, j = nbits - rvbits);
|
||||
rve -= j;
|
||||
rvbits = nbits;
|
||||
}
|
||||
ab = d2b(dval(&adj), &abe, &abits);
|
||||
ab = __gdtoa_d2b(dval(&adj), &abe, &abits);
|
||||
if (abe < 0)
|
||||
rshift(ab, -abe);
|
||||
__gdtoa_rshift(ab, -abe);
|
||||
else if (abe > 0)
|
||||
ab = lshift(ab, abe);
|
||||
ab = __gdtoa_lshift(ab, abe);
|
||||
rvb0 = rvb;
|
||||
if (asub) {
|
||||
/* rv -= adj; */
|
||||
j = hi0bits(rvb->x[rvb->wds-1]);
|
||||
rvb = diff(rvb, ab);
|
||||
rvb = __gdtoa_diff(rvb, ab);
|
||||
k = rvb0->wds - 1;
|
||||
if (denorm)
|
||||
/* do nothing */;
|
||||
|
@ -785,7 +785,7 @@ rv_notOK:
|
|||
denorm = 1;
|
||||
}
|
||||
else {
|
||||
rvb = lshift(rvb, 1);
|
||||
rvb = __gdtoa_lshift(rvb, 1);
|
||||
--rve;
|
||||
--rve1;
|
||||
L = finished = 0;
|
||||
|
@ -793,7 +793,7 @@ rv_notOK:
|
|||
}
|
||||
}
|
||||
else {
|
||||
rvb = sum(rvb, ab);
|
||||
rvb = __gdtoa_sum(rvb, ab);
|
||||
k = rvb->wds - 1;
|
||||
if (k >= rvb0->wds
|
||||
|| hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) {
|
||||
|
@ -802,15 +802,15 @@ rv_notOK:
|
|||
denorm = 0;
|
||||
}
|
||||
else {
|
||||
rshift(rvb, 1);
|
||||
__gdtoa_rshift(rvb, 1);
|
||||
rve++;
|
||||
rve1++;
|
||||
L = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Bfree(ab);
|
||||
Bfree(rvb0);
|
||||
__gdtoa_Bfree(ab);
|
||||
__gdtoa_Bfree(rvb0);
|
||||
if (finished)
|
||||
break;
|
||||
z = rve + rvbits;
|
||||
|
@ -829,28 +829,28 @@ rv_notOK:
|
|||
break;
|
||||
}
|
||||
}
|
||||
bb0 = denorm ? 0 : trailz(rvb);
|
||||
Bfree(bb);
|
||||
Bfree(bd);
|
||||
Bfree(bs);
|
||||
Bfree(delta);
|
||||
bb0 = denorm ? 0 : __gdtoa_trailz(rvb);
|
||||
__gdtoa_Bfree(bb);
|
||||
__gdtoa_Bfree(bd);
|
||||
__gdtoa_Bfree(bs);
|
||||
__gdtoa_Bfree(delta);
|
||||
}
|
||||
if (!denorm && (j = nbits - rvbits)) {
|
||||
if (j > 0)
|
||||
rvb = lshift(rvb, j);
|
||||
rvb = __gdtoa_lshift(rvb, j);
|
||||
else
|
||||
rshift(rvb, -j);
|
||||
__gdtoa_rshift(rvb, -j);
|
||||
rve -= j;
|
||||
}
|
||||
*exp = rve;
|
||||
Bfree(bb);
|
||||
Bfree(bd);
|
||||
Bfree(bs);
|
||||
Bfree(bd0);
|
||||
Bfree(delta);
|
||||
__gdtoa_Bfree(bb);
|
||||
__gdtoa_Bfree(bd);
|
||||
__gdtoa_Bfree(bs);
|
||||
__gdtoa_Bfree(bd0);
|
||||
__gdtoa_Bfree(delta);
|
||||
if (rve > fpi->emax) {
|
||||
huge:
|
||||
Bfree(rvb);
|
||||
__gdtoa_Bfree(rvb);
|
||||
rvb = 0;
|
||||
errno = ERANGE;
|
||||
switch(fpi->rounding & 3) {
|
||||
|
@ -903,8 +903,8 @@ ret:
|
|||
if (sign)
|
||||
irv |= STRTOG_Neg;
|
||||
if (rvb) {
|
||||
copybits(bits, nbits, rvb);
|
||||
Bfree(rvb);
|
||||
__gdtoa_copybits(bits, nbits, rvb);
|
||||
__gdtoa_Bfree(rvb);
|
||||
}
|
||||
return irv;
|
||||
}
|
||||
|
|
2
third_party/gdtoa/strtopd.c
vendored
2
third_party/gdtoa/strtopd.c
vendored
|
@ -41,6 +41,6 @@ strtopd(const char *s, char **sp, double *d)
|
|||
int k;
|
||||
#include "third_party/gdtoa/gdtoa_fltrnds.inc"
|
||||
k = strtodg(s, sp, fpi, &exp, bits);
|
||||
ULtod((ULong*)d, bits, exp, k);
|
||||
__gdtoa_ULtod((ULong*)d, bits, exp, k);
|
||||
return k;
|
||||
}
|
||||
|
|
4
third_party/gdtoa/strtord.c
vendored
4
third_party/gdtoa/strtord.c
vendored
|
@ -35,7 +35,7 @@
|
|||
extern ULong __gdtoa_NanDflt_d[2];
|
||||
|
||||
void
|
||||
ULtod(ULong *L, ULong *bits, Long exp, int k)
|
||||
__gdtoa_ULtod(ULong *L, ULong *bits, Long exp, int k)
|
||||
{
|
||||
switch(k & STRTOG_Retmask) {
|
||||
case STRTOG_NoNumber:
|
||||
|
@ -78,6 +78,6 @@ strtord(const char *s, char **sp, int rounding, double *d)
|
|||
fpi = &fpi1;
|
||||
}
|
||||
k = strtodg(s, sp, fpi, &exp, bits);
|
||||
ULtod((ULong*)d, bits, exp, k);
|
||||
__gdtoa_ULtod((ULong*)d, bits, exp, k);
|
||||
return k;
|
||||
}
|
||||
|
|
4
third_party/gdtoa/strtordd.c
vendored
4
third_party/gdtoa/strtordd.c
vendored
|
@ -35,7 +35,7 @@
|
|||
extern ULong __gdtoa_NanDflt_d[2];
|
||||
|
||||
void
|
||||
ULtodd(ULong *L, ULong *bits, Long exp, int k)
|
||||
__gdtoa_ULtodd(ULong *L, ULong *bits, Long exp, int k)
|
||||
{
|
||||
int i, j;
|
||||
switch(k & STRTOG_Retmask) {
|
||||
|
@ -176,6 +176,6 @@ strtordd(const char *s, char **sp, int rounding, double *dd)
|
|||
fpi = &fpi1;
|
||||
}
|
||||
k = strtodg(s, sp, fpi, &exp, bits);
|
||||
ULtodd((ULong*)dd, bits, exp, k);
|
||||
__gdtoa_ULtodd((ULong*)dd, bits, exp, k);
|
||||
return k;
|
||||
}
|
||||
|
|
4
third_party/gdtoa/strtorf.c
vendored
4
third_party/gdtoa/strtorf.c
vendored
|
@ -35,7 +35,7 @@
|
|||
extern ULong __gdtoa_NanDflt_f[1];
|
||||
|
||||
void
|
||||
ULtof(ULong *L, ULong *bits, Long exp, int k)
|
||||
__gdtoa_ULtof(ULong *L, ULong *bits, Long exp, int k)
|
||||
{
|
||||
switch(k & STRTOG_Retmask) {
|
||||
case STRTOG_NoNumber:
|
||||
|
@ -74,6 +74,6 @@ strtorf(const char *s, char **sp, int rounding, float *f)
|
|||
fpi = &fpi1;
|
||||
}
|
||||
k = strtodg(s, sp, fpi, &exp, bits);
|
||||
ULtof((ULong*)f, bits, exp, k);
|
||||
__gdtoa_ULtof((ULong*)f, bits, exp, k);
|
||||
return k;
|
||||
}
|
||||
|
|
4
third_party/gdtoa/strtorx.c
vendored
4
third_party/gdtoa/strtorx.c
vendored
|
@ -35,7 +35,7 @@
|
|||
extern UShort __gdtoa_NanDflt_ldus[5];
|
||||
|
||||
void
|
||||
ULtox(UShort *L, ULong *bits, Long exp, int k)
|
||||
__gdtoa_ULtox(UShort *L, ULong *bits, Long exp, int k)
|
||||
{
|
||||
switch(k & STRTOG_Retmask) {
|
||||
case STRTOG_NoNumber:
|
||||
|
@ -85,6 +85,6 @@ strtorx(const char *s, char **sp, int rounding, void *L)
|
|||
fpi = &fpi1;
|
||||
}
|
||||
k = strtodg(s, sp, fpi, &exp, bits);
|
||||
ULtox((UShort*)L, bits, exp, k);
|
||||
__gdtoa_ULtox((UShort*)L, bits, exp, k);
|
||||
return k;
|
||||
}
|
||||
|
|
8
third_party/gdtoa/sum.c
vendored
8
third_party/gdtoa/sum.c
vendored
|
@ -33,7 +33,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
Bigint *
|
||||
sum(Bigint *a, Bigint *b)
|
||||
__gdtoa_sum(Bigint *a, Bigint *b)
|
||||
{
|
||||
Bigint *c;
|
||||
ULong carry, *xc, *xa, *xb, *xe, y;
|
||||
|
@ -41,7 +41,7 @@ sum(Bigint *a, Bigint *b)
|
|||
if (a->wds < b->wds) {
|
||||
c = b; b = a; a = c;
|
||||
}
|
||||
c = Balloc(a->k);
|
||||
c = __gdtoa_Balloc(a->k);
|
||||
c->wds = a->wds;
|
||||
carry = 0;
|
||||
xa = a->x;
|
||||
|
@ -66,9 +66,9 @@ sum(Bigint *a, Bigint *b)
|
|||
}
|
||||
if (carry) {
|
||||
if (c->wds == c->maxwds) {
|
||||
b = Balloc(c->k + 1);
|
||||
b = __gdtoa_Balloc(c->k + 1);
|
||||
Bcopy(b, c);
|
||||
Bfree(c);
|
||||
__gdtoa_Bfree(c);
|
||||
c = b;
|
||||
}
|
||||
c->x[c->wds++] = 1;
|
||||
|
|
2
third_party/gdtoa/ulp.c
vendored
2
third_party/gdtoa/ulp.c
vendored
|
@ -33,7 +33,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
double
|
||||
ulp(U *x)
|
||||
__gdtoa_ulp(U *x)
|
||||
{
|
||||
Long L;
|
||||
U a;
|
||||
|
|
63
third_party/infozip/zip/fileio.c
vendored
63
third_party/infozip/zip/fileio.c
vendored
|
@ -1951,69 +1951,6 @@ ZCONST char *to;
|
|||
#endif /* NO_RENAME */
|
||||
|
||||
|
||||
#ifdef ZMEM
|
||||
|
||||
/************************/
|
||||
/* Function memset() */
|
||||
/************************/
|
||||
|
||||
/*
|
||||
* memset - for systems without it
|
||||
* bill davidsen - March 1990
|
||||
*/
|
||||
|
||||
char *
|
||||
memset(buf, init, len)
|
||||
register char *buf; /* buffer loc */
|
||||
register int init; /* initializer */
|
||||
register unsigned int len; /* length of the buffer */
|
||||
{
|
||||
char *start;
|
||||
|
||||
start = buf;
|
||||
while (len--) *(buf++) = init;
|
||||
return(start);
|
||||
}
|
||||
|
||||
|
||||
/************************/
|
||||
/* Function memcpy() */
|
||||
/************************/
|
||||
|
||||
char *
|
||||
memcpy(dst,src,len) /* v2.0f */
|
||||
register char *dst, *src;
|
||||
register unsigned int len;
|
||||
{
|
||||
char *start;
|
||||
|
||||
start = dst;
|
||||
while (len--)
|
||||
*dst++ = *src++;
|
||||
return(start);
|
||||
}
|
||||
|
||||
|
||||
/************************/
|
||||
/* Function memcmp() */
|
||||
/************************/
|
||||
|
||||
int
|
||||
memcmp(b1,b2,len) /* jpd@usl.edu -- 11/16/90 */
|
||||
register char *b1, *b2;
|
||||
register unsigned int len;
|
||||
{
|
||||
|
||||
if (len) do { /* examine each byte (if any) */
|
||||
if (*b1++ != *b2++)
|
||||
return (*((uch *)b1-1) - *((uch *)b2-1)); /* exit when miscompare */
|
||||
} while (--len);
|
||||
|
||||
return(0); /* no miscompares, yield 0 result */
|
||||
}
|
||||
|
||||
#endif /* ZMEM */
|
||||
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
* Split archives
|
||||
|
|
2
third_party/infozip/zip/zip.c
vendored
2
third_party/infozip/zip/zip.c
vendored
|
@ -32,6 +32,8 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/errno.h"
|
||||
#ifdef VMS
|
||||
# include <stsdef.h>
|
||||
|
|
2
third_party/infozip/zip/zipcloak.c
vendored
2
third_party/infozip/zip/zipcloak.c
vendored
|
@ -30,6 +30,8 @@
|
|||
#include "third_party/infozip/zip/ttyio.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#ifndef NO_STDLIB_H
|
||||
# include "libc/mem/mem.h"
|
||||
|
|
6
third_party/infozip/zip/zipnote.c
vendored
6
third_party/infozip/zip/zipnote.c
vendored
|
@ -25,6 +25,8 @@
|
|||
#include "libc/fmt/conv.h"
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
|
||||
/* Calculate size of static line buffer used in write (-w) mode. */
|
||||
|
@ -71,10 +73,6 @@ void zipnoteerr(int c, ZCONST char *h);
|
|||
void zipnotewarn(ZCONST char *a, ZCONST char *b);
|
||||
#endif
|
||||
|
||||
#ifdef QDOS
|
||||
#define exit(p1) QDOSexit()
|
||||
#endif
|
||||
|
||||
int set_filetype(out_path)
|
||||
char *out_path;
|
||||
{
|
||||
|
|
7
third_party/infozip/zip/zipsplit.c
vendored
7
third_party/infozip/zip/zipsplit.c
vendored
|
@ -24,6 +24,8 @@
|
|||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/log/log.h"
|
||||
|
||||
#define DEFSIZ 36000L /* Default split size (change in help() too) */
|
||||
|
@ -39,11 +41,6 @@
|
|||
# define ZPATH_SEP '.'
|
||||
#else
|
||||
#ifdef QDOS
|
||||
# define ZPATH_SEP '_'
|
||||
# define INDEX "zipsplit_idx" /* Name of index file */
|
||||
# define TEMPL_FMT "%%0%dld_zip"
|
||||
# define TEMPL_SIZ 17
|
||||
# define exit(p1) QDOSexit()
|
||||
#else
|
||||
#ifdef VM_CMS
|
||||
# define INDEX "zipsplit.idx" /* Name of index file */
|
||||
|
|
127
third_party/linenoise/linenoise.c
vendored
127
third_party/linenoise/linenoise.c
vendored
|
@ -257,6 +257,7 @@ static struct sigaction orig_cont;
|
|||
static struct sigaction orig_winch;
|
||||
static struct termios orig_termios;
|
||||
static char *history[LINENOISE_MAX_HISTORY];
|
||||
static linenoiseXlatCallback *xlatCallback;
|
||||
static linenoiseHintsCallback *hintsCallback;
|
||||
static linenoiseFreeHintsCallback *freeHintsCallback;
|
||||
static linenoiseCompletionCallback *completionCallback;
|
||||
|
@ -422,12 +423,19 @@ static char HasPendingInput(int fd) {
|
|||
return poll((struct pollfd[]){{fd, POLLIN}}, 1, 0) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns UNICODE CJK Monospace Width of string.
|
||||
*
|
||||
* Control codes and ANSI sequences have a width of zero. We only parse
|
||||
* a limited subset of ANSI here since we don't store ANSI codes in the
|
||||
* linenoiseState::buf, but we do encourage CSI color codes in prompts.
|
||||
*/
|
||||
static size_t GetMonospaceWidth(const char *p, size_t n, char *out_haswides) {
|
||||
int c, d;
|
||||
size_t i, w;
|
||||
struct rune r;
|
||||
char haswides;
|
||||
enum { kAscii, kUtf8, kEsc, kCsi1, kCsi2, kSs, kNf, kStr, kStr2 } t;
|
||||
enum { kAscii, kUtf8, kEsc, kCsi1, kCsi2 } t;
|
||||
for (haswides = r.c = r.n = t = w = i = 0; i < n; ++i) {
|
||||
c = p[i] & 255;
|
||||
switch (t) {
|
||||
|
@ -451,87 +459,26 @@ static size_t GetMonospaceWidth(const char *p, size_t n, char *out_haswides) {
|
|||
r.c <<= 6;
|
||||
r.c |= c & 077;
|
||||
if (!--r.n) {
|
||||
switch (r.c) {
|
||||
case 033:
|
||||
t = kEsc;
|
||||
break;
|
||||
case 0x9b:
|
||||
t = kCsi1;
|
||||
break;
|
||||
case 0x8e:
|
||||
case 0x8f:
|
||||
t = kSs;
|
||||
break;
|
||||
case 0x90:
|
||||
case 0x98:
|
||||
case 0x9d:
|
||||
case 0x9e:
|
||||
case 0x9f:
|
||||
t = kStr;
|
||||
break;
|
||||
default:
|
||||
d = wcwidth(r.c);
|
||||
d = MAX(0, d);
|
||||
w += d;
|
||||
haswides |= d > 1;
|
||||
t = kAscii;
|
||||
break;
|
||||
}
|
||||
d = wcwidth(r.c);
|
||||
d = MAX(0, d);
|
||||
w += d;
|
||||
haswides |= d > 1;
|
||||
t = kAscii;
|
||||
}
|
||||
} else {
|
||||
goto Whoopsie;
|
||||
}
|
||||
break;
|
||||
case kEsc:
|
||||
if (0x20 <= c && c <= 0x2f) {
|
||||
t = kNf;
|
||||
} else if (0x30 <= c && c <= 0x3f) {
|
||||
t = kAscii;
|
||||
} else if (0x20 <= c && c <= 0x5F) {
|
||||
switch (c) {
|
||||
case '[':
|
||||
t = kCsi1;
|
||||
break;
|
||||
case 'N':
|
||||
case 'O':
|
||||
t = kSs;
|
||||
break;
|
||||
case 'P':
|
||||
case 'X':
|
||||
case ']':
|
||||
case '^':
|
||||
case '_':
|
||||
t = kStr;
|
||||
break;
|
||||
case '\\':
|
||||
goto Whoopsie;
|
||||
default:
|
||||
t = kAscii;
|
||||
break;
|
||||
}
|
||||
} else if (0x60 <= c && c <= 0x7e) {
|
||||
t = kAscii;
|
||||
} else if (c == 033) {
|
||||
if (i == 3) t = kAscii;
|
||||
if (c == '[') {
|
||||
t = kCsi1;
|
||||
} else {
|
||||
t = kAscii;
|
||||
}
|
||||
break;
|
||||
case kSs:
|
||||
t = kAscii;
|
||||
break;
|
||||
case kNf:
|
||||
if (0x30 <= c && c <= 0x7e) {
|
||||
t = kAscii;
|
||||
} else if (!(0x20 <= c && c <= 0x2f)) {
|
||||
goto Whoopsie;
|
||||
}
|
||||
break;
|
||||
case kCsi1:
|
||||
if (0x20 <= c && c <= 0x2f) {
|
||||
t = kCsi2;
|
||||
} else if (c == '[' && i == 3) {
|
||||
/* linux function keys */
|
||||
} else if (0x40 <= c && c <= 0x7e) {
|
||||
t = kAscii;
|
||||
} else if (!(0x30 <= c && c <= 0x3f)) {
|
||||
|
@ -545,31 +492,6 @@ static size_t GetMonospaceWidth(const char *p, size_t n, char *out_haswides) {
|
|||
goto Whoopsie;
|
||||
}
|
||||
break;
|
||||
case kStr:
|
||||
switch (c) {
|
||||
case '\a':
|
||||
t = kAscii;
|
||||
break;
|
||||
case 0033:
|
||||
case 0302:
|
||||
t = kStr2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case kStr2:
|
||||
switch (c) {
|
||||
case '\a':
|
||||
case '\\':
|
||||
case 0234:
|
||||
t = kAscii;
|
||||
break;
|
||||
default:
|
||||
t = kStr;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -1745,8 +1667,10 @@ static void linenoiseEditCtrlq(struct linenoiseState *l) {
|
|||
static ssize_t linenoiseEdit(int stdin_fd, int stdout_fd, const char *prompt,
|
||||
char **obuf) {
|
||||
ssize_t rc;
|
||||
uint64_t w;
|
||||
size_t nread;
|
||||
char *p, seq[16];
|
||||
struct rune rune;
|
||||
struct linenoiseState l;
|
||||
bzero(&l, sizeof(l));
|
||||
if (!(l.buf = malloc((l.buflen = 32)))) return -1;
|
||||
|
@ -1914,6 +1838,14 @@ static ssize_t linenoiseEdit(int stdin_fd, int stdout_fd, const char *prompt,
|
|||
break;
|
||||
default:
|
||||
if (!iswcntrl(seq[0])) { /* only sees canonical c0 */
|
||||
if (xlatCallback) {
|
||||
rune = GetUtf8(seq, nread);
|
||||
w = tpenc(xlatCallback(rune.c));
|
||||
nread = 0;
|
||||
do {
|
||||
seq[nread++] = w;
|
||||
} while ((w >>= 8));
|
||||
}
|
||||
linenoiseEditInsert(&l, seq, nread);
|
||||
}
|
||||
break;
|
||||
|
@ -2200,6 +2132,13 @@ void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *fn) {
|
|||
freeHintsCallback = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets character translation callback.
|
||||
*/
|
||||
void linenoiseSetXlatCallback(linenoiseXlatCallback *fn) {
|
||||
xlatCallback = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds completion.
|
||||
*
|
||||
|
|
2
third_party/linenoise/linenoise.h
vendored
2
third_party/linenoise/linenoise.h
vendored
|
@ -12,11 +12,13 @@ typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
|||
typedef char *(linenoiseHintsCallback)(const char *, const char **,
|
||||
const char **);
|
||||
typedef void(linenoiseFreeHintsCallback)(void *);
|
||||
typedef wint_t(linenoiseXlatCallback)(wint_t);
|
||||
|
||||
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||
void linenoiseSetHintsCallback(linenoiseHintsCallback *);
|
||||
void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
|
||||
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||
void linenoiseSetXlatCallback(linenoiseXlatCallback *);
|
||||
|
||||
char *linenoise(const char *) nodiscard;
|
||||
char *linenoiseRaw(const char *, int, int) nodiscard;
|
||||
|
|
3
third_party/lua/lua.main.c
vendored
3
third_party/lua/lua.main.c
vendored
|
@ -12,6 +12,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/lua/lauxlib.h"
|
||||
|
@ -19,6 +20,8 @@
|
|||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/lualib.h"
|
||||
|
||||
STATIC_STACK_SIZE(0x40000);
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#if !defined(LUA_PROGNAME)
|
||||
|
|
2
third_party/mbedtls/net_sockets.c
vendored
2
third_party/mbedtls/net_sockets.c
vendored
|
@ -16,6 +16,7 @@
|
|||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/sockaddr6.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/msg.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/so.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/consts/sol.h"
|
||||
|
|
5
third_party/mbedtls/test/everest_unravaged.c
vendored
5
third_party/mbedtls/test/everest_unravaged.c
vendored
|
@ -33,11 +33,6 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#ifdef memcpy
|
||||
#undef memcpy
|
||||
#endif
|
||||
#define memcpy(x,y,z) __builtin_memcpy(x,y,z)
|
||||
|
||||
#define load64_le(b) READ64LE(b)
|
||||
#define store64_le(b, i) WRITE64LE(b, i)
|
||||
|
||||
|
|
8
third_party/python/Include/ceval.h
vendored
8
third_party/python/Include/ceval.h
vendored
|
@ -2,6 +2,7 @@
|
|||
#define Py_CEVAL_H
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "third_party/python/Include/object.h"
|
||||
#include "third_party/python/Include/pyerrors.h"
|
||||
#include "third_party/python/Include/pystate.h"
|
||||
|
@ -111,15 +112,14 @@ int _Py_CheckRecursiveCall(const char *);
|
|||
#define Py_EnterRecursiveCall(where) \
|
||||
({ \
|
||||
int rc = 0; \
|
||||
const char *rsp, *bot; \
|
||||
intptr_t rsp, bot; \
|
||||
if (!IsTiny()) { \
|
||||
if (IsModeDbg()) { \
|
||||
PyThreadState_GET()->recursion_depth++; \
|
||||
rc = _Py_CheckRecursiveCall(where); \
|
||||
} else { \
|
||||
rsp = __builtin_frame_address(0); \
|
||||
asm(".weak\tape_stack_vaddr\n\t" \
|
||||
"movabs\t$ape_stack_vaddr+32768,%0" : "=r"(bot)); \
|
||||
rsp = (intptr_t)__builtin_frame_address(0); \
|
||||
bot = GetStackAddr(32768); \
|
||||
if (UNLIKELY(rsp < bot)) { \
|
||||
PyErr_Format(PyExc_MemoryError, "Stack overflow%s", where); \
|
||||
rc = -1; \
|
||||
|
|
4
third_party/python/Include/ezprint.h
vendored
4
third_party/python/Include/ezprint.h
vendored
|
@ -18,13 +18,13 @@ static void EzPrint(PyObject *x, const char *s) {
|
|||
t = PyObject_Type(x);
|
||||
r = PyObject_Repr(t);
|
||||
u = PyUnicode_AsUTF8String(r);
|
||||
__printf("%S ", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
__printf("%.*s ", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
Py_DECREF(u);
|
||||
Py_DECREF(r);
|
||||
Py_DECREF(t);
|
||||
r = PyObject_Repr(x);
|
||||
u = PyUnicode_AsUTF8String(r);
|
||||
__printf("%S", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
__printf("%.*s", PyBytes_GET_SIZE(u), PyBytes_AS_STRING(u));
|
||||
Py_DECREF(u);
|
||||
Py_DECREF(r);
|
||||
}
|
||||
|
|
4
third_party/python/Modules/faulthandler.c
vendored
4
third_party/python/Modules/faulthandler.c
vendored
|
@ -11,6 +11,7 @@
|
|||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/ss.h"
|
||||
#include "third_party/python/Include/abstract.h"
|
||||
#include "third_party/python/Include/boolobject.h"
|
||||
#include "third_party/python/Include/ceval.h"
|
||||
|
@ -1118,7 +1119,6 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* TODO(jart): sigaltstack */
|
||||
#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
|
||||
#define FAULTHANDLER_STACK_OVERFLOW
|
||||
static
|
||||
|
@ -1352,7 +1352,6 @@ int _PyFaulthandler_Init(void)
|
|||
{
|
||||
#ifdef HAVE_SIGALTSTACK
|
||||
int err;
|
||||
|
||||
/* Try to allocate an alternate stack for faulthandler() signal handler to
|
||||
* be able to allocate memory on the stack, even on a stack overflow. If it
|
||||
* fails, ignore the error. */
|
||||
|
@ -1378,7 +1377,6 @@ int _PyFaulthandler_Init(void)
|
|||
}
|
||||
PyThread_acquire_lock(thread.cancel_event, 1);
|
||||
#endif
|
||||
|
||||
faulthandler_handlers_init();
|
||||
return faulthandler_env_options();
|
||||
}
|
||||
|
|
2
third_party/python/Objects/obmalloc.c
vendored
2
third_party/python/Objects/obmalloc.c
vendored
|
@ -98,7 +98,7 @@ _PyMem_RawMalloc(void *ctx, size_t size)
|
|||
{
|
||||
#ifdef __COSMOPOLITAN__
|
||||
#ifdef __FSANITIZE_ADDRESS__
|
||||
return __asan_memalign(__BIGGEST_ALIGNMENT__, size);
|
||||
return __asan_memalign(16, size);
|
||||
#else
|
||||
return dlmalloc(size);
|
||||
#endif
|
||||
|
|
1
third_party/python/Python/getsig.c
vendored
1
third_party/python/Python/getsig.c
vendored
|
@ -6,6 +6,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "third_party/python/Include/pydebug.h"
|
||||
#include "third_party/python/Include/pylifecycle.h"
|
||||
#include "third_party/python/pyconfig.h"
|
||||
|
|
5
third_party/python/launch.c
vendored
5
third_party/python/launch.c
vendored
|
@ -6,6 +6,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
@ -93,10 +94,10 @@ ShowCrashReportHook(int err, int fd, int sig,
|
|||
{
|
||||
PyObject *str;
|
||||
PyFrameObject *frame;
|
||||
dprintf(2, "\nCalamity Occurred w/ Python\n");
|
||||
__printf("\nCalamity Occurred w/ Python\n");
|
||||
for (frame = PyEval_GetFrame(); frame; frame = frame->f_back) {
|
||||
str = PyUnicode_AsUTF8String(frame->f_code->co_filename);
|
||||
dprintf(2, "%s:%d\n", PyBytes_AS_STRING(str), frame->f_code->co_firstlineno/* frame->f_lineno */);
|
||||
__printf("%s:%d\n", PyBytes_AS_STRING(str), frame->f_code->co_firstlineno/* frame->f_lineno */);
|
||||
Py_DECREF(str);
|
||||
}
|
||||
}
|
||||
|
|
5
third_party/python/pyconfig.h
vendored
5
third_party/python/pyconfig.h
vendored
|
@ -328,6 +328,8 @@
|
|||
#define HAVE_READV 1
|
||||
#define HAVE_REALPATH 1
|
||||
#define HAVE_RENAMEAT 1
|
||||
#define HAVE_SIGALTSTACK 1
|
||||
|
||||
/* #define HAVE_MREMAP 1 */
|
||||
/* #undef HAVE_PLOCK */
|
||||
/* #undef HAVE_POSIX_FALLOCATE */
|
||||
|
@ -336,7 +338,6 @@
|
|||
/* #undef HAVE_TMPNAM */
|
||||
/* #undef HAVE_TMPNAM_R */
|
||||
/* #undef HAVE_SETPGRP */
|
||||
/* #undef HAVE_SIGALTSTACK */
|
||||
/* #undef HAVE_STATVFS */
|
||||
/* #undef HAVE_STAT_TV_NSEC2 */
|
||||
/* #undef HAVE_SIGPENDING */
|
||||
|
@ -574,7 +575,7 @@
|
|||
#define HAVE_LANGINFO_H 1
|
||||
|
||||
#if IsModeDbg()
|
||||
#define Py_DEBUG 1
|
||||
#define Py_DEBUG 1
|
||||
#endif
|
||||
|
||||
/* #define FAST_LOOPS 1 /\* froot loops *\/ */
|
||||
|
|
2
third_party/python/repl.c
vendored
2
third_party/python/repl.c
vendored
|
@ -43,6 +43,8 @@
|
|||
#include "third_party/python/Include/yoink.h"
|
||||
/* clang-format off */
|
||||
|
||||
STATIC_STACK_SIZE(0x100000);
|
||||
|
||||
STATIC_YOINK("__die");
|
||||
STATIC_YOINK("zip_uri_support");
|
||||
|
||||
|
|
3
third_party/quickjs/qjs.c
vendored
3
third_party/quickjs/qjs.c
vendored
|
@ -27,6 +27,7 @@
|
|||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
|
@ -34,6 +35,8 @@
|
|||
#include "third_party/quickjs/cutils.h"
|
||||
#include "third_party/quickjs/quickjs-libc.h"
|
||||
|
||||
STATIC_STACK_SIZE(0x80000);
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
QuickJS (MIT License)\\n\
|
||||
Copyright (c) 2017-2021 Fabrice Bellard\\n\
|
||||
|
|
2
third_party/quickjs/quickjs-libc.c
vendored
2
third_party/quickjs/quickjs-libc.c
vendored
|
@ -26,8 +26,10 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/typedef/sighandler_t.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
|
34
third_party/sqlite3/shell.c
vendored
34
third_party/sqlite3/shell.c
vendored
|
@ -90,6 +90,7 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "third_party/sqlite3/sqlite3.h"
|
||||
|
||||
|
@ -158,39 +159,6 @@ typedef unsigned char u8;
|
|||
# define SHELL_USE_LOCAL_GETLINE 1
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
# if SQLITE_OS_WINRT
|
||||
# define SQLITE_OMIT_POPEN 1
|
||||
# else
|
||||
# include <io.h>
|
||||
# include <fcntl.h>
|
||||
# define isatty(h) _isatty(h)
|
||||
# ifndef access
|
||||
# define access(f,m) _access((f),(m))
|
||||
# endif
|
||||
# ifndef unlink
|
||||
# define unlink _unlink
|
||||
# endif
|
||||
# ifndef strdup
|
||||
# define strdup _strdup
|
||||
# endif
|
||||
# undef popen
|
||||
# define popen _popen
|
||||
# undef pclose
|
||||
# define pclose _pclose
|
||||
# endif
|
||||
#else
|
||||
/* Make sure isatty() has a prototype. */
|
||||
|
||||
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
/* popen and pclose are not C89 functions and so are
|
||||
** sometimes omitted from the "libc/stdio/stdio.h" header */
|
||||
#else
|
||||
#define SQLITE_OMIT_POPEN 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
/* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
|
||||
* thus we always assume that we have a console. That can be
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue