From f72fa1121f2571aba9f16f95d58d8e915965d765 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 8 Sep 2015 06:43:11 -0700 Subject: Random states of type random-state, not *random-state*. * lib.c (compat_fixup): Call rand_compat_fixup. * rand.c (random_state_var_s): New global symbol variable. (rand_compat_fixup): New static function. (rand_init): Initialize random_state_var_s by intering the earmuffed symbol *random-state*. Initialize random_state_s to the non-earmuffed symbol random-state. * rand.h (random_state_var_s): Declared. (random_state): Macro updated to look up the special variable using random_state_var_s, rather than random_state_s. (rand_compat_fixup): Declared. --- lib.c | 1 + rand.c | 17 ++++++++++++++--- rand.h | 5 +++-- txr.1 | 8 ++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib.c b/lib.c index d96ab8b2..84988206 100644 --- a/lib.c +++ b/lib.c @@ -7762,6 +7762,7 @@ int compat_fixup(int compat_ver) } eval_compat_fixup(compat_ver); + rand_compat_fixup(compat_ver); return 0; } diff --git a/rand.c b/rand.c index b6ccdda2..b127dae0 100644 --- a/rand.c +++ b/rand.c @@ -44,6 +44,7 @@ #include "signal.h" #include "unwind.h" #include "arith.h" +#include "txr.h" #include "rand.h" #include "eval.h" @@ -62,7 +63,7 @@ struct rand_state { unsigned cur; }; -val random_state_s; +val random_state_s, random_state_var_s; static struct cobj_ops random_state_ops = cobj_ops_init(eq, cobj_print_op, @@ -261,8 +262,18 @@ val rnd(val modulus, val state) return random(state, modulus); } +void rand_compat_fixup(int compat_ver) +{ + if (compat_ver <= 114) { + loc l = lookup_var_l(nil, random_state_var_s); + random_state_s = random_state_var_s; + set(l, make_random_state(num_fast(42))); + } +} + void rand_init(void) { - random_state_s = intern(lit("*random-state*"), user_package); - reg_var(random_state_s, make_random_state(num_fast(42))); + random_state_var_s = intern(lit("*random-state*"), user_package); + random_state_s = intern(lit("random-state"), user_package); + reg_var(random_state_var_s, make_random_state(num_fast(42))); } diff --git a/rand.h b/rand.h index 23c4167a..d68be1f9 100644 --- a/rand.h +++ b/rand.h @@ -24,11 +24,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define random_state (deref(lookup_var_l(nil, random_state_s))) -extern val random_state_s; +#define random_state (deref(lookup_var_l(nil, random_state_var_s))) +extern val random_state_s, random_state_var_s; val make_random_state(val seed); val random_state_p(val obj); val random_fixnum(val state); val random(val state, val modulus); val rnd(val modulus, val state); +void rand_compat_fixup(int compat_ver); void rand_init(void); diff --git a/txr.1 b/txr.1 index 2192b870..bac8d8e6 100644 --- a/txr.1 +++ b/txr.1 @@ -33297,6 +33297,7 @@ selects the behaviors described below for version 105, but not those for 102. .cble The new format omits the program name prefix and parentheses. + Also, the .code kill function returned an integer, obtained from the return @@ -33304,6 +33305,13 @@ value of the underlying C function, rather than converting that value to a boolean. The old behavior was not documented, and 114 compatibility restores it. +Lastly, prior to 115, random state objects were of type +.code *random-state* +(the same symbol as the special variable name) +rather than of type +.codn random-state . +This is a bug whose behavior is simulated by 114 compatibility. + .IP 113 Version 113 is the last version in which the .codn stat , -- cgit v1.2.3