[gambit-list] segfault on re-defining variable

Marc Feeley feeley at iro.umontreal.ca
Wed Jul 6 18:54:43 EDT 2016


Very strange bug!  It was introduced by commit c69fa0c08e787c1e4ca5defd9772878e7a20b22e and it exists since v4.5.2 .

The bug happens when doing a “define” in a nested REPL and the variable being defined exists in the lexical environment (in your case, in the let* bindings).  So the interpreter gets confused and tries to set a global variable that is in fact a local variable.

I’ve now committed a fix which raises an exception in this case.  The behavior is now:

> (define xs '(1 2 3))
> (let* ((x (car xs)) (xs (cdr xs)) (y (car (xs))) (xs (cdr xs)) (z (car xs))) (+ x y z))
*** ERROR IN (console)@10.43 -- Operator is not a PROCEDURE
((2 3))
1> ,e
xs = '(2 3)
x = 1
1> (define xs '(1 2 3))                                                                   
*** ERROR IN (console)@12.1 -- Ill-placed 'define'
1> (set! xs '(1 2 3))                                                                     
1> ,e
xs = '(1 2 3)
x = 1

So in a nested REPL, a define of a global variable will now only be allowed (with warning), when there is no variable of the same name in the local environment.

Marc

> On Jul 6, 2016, at 4:55 AM, Vijay Mathew <vijay.the.lisper at gmail.com> wrote:
> 
> Reproducing a session at the gambit REPL that led to a segmentation fault:
> 
> $ uname -srmp
> Darwin 14.5.0 x86_64 i386
> 
> $ gsc
> Gambit v4.8.4
> 
>> (define xs '(1 2 3))
>> (let* ((x (car xs)) (xs (cdr xs)) (y (car (xs))) (xs (cdr xs)) (z (car xs))) (+ x y z))
> *** ERROR IN (console)@2.43 -- Operator is not a PROCEDURE
> ((2 3))
> 
> 1> xs
> (2 3)
> 
> 1> (define xs '(1 2 3))
> *** WARNING -- defining global variable: xs
> [1]    11502 segmentation fault  gsc
> 
> Also wondering why the `xs` in the `let*` bindings is referring to the global `xs`.
> 
> Thanks,
> 
> --Vijay
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list