if _REENT_SMALL is defined in config.h. define this for xstormy16.
+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.
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. */
#define MALLOC_ALIGNMENT 8
#define _POINTER_INT short
#define __BUFSIZ__ 16
+#define _REENT_SMALL
#endif
#if INT_MAX == 32767
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;
};
/*
- * 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.
* _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() */
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 */
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
};
/*
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
*
* 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.
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;
struct
{
unsigned int _unused_rand;
- char * _strtok_last;
+ char * _unused_strtok_last;
char _asctime_buf[26];
struct __tm _localtime_buf;
int _gamma_signgam;
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, "", \
{{_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.
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;
}
}
- _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))
{
_free_r (ptr, q);
}
}
+#endif
if (ptr->_cvtbuf)
_free_r (ptr, ptr->_cvtbuf);
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);
}
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
int *
__signgam ()
{
- return &_REENT->_new._reent._gamma_signgam;
+ return _REENT_SIGNGAM(_REENT);
}
#endif
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];
}
#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));
}
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
+
#ifndef _REENT_ONLY
#ifdef _HAVE_STDC
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);
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);
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);
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);
#include <stdio.h>
#include <string.h>
+#include "local.h"
+
void
_DEFUN (_perror_r, (ptr, s),
struct _reent *ptr _AND
{
char *error;
+ _REENT_SMALL_CHECK_INIT(_stderr_r (ptr));
if (s != NULL && *s != '\0')
{
fputs (s, _stderr_r (ptr));
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
+
#ifdef _HAVE_STDC
#include <stdarg.h>
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);
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);
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);
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);
#include <stdio.h>
+#include "local.h"
+
#undef putchar
int
struct _reent *ptr;
int c;
{
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return __sputc (c, _stdout_r (ptr));
}
#include <stdio.h>
#include <string.h>
+
#include "fvwrite.h"
+#include "local.h"
/*
* Write the given string to stdout, appending a newline.
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
}
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdin_r (_REENT));
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
int ret;
va_list ap;
+ _REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
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
{
#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
_CONST char *fmt _AND
va_list ap)
{
+ _REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
return _vfprintf_r (ptr, _stdout_r (ptr), 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);
}
_CONST char *fmt _AND
va_list ap)
{
+ _REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}
{
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)
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;
}
_DEFUN (_drand48_r, (r),
struct _reent *r)
{
+ _REENT_CHECK_RAND48(r);
return _erand48_r(r, __rand48_seed);
}
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)
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)
{
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);
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];
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
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;
_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);
MALLOC_UNLOCK;
#ifdef INTERNAL_NEWLIB
+ _REENT_SMALL_CHECK_INIT(_stderr_r (reent_ptr));
fp = _stderr_r(reent_ptr);
#define fprintf fiprintf
#else
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
{
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;
}
}
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 (;;)
_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];
}
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);
}
void
_DEFUN (srand, (seed), unsigned int seed)
{
- _REENT->_new._reent._rand_next = seed;
+ _REENT_RAND_NEXT(_REENT) = seed;
}
int
/* 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 */
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 */
#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> */
{
static unsigned short sseed[3];
+ _REENT_CHECK_RAND48(r);
sseed[0] = __rand48_seed[0];
sseed[1] = __rand48_seed[1];
sseed[2] = __rand48_seed[2];
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);
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
_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
_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
#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
#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
#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
#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