277
278
(y #:accessor y #:init-value 456)
278
279
(z #:accessor z #:init-value 789))
279
280
(current-module))
280
(eval '(and (= (y foo) 456) (= (z foo) 789)) (current-module))))
281
(eval '(and (= (y foo) 456) (= (z foo) 789)) (current-module)))
283
(pass-if "changing class"
284
(let* ((c1 (class () (the-slot #:init-keyword #:value)))
285
(c2 (class () (the-slot #:init-keyword #:value)
286
(the-other-slot #:init-value 888)))
287
(o1 (make c1 #:value 777)))
290
(equal? (slot-ref o1 'the-slot) 777)
291
(let ((o2 (change-class o1 c2)))
295
(equal? (slot-ref o2 'the-slot) 777))))))
297
(pass-if "`hell' in `goops.c' grows as expected"
298
;; This snippet yielded a segfault prior to the 2008-08-19 `goops.c'
299
;; fix (i.e., Guile 1.8.5 and earlier). The root of the problem was
300
;; that `go_to_hell ()' would not reallocate enough room for the `hell'
301
;; array, leading to out-of-bounds accesses.
303
(let* ((parent-class (class ()
304
#:name '<class-that-will-be-redefined>))
306
(unfold (lambda (i) (>= i 20))
308
(make-class (list parent-class)
309
'((the-slot #:init-value #:value)
311
#:name (string->symbol
312
(string-append "<foo-to-redefine-"
320
(make class #:value 777))
323
(define-method (change-class (foo parent-class)
325
;; Called by `scm_change_object_class ()', via `purgatory ()'.
328
(let ((class (car classes))
329
(object (car objects)))
330
(set! classes (cdr classes))
331
(set! objects (cdr objects))
333
;; Redefine the class so that its instances are eventually
334
;; passed to `scm_change_object_class ()'. This leads to
335
;; nested `scm_change_object_class ()' calls, which increases
336
;; the size of HELL and increments N_HELL.
337
(class-redefinition class
338
(make-class '() (class-slots class)
339
#:name (class-name class)))
341
;; Use `slot-ref' to trigger the `scm_change_object_class ()'
342
;; and `go_to_hell ()' calls.
343
(slot-ref object 'the-slot)
348
;; Initiate the whole `change-class' chain.
349
(let* ((class (car classes))
350
(object (change-class (car objects) class)))
351
(is-a? object class)))))
282
353
(with-test-prefix "object comparison"
283
354
(pass-if "default method"