From 4cc8df68f542efe627df48cb8db365e1da79d0ee Mon Sep 17 00:00:00 2001 From: Matt Novenstern Date: Mon, 22 Apr 2013 17:17:30 -0500 Subject: [PATCH] Use gensyms in struct slot accessors This avoids any name-collisions with special variables. --- src/code/defstruct.lisp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/code/defstruct.lisp b/src/code/defstruct.lisp index 9ff1cb9..a24e9bb 100644 --- a/src/code/defstruct.lisp +++ b/src/code/defstruct.lisp @@ -527,18 +527,16 @@ (defun typed-accessor-definitions (defstruct) ((not inherited) (stuff `(declaim (inline ,name ,@(unless (dsd-read-only slot) `((setf ,name)))))) - ;; FIXME: The arguments in the next two DEFUNs should - ;; be gensyms. (Otherwise e.g. if NEW-VALUE happened to - ;; be the name of a special variable, things could get - ;; weird.) - (stuff `(defun ,name (structure) - (declare (type ,ltype structure)) - (the ,slot-type (elt structure ,index)))) + (with-unique-names (structure) + (stuff `(defun ,name (,structure) + (declare (type ,ltype ,structure)) + (the ,slot-type (elt ,structure ,index))))) (unless (dsd-read-only slot) - (stuff - `(defun (setf ,name) (new-value structure) - (declare (type ,ltype structure) (type ,slot-type new-value)) - (setf (elt structure ,index) new-value))))) + (with-unique-names (new-value structure) + (stuff + `(defun (setf ,name) (,new-value ,structure) + (declare (type ,ltype ,structure) (type ,slot-type ,new-value)) + (setf (elt ,structure ,index) ,new-value)))))) ((not (= (cdr inherited) index)) (style-warn "~@