From 8195aff714f2ea5d680a5129a1d54af388e90355 Mon Sep 17 00:00:00 2001 From: Matthew Green Date: Sun, 3 Feb 2002 09:24:18 +0000 Subject: * implement a new `struct _reent' that is significantly smaller. use this if _REENT_SMALL is defined in config.h. define this for xstormy16. --- newlib/libc/stdlib/atexit.c | 7 +++++++ newlib/libc/stdlib/drand48.c | 1 + newlib/libc/stdlib/dtoa.c | 19 ++++++++++--------- newlib/libc/stdlib/exit.c | 5 +++++ newlib/libc/stdlib/lcong48.c | 1 + newlib/libc/stdlib/ldtoa.c | 18 ++++++++++-------- newlib/libc/stdlib/lrand48.c | 1 + newlib/libc/stdlib/mallocr.c | 1 + newlib/libc/stdlib/mprec.c | 21 ++++++++++++--------- newlib/libc/stdlib/mrand48.c | 1 + newlib/libc/stdlib/mstats.c | 1 + newlib/libc/stdlib/rand.c | 9 +++++---- newlib/libc/stdlib/rand48.c | 1 + newlib/libc/stdlib/rand48.h | 6 +++--- newlib/libc/stdlib/seed48.c | 1 + newlib/libc/stdlib/srand48.c | 1 + 16 files changed, 61 insertions(+), 33 deletions(-) (limited to 'newlib/libc/stdlib') diff --git a/newlib/libc/stdlib/atexit.c b/newlib/libc/stdlib/atexit.c index 88cdd234c..77aab0c98 100644 --- a/newlib/libc/stdlib/atexit.c +++ b/newlib/libc/stdlib/atexit.c @@ -65,6 +65,8 @@ _DEFUN (atexit, { register struct _atexit *p; +/* _REENT_SMALL atexit() doesn't allow more than the required 32 entries. */ +#ifndef _REENT_SMALL if ((p = _REENT->_atexit) == NULL) _REENT->_atexit = p = &_REENT->_atexit0; if (p->_ind >= _ATEXIT_SIZE) @@ -75,6 +77,11 @@ _DEFUN (atexit, p->_next = _REENT->_atexit; _REENT->_atexit = p; } +#else + p = &_REENT->_atexit; + if (p->_ind >= _ATEXIT_SIZE) + return -1; +#endif p->_fns[p->_ind++] = fn; return 0; } diff --git a/newlib/libc/stdlib/drand48.c b/newlib/libc/stdlib/drand48.c index 8f9c4a269..89fe6af1d 100644 --- a/newlib/libc/stdlib/drand48.c +++ b/newlib/libc/stdlib/drand48.c @@ -17,6 +17,7 @@ double _DEFUN (_drand48_r, (r), struct _reent *r) { + _REENT_CHECK_RAND48(r); return _erand48_r(r, __rand48_seed); } diff --git a/newlib/libc/stdlib/dtoa.c b/newlib/libc/stdlib/dtoa.c index 1ea1c5560..c9be9ed51 100644 --- a/newlib/libc/stdlib/dtoa.c +++ b/newlib/libc/stdlib/dtoa.c @@ -235,12 +235,13 @@ _DEFUN (_dtoa_r, d.d = _d; - if (ptr->_result) + _REENT_CHECK_MP(ptr); + if (_REENT_MP_RESULT(ptr)) { - ptr->_result->_k = ptr->_result_k; - ptr->_result->_maxwds = 1 << ptr->_result_k; - Bfree (ptr, ptr->_result); - ptr->_result = 0; + _REENT_MP_RESULT(ptr)->_k = _REENT_MP_RESULT_K(ptr); + _REENT_MP_RESULT(ptr)->_maxwds = 1 << _REENT_MP_RESULT_K(ptr); + Bfree (ptr, _REENT_MP_RESULT(ptr)); + _REENT_MP_RESULT(ptr) = 0; } if (word0 (d) & Sign_bit) @@ -415,11 +416,11 @@ _DEFUN (_dtoa_r, i = 1; } j = sizeof (__ULong); - for (ptr->_result_k = 0; sizeof (_Bigint) - sizeof (__ULong) + j <= i; + for (_REENT_MP_RESULT_K(ptr) = 0; sizeof (_Bigint) - sizeof (__ULong) + j <= i; j <<= 1) - ptr->_result_k++; - ptr->_result = Balloc (ptr, ptr->_result_k); - s = s0 = (char *) ptr->_result; + _REENT_MP_RESULT_K(ptr)++; + _REENT_MP_RESULT(ptr) = Balloc (ptr, _REENT_MP_RESULT_K(ptr)); + s = s0 = (char *) _REENT_MP_RESULT(ptr); if (ilim >= 0 && ilim <= Quick_max && try_quick) { diff --git a/newlib/libc/stdlib/exit.c b/newlib/libc/stdlib/exit.c index 543bd0e30..fb7f73e77 100644 --- a/newlib/libc/stdlib/exit.c +++ b/newlib/libc/stdlib/exit.c @@ -62,9 +62,14 @@ _DEFUN (exit, (code), register struct _atexit *p; register int n; +#ifdef _REENT_SMALL + for (p = &_REENT->_atexit, n = p->_ind; --n >= 0;) + (*p->_fns[n]) (); +#else for (p = _REENT->_atexit; p; p = p->_next) for (n = p->_ind; --n >= 0;) (*p->_fns[n]) (); +#endif if (_REENT->__cleanup) (*_REENT->__cleanup) (_REENT); _exit (code); diff --git a/newlib/libc/stdlib/lcong48.c b/newlib/libc/stdlib/lcong48.c index 6dae4e906..548f32757 100644 --- a/newlib/libc/stdlib/lcong48.c +++ b/newlib/libc/stdlib/lcong48.c @@ -18,6 +18,7 @@ _DEFUN (_lcong48_r, (r, p), struct _reent *r _AND unsigned short p[7]) { + _REENT_CHECK_RAND48(r); __rand48_seed[0] = p[0]; __rand48_seed[1] = p[1]; __rand48_seed[2] = p[2]; diff --git a/newlib/libc/stdlib/ldtoa.c b/newlib/libc/stdlib/ldtoa.c index b332d2a2e..0a4c3230f 100644 --- a/newlib/libc/stdlib/ldtoa.c +++ b/newlib/libc/stdlib/ldtoa.c @@ -2711,13 +2711,15 @@ char *outstr; rnd.rlast = -1; rnd.rndprc = NBITS; + _REENT_CHECK_MP(ptr); + /* reentrancy addition to use mprec storage pool */ -if (ptr->_result) +if (_REENT_MP_RESULT(ptr)) { - ptr->_result->_k = ptr->_result_k; - ptr->_result->_maxwds = 1 << ptr->_result_k; - Bfree (ptr, ptr->_result); - ptr->_result = 0; + _REENT_MP_RESULT(ptr)->_k = _REENT_MP_RESULT_K(ptr); + _REENT_MP_RESULT(ptr)->_maxwds = 1 << _REENT_MP_RESULT_K(ptr); + Bfree (ptr, _REENT_MP_RESULT(ptr)); + _REENT_MP_RESULT(ptr) = 0; } #if LDBL_MANT_DIG == 24 @@ -2748,9 +2750,9 @@ if( ndigits > NDEC ) ndigits = NDEC; /* reentrancy addition to use mprec storage pool */ -ptr->_result = Balloc (ptr, 3); -ptr->_result_k = 3; -outstr = (char *)ptr->_result; +_REENT_MP_RESULT(ptr) = Balloc (ptr, 3); +_REENT_MP_RESULT_K(ptr) = 3; +outstr = (char *)_REENT_MP_RESULT(ptr); etoasc( e, outstr, ndigits, mode, ldp ); s = outstr; diff --git a/newlib/libc/stdlib/lrand48.c b/newlib/libc/stdlib/lrand48.c index 2e850f224..bfc693b75 100644 --- a/newlib/libc/stdlib/lrand48.c +++ b/newlib/libc/stdlib/lrand48.c @@ -17,6 +17,7 @@ long _DEFUN (_lrand48_r, (r), struct _reent *r) { + _REENT_CHECK_RAND48(r); __dorand48(r, __rand48_seed); return (long)((unsigned long) __rand48_seed[2] << 15) + ((unsigned long) __rand48_seed[1] >> 1); diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c index fb9b7d8b5..1e7120ab3 100644 --- a/newlib/libc/stdlib/mallocr.c +++ b/newlib/libc/stdlib/mallocr.c @@ -3462,6 +3462,7 @@ void malloc_stats(RONEARG) RDECL MALLOC_UNLOCK; #ifdef INTERNAL_NEWLIB + _REENT_SMALL_CHECK_INIT(_stderr_r (reent_ptr)); fp = _stderr_r(reent_ptr); #define fprintf fiprintf #else diff --git a/newlib/libc/stdlib/mprec.c b/newlib/libc/stdlib/mprec.c index 8a2d404dc..0ef28c745 100644 --- a/newlib/libc/stdlib/mprec.c +++ b/newlib/libc/stdlib/mprec.c @@ -95,21 +95,22 @@ _DEFUN (Balloc, (ptr, k), struct _reent *ptr _AND int k) int x; _Bigint *rv ; - if (ptr->_freelist == NULL) + _REENT_CHECK_MP(ptr); + if (_REENT_MP_FREELIST(ptr) == NULL) { /* Allocate a list of pointers to the mprec objects */ - ptr->_freelist = (struct _Bigint **) _calloc_r (ptr, + _REENT_MP_FREELIST(ptr) = (struct _Bigint **) _calloc_r (ptr, sizeof (struct _Bigint *), _Kmax + 1); - if (ptr->_freelist == NULL) + if (_REENT_MP_FREELIST(ptr) == NULL) { return NULL; } } - if ((rv = ptr->_freelist[k]) != 0) + if ((rv = _REENT_MP_FREELIST(ptr)[k]) != 0) { - ptr->_freelist[k] = rv->_next; + _REENT_MP_FREELIST(ptr)[k] = rv->_next; } else { @@ -130,10 +131,11 @@ _DEFUN (Balloc, (ptr, k), struct _reent *ptr _AND int k) void _DEFUN (Bfree, (ptr, v), struct _reent *ptr _AND _Bigint * v) { + _REENT_CHECK_MP(ptr); if (v) { - v->_next = ptr->_freelist[v->_k]; - ptr->_freelist[v->_k] = v; + v->_next = _REENT_MP_FREELIST(ptr)[v->_k]; + _REENT_MP_FREELIST(ptr)[v->_k] = v; } } @@ -425,10 +427,11 @@ _DEFUN (pow5mult, if (!(k >>= 2)) return b; - if (!(p5 = ptr->_p5s)) + _REENT_CHECK_MP(ptr); + if (!(p5 = _REENT_MP_P5S(ptr))) { /* first time */ - p5 = ptr->_p5s = i2b (ptr, 625); + p5 = _REENT_MP_P5S(ptr) = i2b (ptr, 625); p5->_next = 0; } for (;;) diff --git a/newlib/libc/stdlib/mrand48.c b/newlib/libc/stdlib/mrand48.c index d515b3a80..28f4f7d2b 100644 --- a/newlib/libc/stdlib/mrand48.c +++ b/newlib/libc/stdlib/mrand48.c @@ -17,6 +17,7 @@ long _DEFUN (_mrand48_r, (r), struct _reent *r) { + _REENT_CHECK_RAND48(r); __dorand48(r, __rand48_seed); return ((long) __rand48_seed[2] << 16) + (long) __rand48_seed[1]; } diff --git a/newlib/libc/stdlib/mstats.c b/newlib/libc/stdlib/mstats.c index c1628957a..a2ae95929 100644 --- a/newlib/libc/stdlib/mstats.c +++ b/newlib/libc/stdlib/mstats.c @@ -135,6 +135,7 @@ _DEFUN (_mstats_r, (ptr, s), struct _reent *ptr _AND char *s) { + _REENT_SMALL_CHECK_INIT(_stderr_r (ptr)); fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s); _malloc_stats_r (ptr); } diff --git a/newlib/libc/stdlib/rand.c b/newlib/libc/stdlib/rand.c index a085ef37c..4f5a60796 100644 --- a/newlib/libc/stdlib/rand.c +++ b/newlib/libc/stdlib/rand.c @@ -72,7 +72,7 @@ on two different systems. void _DEFUN (srand, (seed), unsigned int seed) { - _REENT->_new._reent._rand_next = seed; + _REENT_RAND_NEXT(_REENT) = seed; } int @@ -81,9 +81,10 @@ _DEFUN_VOID (rand) /* This multiplier was obtained from Knuth, D.E., "The Art of Computer Programming," Vol 2, Seminumerical Algorithms, Third Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */ - _REENT->_new._reent._rand_next = - _REENT->_new._reent._rand_next * __extension__ 6364136223846793005LL + 1; - return (int)((_REENT->_new._reent._rand_next >> 32) & RAND_MAX); + _REENT_CHECK_RAND48(_REENT); + _REENT_RAND_NEXT(_REENT) = + _REENT_RAND_NEXT(_REENT) * __extension__ 6364136223846793005LL + 1; + return (int)((_REENT_RAND_NEXT(_REENT) >> 32) & RAND_MAX); } #endif /* _REENT_ONLY */ diff --git a/newlib/libc/stdlib/rand48.c b/newlib/libc/stdlib/rand48.c index c65af12cd..17fd04e92 100644 --- a/newlib/libc/stdlib/rand48.c +++ b/newlib/libc/stdlib/rand48.c @@ -163,6 +163,7 @@ _DEFUN (__dorand48, (r, xseed), unsigned long accu; unsigned short temp[2]; + _REENT_CHECK_RAND48(r); accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] + (unsigned long) __rand48_add; temp[0] = (unsigned short) accu; /* lower 16 bits */ diff --git a/newlib/libc/stdlib/rand48.h b/newlib/libc/stdlib/rand48.h index c1446d683..a6cb479ef 100644 --- a/newlib/libc/stdlib/rand48.h +++ b/newlib/libc/stdlib/rand48.h @@ -18,9 +18,9 @@ #include extern void _EXFUN(__dorand48,(struct _reent *r, unsigned short[3])); -#define __rand48_seed (r->_new._reent._r48._seed) -#define __rand48_mult (r->_new._reent._r48._mult) -#define __rand48_add (r->_new._reent._r48._add) +#define __rand48_seed _REENT_RAND48_SEED(r) +#define __rand48_mult _REENT_RAND48_MULT(r) +#define __rand48_add _REENT_RAND48_ADD(r) #if 0 /* following values are defined in */ diff --git a/newlib/libc/stdlib/seed48.c b/newlib/libc/stdlib/seed48.c index 3f2cb5061..43629cc40 100644 --- a/newlib/libc/stdlib/seed48.c +++ b/newlib/libc/stdlib/seed48.c @@ -20,6 +20,7 @@ _DEFUN (_seed48_r, (r, xseed), { static unsigned short sseed[3]; + _REENT_CHECK_RAND48(r); sseed[0] = __rand48_seed[0]; sseed[1] = __rand48_seed[1]; sseed[2] = __rand48_seed[2]; diff --git a/newlib/libc/stdlib/srand48.c b/newlib/libc/stdlib/srand48.c index 8850540e3..69bdbfc3b 100644 --- a/newlib/libc/stdlib/srand48.c +++ b/newlib/libc/stdlib/srand48.c @@ -18,6 +18,7 @@ _DEFUN (_srand48_r, (r, seed), struct _reent *r _AND long seed) { + _REENT_CHECK_RAND48(r); __rand48_seed[0] = _RAND48_SEED_0; __rand48_seed[1] = (unsigned short) seed; __rand48_seed[2] = (unsigned short) ((unsigned long)seed >> 16); -- cgit v1.2.3