Opened 12 years ago
Closed 11 years ago
#876 closed enhancement (wontfix)
csi segfaults immediately when running this code
Reported by: | Christian Kellermann | Owned by: | felix winkelmann |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | core tools | Version: | 4.7.x |
Keywords: | csi segfault master | Cc: | |
Estimated difficulty: |
Description (last modified by )
As found by uman on IRC the following works when compiled and crashes when interpreted:
(define (product-rec f a next b) (if (> a b) 1 (* (f a) (product-rec f (next a) next b)))) (define (estimate-pi n) (define (num-term k) (+ k (if (even? k) 2 1))) (define (denom-term k) (+ k (if (even? k) 1 2))) (* 4 (product-rec (lambda (k) (/ (num-term k) (denom-term k))) 1 add1 n))) (print (estimate-pi 100000))
This crashes current master, on x64 linux, also 4.7.0 on 32bit x86 OpenBSD
Change History (9)
comment:1 Changed 12 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 12 years ago by
comment:3 Changed 12 years ago by
Owner: | set to felix winkelmann |
---|---|
Status: | new → assigned |
This is a simple stack overflow. Normally this should not be a problem as chicken allocates activation frames on the heap, but the checks that test whether the nursery is full (and whether a minor GC is needed) are not generated in all compiled procedures - specifically: not in continuation procedures. As long as these call normal compiled code, the called procedures will perform the check. Here we have the situation that the called procedure is a "primitive" (the internal, manually written C code for *
), which doesn't do a stack/nursery-check.
Emitting stack-checks in all procedures might be too costly. One option would be to add stack-checks in primitives, or wrap them in a thunk, or something. I have to ponder this.
comment:4 Changed 12 years ago by
Milestone: | 4.8.0 → 4.9.0 |
---|
A patch to fix this (using a specific build-mode), at least in the interpreter, is currently pending. To avoid any last minute problems, I propose to postpone this patch until after the next release.
comment:5 Changed 12 years ago by
Milestone: | 4.9.0 |
---|---|
Priority: | major → minor |
Type: | defect → change request |
comment:6 Changed 12 years ago by
Type: | change request → enhancement |
---|
comment:7 Changed 12 years ago by
Which patch is this? Can we include it now? My memory is a blurr wrt. this issue.
comment:9 Changed 11 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
When I increase the process's ulimit of its stack to unlimited it produces an answer without crashing. The garbage collection output gave me the hint: