[PATCH] Include a bug from Nix we dropped on the floor

Aidan Kehoe kehoea at parhasard.net
Fri Nov 24 08:48:27 EST 2006


Was looking through Gmane, and came across this. Sorry about the delay, Nix. 
See the discussion here: http://thread.gmane.org/gmane.lisp.emacs-cl/128 for
more info.

lisp/ChangeLog addition:

2004-06-28  Nix  <nix at esperi.org.uk>

	* cmdloop.el (truncate-command-history-for-gc): Delay
        execution of all things that look up variable bindings,
        via `enqueue-eval-event'.


XEmacs Trunk source patch:
Diff command:   cvs -q diff -u
Files affected: lisp/cmdloop.el
===================================================================
RCS

Index: lisp/cmdloop.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/cmdloop.el,v
retrieving revision 1.22
diff -u -r1.22 cmdloop.el
--- lisp/cmdloop.el	2006/06/25 13:58:03	1.22
+++ lisp/cmdloop.el	2006/11/24 13:38:29
@@ -183,11 +183,26 @@
 
 
 (defun truncate-command-history-for-gc ()
-  (let ((tail (nthcdr 30 command-history)))
-    (if tail (setcdr tail nil)))
-  (let ((tail (nthcdr 30 values)))
-    (if tail (setcdr tail nil)))
-  )
+  ;; We should try to avoid accessing any bindings to speak of in this
+  ;; function; as this hook is called asynchronously, the search for
+  ;; those bindings might search local bindings from essentially
+  ;; arbitrary functions. We force the body of the function to run at
+  ;; command-loop level, where the danger of local bindings is much
+  ;; reduced; the code can still do its job because the command history
+  ;; and values list will not grow before then anyway.
+  ;;
+  ;; Nothing is done in batch mode, both because it is a waste of time
+  ;; (there is no command loop!) and because this any GCs during dumping
+  ;; will invoke this code, and if it were to enqueue an eval event,
+  ;; the portable dumper would try to dump it and fail.
+  (if (not (noninteractive))
+      (enqueue-eval-event
+       (lambda (arg)
+         (let ((tail (nthcdr 30 command-history)))
+           (if tail (setcdr tail nil)))
+         (let ((tail (nthcdr 30 values)))
+           (if tail (setcdr tail nil))))
+       nil)))
 
 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc)
 

-- 
Santa Maradona, priez pour moi!



More information about the XEmacs-Patches mailing list