summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Browning <rlb@defaultvalue.org>2019-12-08 11:35:37 -0600
committerAndy Wingo <wingo@pobox.com>2020-01-12 22:04:29 +0100
commit2446e7dc298757504858552e86abb62da8d76494 (patch)
tree3b2b9c9883ca5e710650f4f612d5baf009f1bb5c
parent4dd4d286cc679fe05028ebcb9cbc93ca60b7d3fd (diff)
downloadguile-2446e7dc298757504858552e86abb62da8d76494.tar.gz
Respect thread local fluid defaults
Previously (fluid-ref (make-thread-local-fluid #t)) would return #f via scm_fluid_ref because the internal scm_hashq_ref would return #f when the fluid had not been set, and that was interpreted as an actual value for the fluid. Instead, just pass the fluid default as the default for the hash table lookups so that we don't need a second step to determine if the fluid was set. Thanks to Andrew Gierth for tracking down the problem.
-rw-r--r--libguile/fluids.c23
-rw-r--r--test-suite/tests/fluids.test14
2 files changed, 21 insertions, 16 deletions
diff --git a/libguile/fluids.c b/libguile/fluids.c
index f62693338..ebdb48fbc 100644
--- a/libguile/fluids.c
+++ b/libguile/fluids.c
@@ -350,22 +350,17 @@ fluid_ref (scm_t_dynamic_state *dynamic_state, SCM fluid)
entry = scm_cache_lookup (&dynamic_state->cache, fluid);
if (scm_is_eq (SCM_PACK (entry->key), fluid))
- val = SCM_PACK (entry->value);
- else
- {
- if (SCM_I_FLUID_THREAD_LOCAL_P (fluid))
- val = scm_hashq_ref (dynamic_state->thread_local_values, fluid,
- SCM_UNDEFINED);
- else
- val = scm_weak_table_refq (dynamic_state->values, fluid,
- SCM_UNDEFINED);
+ return SCM_PACK (entry->value);
- if (SCM_UNBNDP (val))
- val = SCM_I_FLUID_DEFAULT (fluid);
+ if (SCM_I_FLUID_THREAD_LOCAL_P (fluid))
+ val = scm_hashq_ref (dynamic_state->thread_local_values, fluid,
+ SCM_I_FLUID_DEFAULT (fluid));
+ else
+ val = scm_weak_table_refq (dynamic_state->values, fluid,
+ SCM_I_FLUID_DEFAULT (fluid));
- /* Cache this lookup. */
- fluid_set_x (dynamic_state, fluid, val);
- }
+ /* Cache this lookup. */
+ fluid_set_x (dynamic_state, fluid, val);
return val;
}
diff --git a/test-suite/tests/fluids.test b/test-suite/tests/fluids.test
index a5ca8857e..949d50410 100644
--- a/test-suite/tests/fluids.test
+++ b/test-suite/tests/fluids.test
@@ -49,8 +49,18 @@
(interaction-environment))))
(with-test-prefix "initial fluid values"
- (pass-if "fluid-ref uninitialized fluid is #f"
- (not (fluid-ref a)))
+
+ (pass-if "fluid-ref returns #f for uninitialized fluid"
+ (eq? #f (fluid-ref (make-fluid))))
+
+ (pass-if "fluid-ref returns #f for uninitialized thread local fluid"
+ (eq? #f (fluid-ref (make-thread-local-fluid))))
+
+ (pass-if "fluid-ref returns default"
+ (eq? #t (fluid-ref (make-fluid #t))))
+
+ (pass-if "fluid-ref returns thread local default"
+ (eq? #t (fluid-ref (make-thread-local-fluid #t))))
(pass-if "initial value is inherited from parent thread"
(if (provided? 'threads)