Skip to content

Commit

Permalink
0.7.12.9:
Browse files Browse the repository at this point in the history
	Fix issue in DEFSTRUCT :NAMED :TYPE structure predicates, which
		had a tendency to signal errors on #() or dotted lists.
  • Loading branch information
csrhodes committed Jan 28, 2003
1 parent 2489ac3 commit 8922e16
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
8 changes: 5 additions & 3 deletions NEWS
Expand Up @@ -1508,12 +1508,14 @@ changes in sbcl-0.7.13 relative to sbcl-0.7.12:
* fixed bug 157: TYPEP, SUBTYPEP, UPGRADED-ARRAY-ELEMENT-TYPE and
UPGRADED-COMPLEX-PART-TYPE now take (ignored, in all situations)
optional environment arguments, as required by ANSI.
* fixed bug 228: primary return values from
FUNCTION-LAMBDA-EXPRESSION are either NIL or suitable for input to
COMPILE or FUNCTION.
* fixed bugs in other functions taking environment objects, allowing
calls with an explicit NIL environment argument to be compiled
without error.
* fixed bug 228: primary return values from
FUNCTION-LAMBDA-EXPRESSION are either NIL or suitable for input to
COMPILE or FUNCTION.
* fixed a bug in DEFSTRUCT: predicates for :NAMED structures with
:TYPE will no longer signal errors on innocuous objects.
* fixed some bugs revealed by Paul Dietz' test suite:
** ARRAY-IN-BOUNDS-P now allows arbitrary integers as arguments,
not just nonnegative fixnums;
Expand Down
13 changes: 11 additions & 2 deletions src/code/defstruct.lisp
Expand Up @@ -426,11 +426,20 @@
(predicate-name (dd-predicate-name defstruct))
(argname (gensym)))
(when (and predicate-name (dd-named defstruct))
(let ((ltype (dd-lisp-type defstruct)))
(let ((ltype (dd-lisp-type defstruct))
(name-index (cdr (car (last (find-name-indices defstruct))))))
`((defun ,predicate-name (,argname)
(and (typep ,argname ',ltype)
,(cond
((subtypep ltype 'list)
`(consp (nthcdr ,name-index (the ,ltype ,argname))))
((subtypep ltype 'vector)
`(= (length (the ,ltype ,argname))
,(dd-length defstruct)))
(t (bug "Uncatered-for lisp type in typed DEFSTRUCT: ~S."
ltype)))
(eq (elt (the ,ltype ,argname)
,(cdr (car (last (find-name-indices defstruct)))))
,name-index)
',name))))))))

;;; Return a list of forms to create a copier function of a typed DEFSTRUCT.
Expand Down
17 changes: 17 additions & 0 deletions tests/defstruct.impure.lisp
Expand Up @@ -459,6 +459,23 @@
(assert (raises-error? (conc-name-nil-slot (make-conc-name-nil))
undefined-function))

;;; The named/typed predicates were a little fragile, in that they
;;; could throw errors on innocuous input:
(defstruct (list-struct (:type list) :named) a-slot)
(assert (list-struct-p (make-list-struct)))
(assert (not (list-struct-p nil)))
(assert (not (list-struct-p 1)))
(defstruct (offset-list-struct (:type list) :named (:initial-offset 1)) a-slot)
(assert (offset-list-struct-p (make-offset-list-struct)))
(assert (not (offset-list-struct-p nil)))
(assert (not (offset-list-struct-p 1)))
(assert (not (offset-list-struct-p '(offset-list-struct))))
(assert (not (offset-list-struct-p '(offset-list-struct . 3))))
(defstruct (vector-struct (:type vector) :named) a-slot)
(assert (vector-struct-p (make-vector-struct)))
(assert (not (vector-struct-p nil)))
(assert (not (vector-struct-p #())))

;;; success
(format t "~&/returning success~%")
(quit :unix-status 104)
2 changes: 1 addition & 1 deletion version.lisp-expr
Expand Up @@ -18,4 +18,4 @@
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)

"0.7.12.8"
"0.7.12.9"

0 comments on commit 8922e16

Please sign in to comment.