[slime-cvs] CVS slime

mkoeppe mkoeppe at common-lisp.net
Sat Aug 19 16:27:28 UTC 2006


Update of /project/slime/cvsroot/slime
In directory clnet:/tmp/cvs-serv8698

Modified Files:
	swank.lisp 
Log Message:
(*nil-surrogate*): New.
(save-presented-object, lookup-presented-object): Distinguish
between a saved NIL and a garbage-collected object that was
replaced by NIL in the weak hash table.


--- /project/slime/cvsroot/slime/swank.lisp	2006/08/19 15:39:48	1.391
+++ /project/slime/cvsroot/slime/swank.lisp	2006/08/19 16:27:28	1.392
@@ -2305,20 +2305,36 @@
 
 (defvar *presentation-counter* 0 "identifier counter")
 
+(defvar *nil-surrogate* (make-symbol "nil-surrogate"))
+
 ;; XXX thread safety?
 (defun save-presented-object (object)
   "Save OBJECT and return the assigned id.
 If OBJECT was saved previously return the old id."
-  (or (gethash object *object-to-presentation-id*)
-      (let ((id (incf *presentation-counter*)))
-        (setf (gethash id *presentation-id-to-object*) object)
-        (setf (gethash object *object-to-presentation-id*) id)
-        id)))
+  (let ((object (if (null object) *nil-surrogate* object)))
+    ;; We store *nil-surrogate* instead of nil, to distinguish it from
+    ;; an object that was garbage collected.
+    (or (gethash object *object-to-presentation-id*)
+        (let ((id (incf *presentation-counter*)))
+          (setf (gethash id *presentation-id-to-object*) object)
+          (setf (gethash object *object-to-presentation-id*) id)
+          id))))
 
 (defun lookup-presented-object (id)
   "Retrieve the object corresponding to ID.
 The secondary value indicates the absence of an entry."
-  (gethash id *presentation-id-to-object*))
+  (multiple-value-bind (object foundp)
+      (gethash id *presentation-id-to-object*)
+    (cond
+      ((eql object *nil-surrogate*)
+       ;; A stored nil object
+       (values nil t))
+      ((null object)
+       ;; Object that was replaced by nil in the weak hash table
+       ;; when the object was garbage collected.
+       (values nil nil))
+      (t 
+       (values object foundp)))))
 
 (defslimefun get-repl-result (id)
   "Get the result of the previous REPL evaluation with ID."




More information about the slime-cvs mailing list