mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Fix later-bindings-win logic in with-fluids.
Based on a patch by David Kastrup <dak@gnu.org>. Fixes <http://bugs.gnu.org/13843>. * libguile/fluids.c (scm_i_make_with_fluids): Reverse direction of inner loop that checks for duplicates, to properly handle more than two bindings to the same fluid.
This commit is contained in:
parent
b8d8f8b929
commit
8dd01861a9
2 changed files with 9 additions and 7 deletions
|
@ -319,10 +319,10 @@ scm_i_make_with_fluids (size_t n, SCM *fluids, SCM *vals)
|
||||||
/* Ensure that there are no duplicates in the fluids set -- an N^2 operation,
|
/* Ensure that there are no duplicates in the fluids set -- an N^2 operation,
|
||||||
but N will usually be small, so perhaps that's OK. */
|
but N will usually be small, so perhaps that's OK. */
|
||||||
{
|
{
|
||||||
size_t i, j = n;
|
size_t i, j;
|
||||||
|
|
||||||
while (j--)
|
for (j = n; j--;)
|
||||||
for (i = 0; i < j; i++)
|
for (i = j; i--;)
|
||||||
if (scm_is_eq (fluids[i], fluids[j]))
|
if (scm_is_eq (fluids[i], fluids[j]))
|
||||||
{
|
{
|
||||||
vals[i] = vals[j]; /* later bindings win */
|
vals[i] = vals[j]; /* later bindings win */
|
||||||
|
|
|
@ -85,15 +85,17 @@
|
||||||
|
|
||||||
(pass-if "last value wins"
|
(pass-if "last value wins"
|
||||||
(compile '(with-fluids ((a 1)
|
(compile '(with-fluids ((a 1)
|
||||||
(a 2))
|
(a 2)
|
||||||
(eqv? (fluid-ref a) 2))
|
(a 3))
|
||||||
|
(eqv? (fluid-ref a) 3))
|
||||||
#:env (current-module)))
|
#:env (current-module)))
|
||||||
|
|
||||||
(pass-if "remove the duplicate, not the last binding"
|
(pass-if "remove the duplicate, not the last binding"
|
||||||
(compile '(with-fluids ((a 1)
|
(compile '(with-fluids ((a 1)
|
||||||
(a 2)
|
(a 2)
|
||||||
(b 3))
|
(a 3)
|
||||||
(eqv? (fluid-ref b) 3))
|
(b 4))
|
||||||
|
(eqv? (fluid-ref b) 4))
|
||||||
#:env (current-module)))
|
#:env (current-module)))
|
||||||
|
|
||||||
(pass-if "original value restored"
|
(pass-if "original value restored"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue