logo       

Re: Seeing memory corruption, GC moves my objects around: msg#00343

lisp.cmucl.devel

Subject: Re: Seeing memory corruption, GC moves my objects around

gerd.moellmann@xxxxxxxxxxx (Gerd Moellmann) writes:

> For non-raw slots, setting a slot is a (SETF INSTANCE-REF) with the
> index of the slot, which I think should always be valid, plus a normal
> type check. Storing any boxed object in such a slot cannot possibly
> confuse GC, even if the type check is not done for some reason.
> Storing something unboxed could of course a problem, if that is
> possible, dunno, because GC will expect something boxed there.

It can't confuse GC, but it can confuse the system to the point of
confusing GC later.

(defstruct foo (s " " :type (string 10)))

(defstruct (bar (:include foo (s " " :type (simple-string 10)))))

(defun baz (x)
(setf (schar (bar-s x) 9) #\Space))

(compile 'baz)

(defvar *bar* (make-bar))

(setf (foo-s *bar*) (make-array 10 :element-type 'character :fill-pointer 10))

(foo-s *bar*)

(baz *bar*) ; instant heap corruption!

(foo-s *bar*) -> usually some kind of weird error.

Cheers,

Christophe
--
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise