* bug#37066: Using GOOPS #:allocation #:virtual slot option causes stack overflow
@ 2019-08-17 22:42 Jan
2019-08-18 8:08 ` David Pirotte
0 siblings, 1 reply; 3+ messages in thread
From: Jan @ 2019-08-17 22:42 UTC (permalink / raw)
To: 37066
Hi everyone.
I've written the program attached below and it hangs at writing
"after changing (K): ", computer freezes for a moment and then Guile
throws the following message:
allocate_stack failed: Can't allocate memory
Warning: Unwind-only `stack-overflow' exception; skipping pre-unwind
handler.
allocate_stack failed: Can't allocate memory
Warning: Unwind-only `stack-overflow' exception; skipping pre-unwind
handler.
Guile version: 2.9.3
OS: Devuan ASCII GNU/Linux
Architecture: x86_64
Code:
(define-class <temperature> ()
(k #:init-value 0
#:init-keyword #:k
#:accessor kelvin)
(c #:accessor celsius
#:init-keyword #:c
#:allocation #:virtual
#:slot-ref (lambda (o)
(let ((k (slot-ref o 'k)))
(- k 273.15)))
#:slot-set! (lambda (o c)
(slot-set! o 'c c)
(slot-set! o 'k (+ 273.15 c)))))
(define (test-virtual-slots)
(let ((temp1 (make <temperature> #:k 0)))
(display "Absolute zero(K): ")
(display (kelvin temp1))
(newline)
(display "Absolute zero(C): ")
(display (celsius temp1))
(newline)
(display "After changing (K): ")
(slot-set! temp1 'c 0)
(display (kelvin temp1))))
(test-virtual-slots)
I couldn't find any mistake, because I'm a new Guile user, so please
tell me if I'm doing something wrong. Using an example from the manual
(8.5 Illustrating Slot Description) didn't help, because it also throws
a different error, not sure if I hadn't copied everything or if there's
something fundamentally wrong in GOOPS.
The code of the example:
(define-class <my-complex> (<number>)
;; True slots use rectangular coordinates
(r #:init-value 0 #:accessor real-part #:init-keyword #:r)
(i #:init-value 0 #:accessor imag-part #:init-keyword #:i)
;; Virtual slots access do the conversion
(m #:accessor magnitude #:init-keyword #:magn
#:allocation #:virtual
#:slot-ref (lambda (o)
(let ((r (slot-ref o ’r)) (i (slot-ref o ’i)))
(sqrt (+ (* r r) (* i i)))))
#:slot-set! (lambda (o m)
(let ((a (slot-ref o ’a)))
(slot-set! o ’r (* m (cos a)))
(slot-set! o ’i (* m (sin a))))))
(a #:accessor angle #:init-keyword #:angle
#:allocation #:virtual
#:slot-ref (lambda (o)
(atan (slot-ref o ’i) (slot-ref o ’r)))
#:slot-set! (lambda(o a)
(let ((m (slot-ref o ’m)))
(slot-set! o ’r (* m (cos a)))
(slot-set! o ’i (* m (sin a)))))))
(define c (make <my-complex> #:r 12 #:i 20))
(slot-set! c ’a 3)
(display "Real part: ")
(display (real-part c))
(newline)
(display "Angle: ")
(display (angle c))
(newline)
(slot-set! c ’i 10)
(set! (real-part c) 1)
(describe c)
The error:
;;; /home/user/Projects/guile/./goops-bug.scm:44:47: warning: possibly
unbound variable `#{\x2019;i}#'
;;; /home/user/Projects/guile/./goops-bug.scm:47:28: warning: possibly
unbound variable `#{\x2019;a}#'
;;; /home/user/Projects/guile/./goops-bug.scm:48:21: warning: possibly
unbound variable `#{\x2019;r}#'
;;; /home/user/Projects/guile/./goops-bug.scm:49:21: warning: possibly
unbound variable `#{\x2019;i}#'
;;; /home/user/Projects/guile/./goops-bug.scm:53:24: warning: possibly
unbound variable `#{\x2019;i}#'
;;; /home/user/Projects/guile/./goops-bug.scm:53:40: warning: possibly
unbound variable `#{\x2019;r}#'
;;; /home/user/Projects/guile/./goops-bug.scm:55:28: warning: possibly
unbound variable `#{\x2019;m}#'
;;; /home/user/Projects/guile/./goops-bug.scm:56:21: warning: possibly
unbound variable `#{\x2019;r}#'
;;; /home/user/Projects/guile/./goops-bug.scm:57:21: warning: possibly
unbound variable `#{\x2019;i}#'
;;; /home/user/Projects/guile/./goops-bug.scm:60:0: warning: possibly
unbound variable `#{\x2019;a}#'
;;; /home/user/Projects/guile/./goops-bug.scm:67:0: warning: possibly
unbound variable `#{\x2019;i}#'
;;;
compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.1/home/user/Projects/guile/goops-bug.scm.go
Backtrace:
5 (apply-smob/1 #<catch-closure 55db22ad7780>)
In ice-9/boot-9.scm:
702:2 4 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
In ice-9/eval.scm:
619:8 3 (_ #(#(#<directory (guile-user) 55db22b9d750>)))
In ice-9/boot-9.scm:
2296:4 2 (save-module-excursion _)
3816:12 1 (_)
In /home/user/Projects/guile/./goops-bug.scm:
69:0 0 (_)
/home/user/Projects/guile/./goops-bug.scm:69:0: Unbound variable:
#{\x2019;a}#
The line 69 is the last line of the program.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#37066: Using GOOPS #:allocation #:virtual slot option causes stack overflow
2019-08-17 22:42 bug#37066: Using GOOPS #:allocation #:virtual slot option causes stack overflow Jan
@ 2019-08-18 8:08 ` David Pirotte
2019-08-18 21:43 ` Jan
0 siblings, 1 reply; 3+ messages in thread
From: David Pirotte @ 2019-08-18 8:08 UTC (permalink / raw)
To: Jan; +Cc: 37066
[-- Attachment #1: Type: text/plain, Size: 1861 bytes --]
Hello Jan,
> I've written the program attached below and it hangs at writing
> "after changing (K): ", computer freezes for a moment and then Guile
> throws the following message:
> allocate_stack failed: Can't allocate memory
> Warning: Unwind-only `stack-overflow' exception; skipping pre-unwind
> handler.
> ...
This is not goops bug. The problem occurs because you try to set the
value of the virtual slot, something you should never do. Here is a
slightly corrected version of your code:
(define-module (temperature)
#:use-module (oop goops)
#:export (<temperature>
kelvin
celsius))
(define-class <temperature> ()
(k #:accessor kelvin
#:init-keyword #:k
#:init-value 0)
(c #:accessor celsius
#:init-keyword #:c
#:allocation #:virtual
#:slot-ref (lambda (o)
(- (kelvin o) 273.15))
#:slot-set! (lambda (o c)
(set! (kelvin o) (+ 273.15 c)))))
Then, in a repl:
scheme@(guile-user)> (add-to-load-path "/your/temperature/module/path")
scheme@(guile-user)> ,use (oop goops)
scheme@(guile-user)> ,use (oop goops describe)
scheme@(guile-user)> ,use (temperature)
;;; note: source file ... newer than compiled ...
;;; ...
scheme@(guile-user)> (make <temperature>)
$2 = #<<temperature> 5604c4614200>
scheme@(guile-user)> (describe $2)
#<<temperature> 5604c4614200> is an instance of class <temperature>
Slots are:
k = 0
c = -273.15
scheme@(guile-user)> (set! (celsius $2) 0)
$3 = 273.15
scheme@(guile-user)> (describe $2)
#<<temperature> 5604c4614200> is an instance of class <temperature>
Slots are:
k = 273.15
c = 0.0
> ... it also throws a different error ...
I didn't look into this manual example code yet, I wanted to get back
to your own example first ...
David
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#37066: Using GOOPS #:allocation #:virtual slot option causes stack overflow
2019-08-18 8:08 ` David Pirotte
@ 2019-08-18 21:43 ` Jan
0 siblings, 0 replies; 3+ messages in thread
From: Jan @ 2019-08-18 21:43 UTC (permalink / raw)
To: David Pirotte; +Cc: 37066
Sorry, I sent a private mail, hope this one will be in the right
place.
On Sun, 18 Aug 2019 05:08:53 -0300
David Pirotte <david@altosw.be> wrote:
> This is not goops bug. The problem occurs because you try to set the
> value of the virtual slot, something you should never do.
Thank you for explaining, I understand it now.
I don't think eating the whole CPU and RAM and segmentation fault is a
good default behavior though. If this is a thing one should never do,
shouldn't Guile throw an error, warning or whatever?
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-18 21:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-17 22:42 bug#37066: Using GOOPS #:allocation #:virtual slot option causes stack overflow Jan
2019-08-18 8:08 ` David Pirotte
2019-08-18 21:43 ` Jan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).