aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2019-02-12 16:33:23 -0500
committerStefan Monnier2019-02-12 16:33:23 -0500
commit3f4b8e9a299f88a8ea11c0ea6a281a34852e541a (patch)
treeb8e7c1a11db4e76a9ec156b84a41b11288a763c8
parentb384996e86cb5172dd0d5283f178de7f2654a2f4 (diff)
downloademacs-3f4b8e9a299f88a8ea11c0ea6a281a34852e541a.tar.gz
emacs-3f4b8e9a299f88a8ea11c0ea6a281a34852e541a.zip
* src/data.c (Fmake_local_variable): Fix bug#34318
Revert part of ed962f2b8a. * test/src/data-tests.el (data-tests-make-local-forwarded-var): Add corresponding test.
-rw-r--r--src/data.c10
-rw-r--r--test/src/data-tests.el18
2 files changed, 28 insertions, 0 deletions
diff --git a/src/data.c b/src/data.c
index 571114802a1..ed6dedbe243 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1954,6 +1954,16 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */)
1954 (current_buffer, 1954 (current_buffer,
1955 Fcons (Fcons (variable, XCDR (blv->defcell)), 1955 Fcons (Fcons (variable, XCDR (blv->defcell)),
1956 BVAR (current_buffer, local_var_alist))); 1956 BVAR (current_buffer, local_var_alist)));
1957
1958 /* If the symbol forwards into a C variable, then load the binding
1959 for this buffer now, to preserve the invariant that forwarded
1960 variables must always hold the value corresponding to the
1961 current buffer (they are swapped eagerly).
1962 Otherwise, if C code modifies the variable before we load the
1963 binding in, then that new value would clobber the default binding
1964 the next time we unload it. See bug#34318. */
1965 if (blv->fwd)
1966 swap_in_symval_forwarding (sym, blv);
1957 } 1967 }
1958 1968
1959 return variable; 1969 return variable;
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 0069ee84fe1..f3b4262de4b 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -508,4 +508,22 @@ comparing the subr with a much slower lisp implementation."
508 (bound-and-true-p data-tests-foo2) 508 (bound-and-true-p data-tests-foo2)
509 (bound-and-true-p data-tests-foo3))))))) 509 (bound-and-true-p data-tests-foo3)))))))
510 510
511(ert-deftest data-tests-make-local-forwarded-var () ;bug#34318
512 ;; Boy, this bug is tricky to trigger. You need to:
513 ;; - call make-local-variable on a forwarded var (i.e. one that
514 ;; has a corresponding C var linked via DEFVAR_(LISP|INT|BOOL))
515 ;; - cause the C code to modify this variable from the C side of the
516 ;; forwarding, but this needs to happen before the var is accessed
517 ;; from the Lisp side and before we switch to another buffer.
518 ;; The trigger in bug#34318 doesn't exist any more because the C code has
519 ;; changes. Instead I found the trigger below.
520 (with-temp-buffer
521 (setq last-coding-system-used 'bug34318)
522 (make-local-variable 'last-coding-system-used)
523 ;; This should set last-coding-system-used to `no-conversion'.
524 (decode-coding-string "hello" nil)
525 (should (equal (list last-coding-system-used
526 (default-value 'last-coding-system-used))
527 '(no-conversion bug34318)))))
528
511;;; data-tests.el ends here 529;;; data-tests.el ends here