Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Green <mrg@redhat.com>2002-02-03 12:24:18 +0300
committerMatthew Green <mrg@redhat.com>2002-02-03 12:24:18 +0300
commit8195aff714f2ea5d680a5129a1d54af388e90355 (patch)
tree683ff47f4802385e669491dda42bf8050772dbdf
parentad67ada2fc7cdb361643d506701e274a67d796f9 (diff)
* implement a new `struct _reent' that is significantly smaller. use this
if _REENT_SMALL is defined in config.h. define this for xstormy16.
-rw-r--r--newlib/ChangeLog84
-rw-r--r--newlib/libc/include/math.h2
-rw-r--r--newlib/libc/include/sys/config.h1
-rw-r--r--newlib/libc/include/sys/reent.h212
-rw-r--r--newlib/libc/reent/reent.c27
-rw-r--r--newlib/libc/reent/reent.tex4
-rw-r--r--newlib/libc/reent/signgam.c2
-rw-r--r--newlib/libc/stdio/findfp.c23
-rw-r--r--newlib/libc/stdio/getchar.c3
-rw-r--r--newlib/libc/stdio/iprintf.c6
-rw-r--r--newlib/libc/stdio/perror.c3
-rw-r--r--newlib/libc/stdio/printf.c6
-rw-r--r--newlib/libc/stdio/putchar.c3
-rw-r--r--newlib/libc/stdio/puts.c3
-rw-r--r--newlib/libc/stdio/scanf.c2
-rw-r--r--newlib/libc/stdio/tmpnam.c3
-rw-r--r--newlib/libc/stdio/vprintf.c6
-rw-r--r--newlib/libc/stdio/vscanf.c2
-rw-r--r--newlib/libc/stdlib/atexit.c7
-rw-r--r--newlib/libc/stdlib/drand48.c1
-rw-r--r--newlib/libc/stdlib/dtoa.c19
-rw-r--r--newlib/libc/stdlib/exit.c5
-rw-r--r--newlib/libc/stdlib/lcong48.c1
-rw-r--r--newlib/libc/stdlib/ldtoa.c18
-rw-r--r--newlib/libc/stdlib/lrand48.c1
-rw-r--r--newlib/libc/stdlib/mallocr.c1
-rw-r--r--newlib/libc/stdlib/mprec.c21
-rw-r--r--newlib/libc/stdlib/mrand48.c1
-rw-r--r--newlib/libc/stdlib/mstats.c1
-rw-r--r--newlib/libc/stdlib/rand.c9
-rw-r--r--newlib/libc/stdlib/rand48.c1
-rw-r--r--newlib/libc/stdlib/rand48.h6
-rw-r--r--newlib/libc/stdlib/seed48.c1
-rw-r--r--newlib/libc/stdlib/srand48.c1
-rw-r--r--newlib/libc/string/strtok.c3
-rw-r--r--newlib/libc/time/asctime.c4
-rw-r--r--newlib/libc/time/lcltime.c3
-rw-r--r--newlib/libm/math/w_gamma.c4
-rw-r--r--newlib/libm/math/w_lgamma.c4
-rw-r--r--newlib/libm/math/wf_gamma.c4
-rw-r--r--newlib/libm/math/wf_lgamma.c4
41 files changed, 445 insertions, 67 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 4ded001a7..3d33a4ca0 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,87 @@
+2002-02-02 matthew green <mrg@redhat.com>
+
+ * libc/include/sys/config.h (_REENT_SMALL): Define for Xstormy16.
+
+ * libc/reent/reent.c (_reclaim_reent): Clean for _REENT_SMALL case.
+ * libc/reent/reent.tex: Add blurb about _REENT_SMALL.
+ * libc/include/sys/reent.h (struct _reent): Completely new version
+ for _REENT_SMALL.
+ (_REENT_INIT): New defines, different defintion depending on _REENT_SMALL.
+ (_REENT_CHECK, _REENT_CHECK_TM): Likewise.
+ (_REENT_CHECK_ASCTIME_BUF, _REENT_INIT_RAND48): Likewise.
+ (_REENT_CHECK_RAND48, _REENT_INIT_MP, _REENT_CHECK_MP): Likewise.
+ (_REENT_CHECK_EMERGENCY, _REENT_SIGNGAM, _REENT_RAND_NEXT): Likewise.
+ (_REENT_RAND48_SEED, _REENT_RAND48_MULT, _REENT_RAND48_ADD): Likewise.
+ (_REENT_MP_RESULT, _REENT_MP_RESULT_K, _REENT_MP_P5S): Likewise.
+ (_REENT_MP_FREELIST, _REENT_ASCTIME_BUF, _REENT_TM): Likewise.
+ (_REENT_EMERGENCY): Likewise.
+
+ * libc/include/sys/reent.h (struct __sFILE_fake): New struct, same as
+ the start of the real __sFILE, used for stdin, stdout and stderr until
+ they are setup properly.
+ (struct __sFILE): Move location of _data in _REENT_SMALL case.
+ * libc/stdio/findfp.c (__sinit): Rearrange for _REENT_SMALL case by
+ allocated stdin, stdout and stderr.
+ * libc/stdio/getchar.c (_getchar_r): Call _REENT_SMALL_CHECK_INIT().
+ * libc/stdio/iprintf.c (iprintf, _iprintf_r): Likewise.
+ * libc/stdio/perror.c (_perror_r): Likewise.
+ * libc/stdio/printf.c (printf, _printf_r): Likewise.
+ * libc/stdio/putchar.c (_putchar_r): Likewise.
+ * libc/stdio/puts.c (_puts_r): Likewise.
+ * libc/stdio/scanf.c (scanf, _scanf_r): Likewise.
+ * libc/stdio/vprintf.c (vprintf): Likewise.
+ * libc/stdio/vscanf.c (vscanf, _vscanf_r): Likewise.
+
+ * libc/stdio/tmpnam.c (_tmpnam_r): Use _REENT_EMERGENCY().
+
+ * libc/reent/reent.c (_wrapup_reent): Adjust for _REENT_SMALL atexit.
+ * libc/include/sys/reent.h (_atexit): Limit atexit() entries to 32
+ for _REENT_SMALL.
+ * libc/stdlib/atexit.c (atexit): Rearrange for _REENT_SMALL case.
+ * libc/stdlib/exit.c (exit): Rearrange for _REENT_SMALL case.
+
+ * libc/include/sys/reent.h (struct _rand48): Keep _rand_next if
+ _REENT_SMALL.
+ * libc/stdlib/drand48.c (_drand48_r): Call _REENT_CHECK_RAND48().
+ * libc/stdlib/lcong48.c (_lcong48_r): Likewise.
+ * libc/stdlib/lrand48.c (_lrand48_r): Likewise.
+ * libc/stdlib/mrand48.c (_mrand48_r): Likewise.
+ * libc/stdlib/rand48.c (__dorand48): Likewise.
+ * libc/stdlib/seed48.c (_seed48_r): Likewise.
+ * libc/stdlib/srand48.c (_srand48_r): Likewise.
+ * libc/stdlib/rand48.h (__rand48_seed, __rand48_mult, __rand48_add): Define
+ as _REENT_RAND48_SEED(), _REENT_RAND48_MULT() and _REENT_RAND48_ADD().
+ * libc/stdlib/dtoa.c (_dtoa_r): Call _REENT_CHECK_MP(). Use
+ _REENT_MP_RESULT() and _REENT_MP_RESULT_K().
+ * libc/stdlib/ldtoa.c (_ldtoa_r): Likewise.
+ * libc/stdlib/rand.c (srand): Use _REENT_RAND_NEXT().
+ * libc/stdlib/rand.c (rand): Likewise.
+
+ * libc/stdlib/mallocr.c (malloc_stats): Call _REENT_SMALL_CHECK_INIT().
+ * libc/stdlib/mstats.c (_mstats_r): Call _REENT_SMALL_CHECK_INIT().
+
+ * libc/stdlib/mprec.c (Balloc): Call _REENT_CHECK_MP. Use
+ _REENT_MP_FREELIST() and _REENT_MP_P5S.
+ * libc/include/sys/reent.h (struct _mprec): New structure.
+
+ * libc/include/sys/reent.h (struct _reent): Rename _strtok_last to
+ _unused_strtok_last.
+ * libc/string/strtok.c (strtok): Use a local static variable.
+
+ * libc/include/sys/reent.h (_REENT_ASCTIME_SIZE): New define.
+ (_REENT_EMERGENCY_SIZE): Likewise.
+ * libc/time/asctime.c (asctime): Call _REENT_CHECK_ASCTIME_BUF(). Use
+ _REENT_ASCTIME_BUF().
+ * libc/time/lcltime.c (localtime): Call _REENT_CHECK_TM(). Use
+ _REENT_TM().
+
+ * libc/include/math.h (__singam_r): Use _REENT_SIGNGAM().
+ * libc/reent/signgam.c (__signgam): Use _REENT_SIGNGAM().
+ * libm/math/w_gamma.c (gamma): Use _REENT_SIGNGAM().
+ * libm/math/w_lgamma.c (lgamma): Use _REENT_SIGNGAM().
+ * libm/math/wf_gamma.c (gammaf): Use _REENT_SIGNGAM().
+ * libm/math/wf_lgamma.c (lgammaf): Use _REENT_SIGNGAM().
+
2002-02-01 Geoffrey Keating <geoffk@redhat.com>
* configure.host (xstormy16): Don't use the generic malloc.
diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index e72d9ca21..0b9ef594e 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -198,7 +198,7 @@ extern float dremf _PARAMS((float, float));
extern int *__signgam _PARAMS((void));
#endif /* ! defined (_REENT_ONLY) */
-#define __signgam_r(ptr) ((ptr)->_new._reent._gamma_signgam)
+#define __signgam_r(ptr) _REENT_SIGNGAM(ptr)
/* The exception structure passed to the matherr routine. */
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 8b1358893..a19274591 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -123,6 +123,7 @@
#define MALLOC_ALIGNMENT 8
#define _POINTER_INT short
#define __BUFSIZ__ 16
+#define _REENT_SMALL
#endif
#if INT_MAX == 32767
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 65417f83a..7d1a47215 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -28,6 +28,11 @@ typedef unsigned __Long __ULong;
typedef __uint32_t __ULong;
#endif
+/*
+ * If _REENT_SMALL is defined, we make struct _reent as small as possible,
+ * by having nearly everything possible allocated at first use.
+ */
+
struct _glue
{
struct _glue *_next;
@@ -57,16 +62,23 @@ struct __tm
};
/*
- * atexit() support
+ * atexit() support. For _REENT_SMALL, we limit to 32 max.
*/
#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
+#ifndef _REENT_SMALL
struct _atexit {
struct _atexit *_next; /* next in list */
int _ind; /* next index in this table */
void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
};
+#else
+struct _atexit {
+ int _ind; /* next index in this table */
+ void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
+};
+#endif
/*
* Stdio buffers.
@@ -113,6 +125,29 @@ typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
* _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
*/
+#ifdef _REENT_SMALL
+/*
+ * struct __sFILE_fake is the start of a struct __sFILE, with only the
+ * minimal fields allocated. In __sinit() we really allocate the 3
+ * standard streams, etc., and point away from this fake.
+ */
+struct __sFILE_fake {
+ unsigned char *_p; /* current position in (some) buffer */
+ int _r; /* read space left for getc() */
+ int _w; /* write space left for putc() */
+ short _flags; /* flags, below; this FILE is free if 0 */
+ short _file; /* fileno, if Unix descriptor, else -1 */
+ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
+ int _lbfsize; /* 0 or -_bf._size, for inline putc */
+
+ struct _reent *_data;
+};
+/* CHECK_INIT() comes from stdio/local.h; be sure to include that. */
+# define _REENT_SMALL_CHECK_INIT(fp) CHECK_INIT(fp)
+#else
+# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */
+#endif
+
struct __sFILE {
unsigned char *_p; /* current position in (some) buffer */
int _r; /* read space left for getc() */
@@ -122,6 +157,10 @@ struct __sFILE {
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
int _lbfsize; /* 0 or -_bf._size, for inline putc */
+#ifdef _REENT_SMALL
+ struct _reent *_data;
+#endif
+
/* operations */
_PTR _cookie; /* cookie passed to io functions */
@@ -147,7 +186,9 @@ struct __sFILE {
int _blksize; /* stat.st_blksize (may be != _bf._size) */
int _offset; /* current lseek offset */
- struct _reent *_data;
+#ifndef _REENT_SMALL
+ struct _reent *_data; /* Here for binary compatibility? Remove? */
+#endif
};
/*
@@ -175,8 +216,16 @@ struct _rand48 {
unsigned short _seed[3];
unsigned short _mult[3];
unsigned short _add;
+#ifdef _REENT_SMALL
+ /* Put this in here as well, for good luck. */
+ __extension__ unsigned long long _rand_next;
+#endif
};
+/* How big the some arrays are. */
+#define _REENT_EMERGENCY_SIZE 25
+#define _REENT_ASCTIME_SIZE 26
+
/*
* struct _reent
*
@@ -185,10 +234,137 @@ struct _rand48 {
* reentrant. IE: All state information is contained here.
*/
+#ifdef _REENT_SMALL
+
+struct _mprec
+{
+ /* used by mprec routines */
+ struct _Bigint *_result;
+ int _result_k;
+ struct _Bigint *_p5s;
+ struct _Bigint **_freelist;
+};
+
+/* This version of _reent is layed our with "int"s in pairs, to help
+ * ports with 16-bit int's but 32-bit pointers, align nicely. */
+struct _reent
+{
+
+ /* FILE is a big struct and may change over time. To try to achieve binary
+ compatibility with future versions, put stdin,stdout,stderr here.
+ These are pointers into member __sf defined below. */
+ struct __sFILE *_stdin, *_stdout, *_stderr; /* XXX */
+
+ int _errno; /* local copy of errno */
+
+ int _inc; /* used by tmpnam */
+
+ char *_emergency;
+
+ int __sdidinit; /* 1 means stdio has been init'd */
+
+ int _current_category; /* used by setlocale */
+ _CONST char *_current_locale;
+
+ struct _mprec *_mp;
+
+ void _EXFUN((*__cleanup),(struct _reent *));
+
+ int _gamma_signgam;
+
+ /* used by some fp conversion routines */
+ int _cvtlen; /* should be size_t */
+ char *_cvtbuf;
+
+ struct _rand48 *_r48;
+ struct __tm *_localtime_buf;
+ char *_asctime_buf;
+
+ /* signal info */
+ void (**(_sig_func))(int);
+
+ /* atexit stuff */
+ struct _atexit _atexit;
+
+ struct _glue __sglue; /* root of glue chain */
+ struct __sFILE *__sf; /* file descriptors */
+ struct __sFILE_fake __sf_fake; /* fake initial stdin/out/err */
+};
+
+#define _REENT_INIT(var) \
+ { &var.__sf_fake, &var.__sf_fake, &var.__sf_fake, 0, 0, _NULL, 0, 0, \
+ "C", _NULL, _NULL, 0, 0, _NULL, _NULL, _NULL, _NULL, _NULL, \
+ { 0, _NULL }, { _NULL, 0, _NULL }, 0 }
+
+/* Only built the assert() calls if we are built with debugging. */
+#if DEBUG
+#include <assert.h>
+#else
+#define assert(x) ((void)0)
+#endif
+
+/* Generic _REENT check macro. */
+#define _REENT_CHECK(var, what, type, size, init) do { \
+ struct _reent *_r = (var); \
+ if (_r->what == NULL) { \
+ _r->what = (type)malloc(size); \
+ assert(_r->what); \
+ init; \
+ } \
+} while (0)
+
+#define _REENT_CHECK_TM(var) \
+ _REENT_CHECK(var, _localtime_buf, struct __tm *, sizeof *((var)->_localtime_buf), \
+ /* nothing */)
+
+#define _REENT_CHECK_ASCTIME_BUF(var) \
+ _REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
+ memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
+
+/* Handle the dynamically allocated rand48 structure. */
+#define _REENT_INIT_RAND48(var) do { \
+ struct _reent *_r = (var); \
+ _r->_r48->_seed[0] = _RAND48_SEED_0; \
+ _r->_r48->_seed[1] = _RAND48_SEED_1; \
+ _r->_r48->_seed[2] = _RAND48_SEED_2; \
+ _r->_r48->_mult[0] = _RAND48_MULT_0; \
+ _r->_r48->_mult[1] = _RAND48_MULT_1; \
+ _r->_r48->_mult[2] = _RAND48_MULT_2; \
+ _r->_r48->_add = _RAND48_ADD; \
+} while (0)
+#define _REENT_CHECK_RAND48(var) \
+ _REENT_CHECK(var, _r48, struct _rand48 *, sizeof *((var)->_r48), _REENT_INIT_RAND48((var)))
+
+#define _REENT_INIT_MP(var) do { \
+ struct _reent *_r = (var); \
+ _r->_mp->_result_k = 0; \
+ _r->_mp->_result = _r->_mp->_p5s = _NULL; \
+ _r->_mp->_freelist = _NULL; \
+} while (0)
+#define _REENT_CHECK_MP(var) \
+ _REENT_CHECK(var, _mp, struct _mprec *, sizeof *((var)->_mp), _REENT_INIT_MP(var))
+
+#define _REENT_CHECK_EMERGENCY(var) \
+ _REENT_CHECK(var, _emergency, char *, sizeof *((var)->_emergency), /* nothing */)
+
+#define _REENT_SIGNGAM(ptr) ((ptr)->_gamma_signgam)
+#define _REENT_RAND_NEXT(ptr) ((ptr)->_r48->_rand_next)
+#define _REENT_RAND48_SEED(ptr) ((ptr)->_r48->_seed)
+#define _REENT_RAND48_MULT(ptr) ((ptr)->_r48->_mult)
+#define _REENT_RAND48_ADD(ptr) ((ptr)->_r48->_add)
+#define _REENT_MP_RESULT(ptr) ((ptr)->_mp->_result)
+#define _REENT_MP_RESULT_K(ptr) ((ptr)->_mp->_result_k)
+#define _REENT_MP_P5S(ptr) ((ptr)->_mp->_p5s)
+#define _REENT_MP_FREELIST(ptr) ((ptr)->_mp->_freelist)
+#define _REENT_ASCTIME_BUF(ptr) ((ptr)->_asctime_buf)
+#define _REENT_TM(ptr) ((ptr)->_localtime_buf)
+#define _REENT_EMERGENCY(ptr) ((ptr)->_emergency)
+
+#else /* !_REENT_SMALL */
+
struct _reent
{
- /* local copy of errno */
- int _errno;
+ int _errno; /* local copy of errno */
/* FILE is a big struct and may change over time. To try to achieve binary
compatibility with future versions, put stdin,stdout,stderr here.
@@ -196,7 +372,7 @@ struct _reent
struct __sFILE *_stdin, *_stdout, *_stderr;
int _inc; /* used by tmpnam */
- char _emergency[25];
+ char _emergency[_REENT_EMERGENCY_SIZE];
int _current_category; /* used by setlocale */
_CONST char *_current_locale;
@@ -220,7 +396,7 @@ struct _reent
struct
{
unsigned int _unused_rand;
- char * _strtok_last;
+ char * _unused_strtok_last;
char _asctime_buf[26];
struct __tm _localtime_buf;
int _gamma_signgam;
@@ -252,8 +428,6 @@ struct _reent
struct __sFILE __sf[3]; /* first three file descriptors */
};
-#define _NULL 0
-
#define _REENT_INIT(var) \
{ 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
0, _NULL, _NULL, 0, _NULL, _NULL, 0, _NULL, { {0, _NULL, "", \
@@ -261,6 +435,28 @@ struct _reent
{{_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \
{_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, _RAND48_ADD}} } }
+#define _REENT_CHECK_RAND48(ptr) /* nothing */
+#define _REENT_CHECK_MP(ptr) /* nothing */
+#define _REENT_CHECK_TM(ptr) /* nothing */
+#define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */
+
+#define _REENT_SIGNGAM(ptr) ((ptr)->_new._reent._gamma_signgam)
+#define _REENT_RAND_NEXT(ptr) ((ptr)->_new._reent._rand_next)
+#define _REENT_RAND48_SEED(ptr) ((ptr)->_new._reent._r48._seed)
+#define _REENT_RAND48_MULT(ptr) ((ptr)->_new._reent._r48._mult)
+#define _REENT_RAND48_ADD(ptr) ((ptr)->_new._reent._r48._add)
+#define _REENT_MP_RESULT(ptr) ((ptr)->_result)
+#define _REENT_MP_RESULT_K(ptr) ((ptr)->_result_k)
+#define _REENT_MP_P5S(ptr) ((ptr)->_p5s)
+#define _REENT_MP_FREELIST(ptr) ((ptr)->_freelist)
+#define _REENT_ASCTIME_BUF(ptr) (&(ptr)->_new._reent._asctime_buf)
+#define _REENT_TM(ptr) (&(ptr)->_new._reent._localtime_buf)
+#define _REENT_EMERGENCY(ptr) ((ptr)->_emergency)
+
+#endif /* !_REENT_SMALL */
+
+#define _NULL 0
+
/*
* All references to struct _reent are via this pointer.
* Internally, newlib routines that need to reference it should use _REENT.
diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c
index f35d95711..192796908 100644
--- a/newlib/libc/reent/reent.c
+++ b/newlib/libc/reent/reent.c
@@ -48,14 +48,17 @@ _reclaim_reent (ptr)
if (ptr != _impure_ptr)
{
/* used by mprec routines. */
- if (ptr->_freelist)
+#ifdef _REENT_SMALL
+ if (ptr->_mp) /* don't bother allocating it! */
+#endif
+ if (_REENT_MP_FREELIST(ptr))
{
int i;
for (i = 0; i < 15 /* _Kmax */; i++)
{
struct _Bigint *thisone, *nextone;
- nextone = ptr->_freelist[i];
+ nextone = _REENT_MP_FREELIST(ptr)[i];
while (nextone)
{
thisone = nextone;
@@ -64,9 +67,21 @@ _reclaim_reent (ptr)
}
}
- _free_r (ptr, ptr->_freelist);
+ _free_r (ptr, _REENT_MP_FREELIST(ptr));
}
+#ifdef _REENT_SMALL
+ if (ptr->_emergency)
+ _free_r (ptr, ptr->_emergency);
+ if (ptr->_mp)
+ _free_r (ptr, ptr->_mp);
+ if (ptr->_r48)
+ _free_r (ptr, ptr->_r48);
+ if (ptr->_localtime_buf)
+ _free_r (ptr, ptr->_localtime_buf);
+ if (ptr->_asctime_buf)
+ _free_r (ptr, ptr->_asctime_buf);
+#else
/* atexit stuff */
if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
{
@@ -78,6 +93,7 @@ _reclaim_reent (ptr)
_free_r (ptr, q);
}
}
+#endif
if (ptr->_cvtbuf)
_free_r (ptr, ptr->_cvtbuf);
@@ -113,9 +129,14 @@ _wrapup_reent(struct _reent *ptr)
if (ptr == 0)
ptr = _REENT;
+#ifdef _REENT_SMALL
+ for (p = &ptr->_atexit, n = p->_ind; --n >= 0;)
+ (*p->_fns[n]) ();
+#else
for (p = ptr->_atexit; p; p = p->_next)
for (n = p->_ind; --n >= 0;)
(*p->_fns[n]) ();
+#endif
if (ptr->__cleanup)
(*ptr->__cleanup) (ptr);
}
diff --git a/newlib/libc/reent/reent.tex b/newlib/libc/reent/reent.tex
index 71a0a0dcd..545624ca9 100644
--- a/newlib/libc/reent/reent.tex
+++ b/newlib/libc/reent/reent.tex
@@ -29,6 +29,10 @@ and @var{mode}, and uses the global reentrancy structure. The function
pointer to an instance of the reentrancy structure, @var{file}
and @var{mode}.
+There are two versions of @samp{struct _reent}, a normal one and one
+for small memory systems, controlled by the @code{_REENT_SMALL}
+definition from the (automatically included) @file{<sys/config.h>}.
+
@cindex global reentrancy structure
@findex _impure_ptr
Each function which uses the global reentrancy structure uses the global
diff --git a/newlib/libc/reent/signgam.c b/newlib/libc/reent/signgam.c
index 905386686..d3c17c9e5 100644
--- a/newlib/libc/reent/signgam.c
+++ b/newlib/libc/reent/signgam.c
@@ -10,7 +10,7 @@
int *
__signgam ()
{
- return &_REENT->_new._reent._gamma_signgam;
+ return _REENT_SIGNGAM(_REENT);
}
#endif
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index c6790c491..a42a69206 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -151,20 +151,29 @@ __sinit (s)
s->__cleanup = _cleanup_r; /* conservative */
s->__sdidinit = 1;
- std (s->__sf + 0, __SRD, 0, s);
+ s->__sglue._next = NULL;
+#ifndef _REENT_SMALL
+ s->__sglue._niobs = 3;
+ s->__sglue._iobs = &s->__sf[0];
+#else
+ s->__sglue._niobs = 0;
+ s->__sglue._iobs = NULL;
+ s->_stdin = __sfp(s);
+ s->_stdout = __sfp(s);
+ s->_stderr = __sfp(s);
+#endif
+
+ std (s->_stdin, __SRD, 0, s);
/* on platforms that have true file system I/O, we can verify whether stdout
is an interactive terminal or not. For all other platforms, we will
default to line buffered mode here. */
#ifdef HAVE_FCNTL
- std (s->__sf + 1, __SWR, 1, s);
+ std (s->_stdout, __SWR, 1, s);
#else
- std (s->__sf + 1, __SWR | __SLBF, 1, s);
+ std (s->_stdout, __SWR | __SLBF, 1, s);
#endif
- std (s->__sf + 2, __SWR | __SNBF, 2, s);
+ std (s->_stderr, __SWR | __SNBF, 2, s);
- s->__sglue._next = NULL;
- s->__sglue._niobs = 3;
- s->__sglue._iobs = &s->__sf[0];
}
diff --git a/newlib/libc/stdio/getchar.c b/newlib/libc/stdio/getchar.c
index 475cd138b..345932666 100644
--- a/newlib/libc/stdio/getchar.c
+++ b/newlib/libc/stdio/getchar.c
@@ -74,12 +74,15 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdio.h>
#include <reent.h>
+#include "local.h"
+
#undef getchar
int
_getchar_r (f)
struct _reent *f;
{
+ _REENT_SMALL_CHECK_INIT(_stdin_r (f));
return getc (_stdin_r (f));
}
diff --git a/newlib/libc/stdio/iprintf.c b/newlib/libc/stdio/iprintf.c
index f05404302..5f6a57dc4 100644
--- a/newlib/libc/stdio/iprintf.c
+++ b/newlib/libc/stdio/iprintf.c
@@ -38,6 +38,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
+
#ifndef _REENT_ONLY
#ifdef _HAVE_STDC
@@ -50,6 +52,7 @@ iprintf (const char *fmt,...)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
va_start (ap, fmt);
_stdout_r (_REENT)->_data = _REENT;
ret = vfiprintf (stdout, fmt, ap);
@@ -69,6 +72,7 @@ iprintf (fmt, va_alist)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
va_start (ap);
_stdout_r (_REENT)->_data = _REENT;
ret = vfiprintf (stdout, fmt, ap);
@@ -89,6 +93,7 @@ _iprintf_r (struct _reent *ptr, const char *fmt, ...)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
va_start (ap, fmt);
ret = vfiprintf (_stdout_r (ptr), fmt, ap);
va_end (ap);
@@ -109,6 +114,7 @@ _iprintf_r (data, fmt, va_alist)
struct _reent *ptr = data;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
va_start (ap);
ret = vfiprintf (_stdout_r (ptr), fmt, ap);
va_end (ap);
diff --git a/newlib/libc/stdio/perror.c b/newlib/libc/stdio/perror.c
index abb595ba9..19354c112 100644
--- a/newlib/libc/stdio/perror.c
+++ b/newlib/libc/stdio/perror.c
@@ -49,6 +49,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <stdio.h>
#include <string.h>
+#include "local.h"
+
void
_DEFUN (_perror_r, (ptr, s),
struct _reent *ptr _AND
@@ -56,6 +58,7 @@ _DEFUN (_perror_r, (ptr, s),
{
char *error;
+ _REENT_SMALL_CHECK_INIT(_stderr_r (ptr));
if (s != NULL && *s != '\0')
{
fputs (s, _stderr_r (ptr));
diff --git a/newlib/libc/stdio/printf.c b/newlib/libc/stdio/printf.c
index 81fb8a2cb..e8ec5b475 100644
--- a/newlib/libc/stdio/printf.c
+++ b/newlib/libc/stdio/printf.c
@@ -2,6 +2,8 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
+
#ifdef _HAVE_STDC
#include <stdarg.h>
@@ -12,6 +14,7 @@ _printf_r (struct _reent *ptr, const char *fmt, ...)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
va_start (ap, fmt);
ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
@@ -31,6 +34,7 @@ _printf_r (ptr, fmt, va_alist)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
va_start (ap);
ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
@@ -52,6 +56,7 @@ printf (const char *fmt, ...)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
va_start (ap, fmt);
_stdout_r (_REENT)->_data = _REENT;
ret = vfprintf (_stdout_r (_REENT), fmt, ap);
@@ -71,6 +76,7 @@ printf (fmt, va_alist)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
va_start (ap);
_stdout_r (_REENT)->_data = _REENT;
ret = vfprintf (_stdout_r (_REENT), fmt, ap);
diff --git a/newlib/libc/stdio/putchar.c b/newlib/libc/stdio/putchar.c
index 462393f8a..b725a496d 100644
--- a/newlib/libc/stdio/putchar.c
+++ b/newlib/libc/stdio/putchar.c
@@ -70,6 +70,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdio.h>
+#include "local.h"
+
#undef putchar
int
@@ -77,6 +79,7 @@ _putchar_r (ptr, c)
struct _reent *ptr;
int c;
{
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return __sputc (c, _stdout_r (ptr));
}
diff --git a/newlib/libc/stdio/puts.c b/newlib/libc/stdio/puts.c
index 44f17cc91..e270199d2 100644
--- a/newlib/libc/stdio/puts.c
+++ b/newlib/libc/stdio/puts.c
@@ -63,7 +63,9 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdio.h>
#include <string.h>
+
#include "fvwrite.h"
+#include "local.h"
/*
* Write the given string to stdout, appending a newline.
@@ -86,6 +88,7 @@ _DEFUN (_puts_r, (ptr, s),
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
}
diff --git a/newlib/libc/stdio/scanf.c b/newlib/libc/stdio/scanf.c
index 5dd14fde4..92473ad89 100644
--- a/newlib/libc/stdio/scanf.c
+++ b/newlib/libc/stdio/scanf.c
@@ -41,6 +41,7 @@ scanf (fmt, va_alist)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdin_r (_REENT));
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
@@ -66,6 +67,7 @@ _scanf_r (ptr, fmt, va_alist)
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
diff --git a/newlib/libc/stdio/tmpnam.c b/newlib/libc/stdio/tmpnam.c
index 28b394f10..ec346c878 100644
--- a/newlib/libc/stdio/tmpnam.c
+++ b/newlib/libc/stdio/tmpnam.c
@@ -146,7 +146,8 @@ _DEFUN (_tmpnam_r, (p, s),
if (s == NULL)
{
/* ANSI states we must use an internal static buffer if s is NULL */
- result = p->_emergency;
+ _REENT_CHECK_EMERGENCY(p);
+ result = _REENT_EMERGENCY(p);
}
else
{
diff --git a/newlib/libc/stdio/vprintf.c b/newlib/libc/stdio/vprintf.c
index f913bc097..e82306eaa 100644
--- a/newlib/libc/stdio/vprintf.c
+++ b/newlib/libc/stdio/vprintf.c
@@ -26,12 +26,15 @@
#include <varargs.h>
#endif
+#include "local.h"
+
int
_DEFUN (vprintf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
- return vfprintf (stdout, fmt, ap);
+ _REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
+ return vfprintf (_stdout_r (_REENT), fmt, ap);
}
int
@@ -40,5 +43,6 @@ _DEFUN (_vprintf_r, (ptr, fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
diff --git a/newlib/libc/stdio/vscanf.c b/newlib/libc/stdio/vscanf.c
index 59c63738a..e494aaf60 100644
--- a/newlib/libc/stdio/vscanf.c
+++ b/newlib/libc/stdio/vscanf.c
@@ -38,6 +38,7 @@ _DEFUN (vscanf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
+ _REENT_SMALL_CHECK_INIT(_stdin_r (_REENT));
return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
}
@@ -49,6 +50,7 @@ _DEFUN (_vscanf_r, (ptr, fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
+ _REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}
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 <stdlib.h>
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 <sys/reent.h> */
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);
diff --git a/newlib/libc/string/strtok.c b/newlib/libc/string/strtok.c
index 7f250b456..17228d223 100644
--- a/newlib/libc/string/strtok.c
+++ b/newlib/libc/string/strtok.c
@@ -73,6 +73,7 @@ _DEFUN (strtok, (s, delim),
register char *s _AND
register const char *delim)
{
- return strtok_r (s, delim, &(_REENT->_new._reent._strtok_last));
+ static char *last;
+ return strtok_r (s, delim, &last);
}
#endif
diff --git a/newlib/libc/time/asctime.c b/newlib/libc/time/asctime.c
index 4ad35e806..e4011856d 100644
--- a/newlib/libc/time/asctime.c
+++ b/newlib/libc/time/asctime.c
@@ -57,8 +57,8 @@ char *
_DEFUN (asctime, (tim_p),
_CONST struct tm *tim_p)
{
- char *buf = _REENT->_new._reent._asctime_buf;
- return asctime_r (tim_p, buf);
+ _REENT_CHECK_ASCTIME_BUF(_REENT);
+ return asctime_r (tim_p, _REENT_ASCTIME_BUF(_REENT));
}
#endif
diff --git a/newlib/libc/time/lcltime.c b/newlib/libc/time/lcltime.c
index e54a49d37..1cdc64fd0 100644
--- a/newlib/libc/time/lcltime.c
+++ b/newlib/libc/time/lcltime.c
@@ -51,7 +51,8 @@ struct tm *
_DEFUN (localtime, (tim_p),
_CONST time_t * tim_p)
{
- return localtime_r (tim_p, (struct tm *)&(_REENT->_new._reent._localtime_buf));
+ _REENT_CHECK_TM(_REENT);
+ return localtime_r (tim_p, (struct tm *)_REENT_TM(_REENT));
}
#endif
diff --git a/newlib/libm/math/w_gamma.c b/newlib/libm/math/w_gamma.c
index da0211555..358a493df 100644
--- a/newlib/libm/math/w_gamma.c
+++ b/newlib/libm/math/w_gamma.c
@@ -145,11 +145,11 @@ Neither <<gamma>> nor <<gammaf>> is ANSI C. */
#endif
{
#ifdef _IEEE_LIBM
- return __ieee754_gamma_r(x,&(_REENT->_new._reent._gamma_signgam));
+ return __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
double y;
struct exception exc;
- y = __ieee754_gamma_r(x,&(_REENT->_new._reent._gamma_signgam));
+ y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
diff --git a/newlib/libm/math/w_lgamma.c b/newlib/libm/math/w_lgamma.c
index 1dc63994f..e56e47767 100644
--- a/newlib/libm/math/w_lgamma.c
+++ b/newlib/libm/math/w_lgamma.c
@@ -32,11 +32,11 @@
#endif
{
#ifdef _IEEE_LIBM
- return __ieee754_lgamma_r(x,&(_REENT->_new._reent._gamma_signgam));
+ return __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
double y;
struct exception exc;
- y = __ieee754_lgamma_r(x,&(_REENT->_new._reent._gamma_signgam));
+ y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
diff --git a/newlib/libm/math/wf_gamma.c b/newlib/libm/math/wf_gamma.c
index fbeb38af1..1204f3999 100644
--- a/newlib/libm/math/wf_gamma.c
+++ b/newlib/libm/math/wf_gamma.c
@@ -26,11 +26,11 @@
#endif
{
#ifdef _IEEE_LIBM
- return __ieee754_gammaf_r(x,&(_REENT->_new._reent._gamma_signgam));
+ return __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
float y;
struct exception exc;
- y = __ieee754_gammaf_r(x,&(_REENT->_new._reent._gamma_signgam));
+ y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL
diff --git a/newlib/libm/math/wf_lgamma.c b/newlib/libm/math/wf_lgamma.c
index e1765c4a0..f1bf0c019 100644
--- a/newlib/libm/math/wf_lgamma.c
+++ b/newlib/libm/math/wf_lgamma.c
@@ -26,11 +26,11 @@
#endif
{
#ifdef _IEEE_LIBM
- return __ieee754_lgammaf_r(x,&(_REENT->_new._reent._gamma_signgam));
+ return __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
float y;
struct exception exc;
- y = __ieee754_lgammaf_r(x,&(_REENT->_new._reent._gamma_signgam));
+ y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL