From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.bugs Subject: Fix for 1001-local-eval-error-backtrace-segfaults - please review Date: 02 May 2002 13:59:06 +0100 Sender: bug-guile-admin@gnu.org Message-ID: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1020354884 17588 127.0.0.1 (2 May 2002 15:54:44 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 2 May 2002 15:54:44 +0000 (UTC) Cc: "M Johnson" Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 173Iup-0004ZZ-00 for ; Thu, 02 May 2002 17:54:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 173IuC-0006It-00; Thu, 02 May 2002 11:54:04 -0400 Original-Received: from mail.uklinux.net ([80.84.72.21] helo=s1.uklinux.net) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 173IrQ-00067D-00 for ; Thu, 02 May 2002 11:51:12 -0400 Original-Received: from portalet.ossau.uklinux.net (dial-212-159-137-158.access.uk.tiscali.com [212.159.137.158]) by s1.uklinux.net (8.11.6/8.11.6) with ESMTP id g42Fp7K27794; Thu, 2 May 2002 16:51:07 +0100 Original-Received: from laruns.ossau.uklinux.net.ossau.uklinux.net (laruns.ossau.uklinux.net [192.168.1.3]) by portalet.ossau.uklinux.net (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) with ESMTP id g42GpM819544; Thu, 2 May 2002 16:51:22 GMT Original-To: Guile Bugs Original-Lines: 99 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Errors-To: bug-guile-admin@gnu.org X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GUILE, GNU's Ubiquitous Extension Language List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.bugs:212 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.bugs:212 Patch --- /home/neil/Guile/1.6/guile-core/libguile/eval.c.old Thu May 2 12:45:56 2002 +++ /home/neil/Guile/1.6/guile-core/libguile/eval.c Thu May 2 12:46:21 2002 @@ -1417,7 +1417,9 @@ ls = scm_cons (scm_sym_define, z = scm_cons (n = SCM_CAR (x), SCM_UNSPECIFIED)); if (SCM_NNULLP (env)) - SCM_SETCAR (SCM_CAR (env), scm_cons (n, SCM_CAR (SCM_CAR (env)))); + env = scm_cons (scm_cons (scm_cons (n, SCM_CAAR (env)), + SCM_CDAR (env)), + SCM_CDR (env)); break; } case SCM_BIT8(SCM_MAKISYM (0)): Diagnosis If scm_unmemocopy is called (e.g. from scm_backtrace) to unmemoize an expression that has an internal define (i.e. SCM_IM_DEFINE) near the top level of the expression, the code in unmemocopy can modify the expression passed in. The modification is such that an extra copy of the symbol being defined is added on every call, thus: (((args) 4) ...) (((xxx args) 4) ...) (((xxx xxx args) 4) ...) and so on, and this modification eventually causes some other code that looks at the environment to SEGV. The copy in scm_unmemocopy, which looks as though it might be intended to fix this problem, doesn't work because it only copies the environment's top-level pair, and it is the car of the car of the environment that gets modified as just described. Fix notes Basically, avoid modifying the environment in hand by making new list structure instead. This is similar to almost all the other cases in unmemocopy, which use EXTEND_ENV. Fix isn't very elegant, though; is there a nicer way of doing this? Checks 1. make check passes. 2. Rerun of problem scenarios: guile> (define (fnc args) (local-eval '(define xxx 3) (the-environment))) guile> (fnc 4) standard input:1:33: In expression (define xxx 3): standard input:1:33: Bad define placement ABORT: (misc-error) Type "(backtrace)" to get more information or "(debug)" to enter the debugger. guile> (debug) This is the Guile debugger; type "help" for help. There are 3 frames on the stack. Frame 2 at standard input:1:33 (define xxx 3) debug> eval (the-environment) ;value: (((args) 4) #) debug> ba In standard input: 2: 0* [fnc 4] 1: 1 [local-eval (define xxx 3) (((args) 4) #)] 1: 2* (define xxx 3) debug> eval (the-environment) ;value: (((args) 4) #) guile> guile> (load "/home/neil/segf.scm") guile> (assignments (command-line)) : In expression (define a (option-ref options b ...)): : Bad define placement ABORT: (misc-error) Type "(backtrace)" to get more information or "(debug)" to enter the debugger. guile> (backtrace ) Backtrace: In standard input: 2: 0* [assignments ("/usr/local/bin/guile")] In /home/neil/segf.scm: 2: 1 (let ((env #)) (for-each (lambda # #) (quote #))) 3: 2 [for-each # ((a b c) (d e f))] In unknown file: ?: 3* [# (a b c)] In /home/neil/segf.scm: 5: 4* (let ((x #) (y #) (z #)) (local-eval (quasiquote #) env)) 8: 5 [local-eval (define a #) (# #)] In unknown file: ?: 6* (define a (option-ref options b c)) Type "(debug-enable 'backtrace)" if you would like a backtrace automatically if an error occurs in the future. guile> _______________________________________________ Bug-guile mailing list Bug-guile@gnu.org http://mail.gnu.org/mailman/listinfo/bug-guile