diff options
Diffstat (limited to 'lib/libc/stdlib/netbsd_strtod.c')
-rw-r--r-- | lib/libc/stdlib/netbsd_strtod.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/lib/libc/stdlib/netbsd_strtod.c b/lib/libc/stdlib/netbsd_strtod.c index ea0dbcd..a402b68 100644 --- a/lib/libc/stdlib/netbsd_strtod.c +++ b/lib/libc/stdlib/netbsd_strtod.c @@ -142,7 +142,7 @@ __RCSID("$NetBSD: strtod.c,v 1.26 1998/02/03 18:44:21 perry Exp $"); #include "memory.h" #endif #endif -char *__dtoa __P((double, int, int, int *, int *, char **, char **)); +char *__dtoa __P((double, int, int, int *, int *, char **)); #ifdef MALLOC #ifdef KR_headers @@ -384,16 +384,6 @@ Bigint { static Bigint *freelist[Kmax+1]; - /* - * Make Balloc/Bfree thread-safe in libc for use with - * kernel threads. - */ -#include "libc_private.h" -#include "spinlock.h" -static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; -#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock); -#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock); - static Bigint * Balloc #ifdef KR_headers @@ -405,13 +395,10 @@ Balloc int x; Bigint *rv; - THREAD_LOCK(); if ((rv = freelist[k]) != NULL) { freelist[k] = rv->next; - THREAD_UNLOCK(); } else { - THREAD_UNLOCK(); x = 1 << k; rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long)); rv->k = k; @@ -430,10 +417,8 @@ Bfree #endif { if (v) { - THREAD_LOCK(); v->next = freelist[v->k]; freelist[v->k] = v; - THREAD_UNLOCK(); } } @@ -1915,11 +1900,10 @@ quorem char * __dtoa #ifdef KR_headers - (d, mode, ndigits, decpt, sign, rve, resultp) - double d; int mode, ndigits, *decpt, *sign; char **rve, **resultp; + (d, mode, ndigits, decpt, sign, rve) + double d; int mode, ndigits, *decpt, *sign; char **rve; #else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, - char **resultp) + (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) #endif { /* Arguments ndigits, decpt, sign are similar to those @@ -1969,6 +1953,15 @@ __dtoa Bigint *mlo = NULL; /* pacify gcc */ double d2, ds, eps; char *s, *s0; + static Bigint *result; + static int result_k; + + if (result) { + result->k = result_k; + result->maxwds = 1 << result_k; + Bfree(result); + result = 0; + } if (word0(d) & Sign_bit) { /* set sign for everything, including 0's and NaNs */ @@ -2130,8 +2123,11 @@ __dtoa if (i <= 0) i = 1; } - *resultp = (char *) malloc(i + 1); - s = s0 = *resultp; + j = sizeof(ULong); + for(result_k = 0; sizeof(Bigint) - sizeof(ULong) + j <= i; + j <<= 1) result_k++; + result = Balloc(result_k); + s = s0 = (char *)result; if (ilim >= 0 && ilim <= Quick_max && try_quick) { |