Commit e26644d3 authored by Radford Neal's avatar Radford Neal

fix bug involving ON_SCALAR_STACK

parent d15b1cd0
......@@ -18,6 +18,12 @@
This is done by using the "gcc" clang alias when compiling one
small glue routine (so this must exist).
}}
\subsection{BUG FIXES}{
\itemize{
\item Fixed a bug involving the "scalar stack" that could affect evaluation
of arithmetic operations when deep recursion has occurred.
}}
}
......
......@@ -1554,10 +1554,9 @@ struct R_local_protect {
} while (0)
/* Segment indexes for constant segments. They start at 0 or 1 depending
on whether SGGC_NO_OBJECT_ZERO is defined (1) or not (0). */
/* Segment indexes for constant segments. They start at 1, since
SGGC_NO_OBJECT_ZERO is defined. */
#ifdef SGGC_NO_OBJECT_ZERO
#define R_SGGC_NIL_INDEX 1
#define R_SGGC_ENV_INDEX 2
#define R_SGGC_SYM_INDEX 3
......@@ -1566,19 +1565,9 @@ struct R_local_protect {
#define R_SGGC_CHAR_INDEX 6 /* also uses 7, 8, and 9 */
#define R_SGGC_STRING_INDEX 10 /* also uses 11, 12, and 13 */
#define R_SGGC_LIST1_INDEX 14
#define R_SGGC_SCALAR_STACK_INDEX 15 /* and possibly subsequent segments */
#else
#define R_SGGC_NIL_INDEX 0
#define R_SGGC_ENV_INDEX 1
#define R_SGGC_SYM_INDEX 2
#define R_SGGC_INT_INDEX 3
#define R_SGGC_MISC_INDEX 4
#define R_SGGC_CHAR_INDEX 5 /* also uses 6, 7, and 8 */
#define R_SGGC_STRING_INDEX 9 /* also uses 10, 11, and 12 */
#define R_SGGC_LIST1_INDEX 13
#define R_SGGC_SCALAR_STACK_INDEX 14 /* and possibly subsequent segments */
#endif
#define R_SGGC_PADDING_INDEX 15 /* unused, here so next will be multiple of 4 */
#define R_SGGC_SCALAR_STACK_INDEX 16 /* and possibly subsequent segments,
must be a multiple of 4 */
/* R_EmptyEnv - an empty environment at the root of the environment tree */
......
......@@ -888,12 +888,31 @@ void Rf_constant_init(void)
if (SGGC_SEGMENT_INDEX(p) != R_SGGC_LIST1_INDEX) abort();
/*** Padding, so next will have index that is a multiple of 4. Pads
by just making another version of NULL. */
p = sggc_constant (R_type_to_sggc_type[NILSXP],
R_type_to_sggc_type[NILSXP]+SGGC_N_TYPES,
1, (char *) &R_NilValue_const
#if USE_COMPRESSED_POINTERS
, (char *) sggc_length0, (char *) nilattrib
#elif USE_AUX_FOR_ATTRIB
, (char *) nilattrib
#endif
);
if (SGGC_SEGMENT_INDEX(p) != R_SGGC_PADDING_INDEX) abort();
/*** Scalar stack space. Uses same segments for integers and reals. ***/
/* Assumes SGGC_SCALAR_CHUNKS is a power of two. */
/* Assumes SGGC_SCALAR_CHUNKS is a power of two. Also assumes that
SGGC_SCALAR_STACK_INDEX is a multiple of 4 (which might increase
to a higher power of two if the stack is made bigger), so that
ON_SCALAR_STACK can be done efficiently. */
if (R_type_to_sggc_type[INTSXP] != R_type_to_sggc_type[REALSXP]) abort();
if ((SGGC_SCALAR_CHUNKS & (SGGC_SCALAR_CHUNKS-1)) != 0) abort();
if ((R_SGGC_SCALAR_STACK_INDEX & 3) != 0) abort();
for (int i = 0;
i < SCALAR_STACK_SIZE;
......@@ -911,7 +930,6 @@ void Rf_constant_init(void)
if (i == 0 && SGGC_SEGMENT_INDEX(p)!=R_SGGC_SCALAR_STACK_INDEX) abort();
}
}
......
......@@ -41,7 +41,9 @@
#include <helpers/helpers-app.h>
#ifndef SCALAR_STACK_DEBUG /* can be overridden by compiler option */
#define SCALAR_STACK_DEBUG 0
#endif
attribute_hidden void SrcrefPrompt(const char * prefix, SEXP srcref)
......
......@@ -55,10 +55,24 @@
((SEXP)(((VECTOR_SEXPREC_C*)R_scalar_stack)-(n)))
#endif
/* Test if object is on the scalar stack (set up in const-objs.c). */
/* Test if object is on the scalar stack (set up in const-objs.c). Relies on
segments for scalar stack being consecutive, starting with an index that
is a multiple of 4. */
#if (SCALAR_STACK_SIZE*SGGC_SCALAR_CHUNKS) / SGGC_CHUNKS_IN_SMALL_SEGMENT == 1
#define ON_SCALAR_STACK(x) \
(SGGC_SEGMENT_INDEX(CPTR_FROM_SEXP(x)) == R_SGGC_SCALAR_STACK_INDEX)
#endif
#if (SCALAR_STACK_SIZE*SGGC_SCALAR_CHUNKS) / SGGC_CHUNKS_IN_SMALL_SEGMENT == 2
#define ON_SCALAR_STACK(x) \
(SGGC_SEGMENT_INDEX(CPTR_FROM_SEXP(x)) >> 1 == R_SGGC_SCALAR_STACK_INDEX >> 1)
#endif
#if (SCALAR_STACK_SIZE*SGGC_SCALAR_CHUNKS) / SGGC_CHUNKS_IN_SMALL_SEGMENT == 4
#define ON_SCALAR_STACK(x) \
(SGGC_SEGMENT_INDEX(CPTR_FROM_SEXP(x)) >> 2 == R_SGGC_SCALAR_STACK_INDEX >> 2)
#endif
/* See if a value can be put on the scalar stack, based on variant, and on
whether there is space. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment