From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Marius Vollmer Newsgroups: gmane.lisp.guile.bugs,gmane.lisp.guile.devel Subject: Re: Can't make a stack from a continuation Date: Thu, 23 Dec 2004 16:36:24 +0100 Message-ID: References: <41A23580.6070702@ossau.uklinux.net> <41A635F5.2030303@ossau.uklinux.net> <41C2398D.9040402@ossau.uklinux.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1103816238 2152 80.91.229.6 (23 Dec 2004 15:37:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 23 Dec 2004 15:37:18 +0000 (UTC) Cc: bug-guile@gnu.org, guile-devel@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Dec 23 16:37:10 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ChV1a-00080c-00 for ; Thu, 23 Dec 2004 16:37:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1ChVCB-00077V-Fl for guile-bugs@m.gmane.org; Thu, 23 Dec 2004 10:48:07 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1ChVC7-000771-Db for bug-guile@gnu.org; Thu, 23 Dec 2004 10:48:03 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1ChVC6-00076b-HE for bug-guile@gnu.org; Thu, 23 Dec 2004 10:48:02 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1ChVC6-00076Q-Et; Thu, 23 Dec 2004 10:48:02 -0500 Original-Received: from [129.217.163.1] (helo=mail.dt.e-technik.uni-dortmund.de) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ChV0s-00058u-Sd; Thu, 23 Dec 2004 10:36:27 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.dt.e-technik.uni-dortmund.de (Postfix) with ESMTP id 52C6749651; Thu, 23 Dec 2004 16:36:26 +0100 (CET) Original-Received: from mail.dt.e-technik.uni-dortmund.de ([127.0.0.1]) by localhost (krusty [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 01846-02-6; Thu, 23 Dec 2004 16:36:25 +0100 (CET) Original-Received: from troy.dt.e-technik.uni-dortmund.de (troy.dt.e-technik.uni-dortmund.de [129.217.163.17]) by mail.dt.e-technik.uni-dortmund.de (Postfix) with ESMTP id 3977A48A53; Thu, 23 Dec 2004 16:36:25 +0100 (CET) Original-Received: by troy.dt.e-technik.uni-dortmund.de (Postfix, from userid 520) id C3857B97E; Thu, 23 Dec 2004 16:36:24 +0100 (CET) Original-To: Neil Jerram In-Reply-To: (Marius Vollmer's message of "Thu, 23 Dec 2004 15:24:13 +0100") User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) X-Virus-Scanned: by amavisd-new at dt.e-technik.uni-dortmund.de X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.bugs:2335 gmane.lisp.guile.devel:4569 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4569 Marius Vollmer writes: > Neil Jerram writes: > >> And one more problem ... the same problem exists in CVS head, but a >> similar patch doesn't fix it ... still investigating. > > I'm looking into this as well, now. The fix you did for 1.6 looks > good, although I don't understand it completely yet. I will try to > come up with my own patch to CVS head. Here it is. I have already applied it to CVS. I think a similar scheme can be used for 1.6, too: i.e., move the offset calculation into scm_make_continuation. Neil, do you want to fix 1.6 yourself? Index: continuations.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/continuations.c,v retrieving revision 1.54 diff -u -r1.54 continuations.c --- continuations.c 22 Oct 2004 15:13:12 -0000 1.54 +++ continuations.c 23 Dec 2004 15:26:20 -0000 @@ -134,6 +134,7 @@ #if ! SCM_STACK_GROWS_UP src -= stack_size; #endif + continuation->offset = continuation->stack - src; memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size); #ifdef __ia64__ Index: continuations.h =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/continuations.h,v retrieving revision 1.31 diff -u -r1.31 continuations.h --- continuations.h 25 Jun 2003 18:12:35 -0000 1.31 +++ continuations.h 23 Dec 2004 15:26:20 -0000 @@ -55,8 +55,19 @@ size_t num_stack_items; /* size of the saved stack. */ unsigned long seq; /* dynamic root identifier. */ - /* the most recently created debug frame on the live stack, before - it was saved. */ + /* The offset from the live stack location and this copy. This is + used to adjust pointers from within the copied stack to the stack + itself. + + Thus, when you read a pointer from the copied stack that points + into the live stack, you need to add OFFSET so that it points + into the copy. + */ + scm_t_ptrdiff offset; + + /* The most recently created debug frame on the live stack, before + it was saved. This need to be adjusted with OFFSET, above. + */ struct scm_t_debug_frame *dframe; SCM_STACKITEM stack[1]; /* copied stack of size num_stack_items. */ Index: stacks.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/stacks.c,v retrieving revision 1.80 diff -u -r1.80 stacks.c --- stacks.c 22 Sep 2004 17:41:37 -0000 1.80 +++ stacks.c 23 Dec 2004 15:26:20 -0000 @@ -124,7 +124,8 @@ * is read from a continuation. */ static scm_t_bits -stack_depth (scm_t_debug_frame *dframe, long offset, SCM *id, int *maxp) +stack_depth (scm_t_debug_frame *dframe, scm_t_ptrdiff offset, + SCM *id, int *maxp) { long n; long max_depth = SCM_BACKTRACE_MAXDEPTH; @@ -134,11 +135,12 @@ { if (SCM_EVALFRAMEP (*dframe)) { - scm_t_debug_info * info = RELOC_INFO (dframe->info, offset); - n += (info - dframe->vect) / 2 + 1; + scm_t_debug_info *info = RELOC_INFO (dframe->info, offset); + scm_t_debug_info *vect = RELOC_INFO (dframe->vect, offset); + n += (info - vect) / 2 + 1; /* Data in the apply part of an eval info frame comes from previous stack frame if the scm_t_debug_info vector is overflowed. */ - if ((((info - dframe->vect) & 1) == 0) + if ((((info - vect) & 1) == 0) && SCM_OVERFLOWP (*dframe) && !SCM_UNBNDP (info[1].a.proc)) ++n; @@ -147,7 +149,7 @@ ++n; } if (dframe && SCM_VOIDFRAMEP (*dframe)) - *id = dframe->vect[0].id; + *id = RELOC_INFO(dframe->vect, offset)[0].id; else if (dframe) *maxp = 1; return n; @@ -156,13 +158,15 @@ /* Read debug info from DFRAME into IFRAME. */ static void -read_frame (scm_t_debug_frame *dframe, long offset, scm_t_info_frame *iframe) +read_frame (scm_t_debug_frame *dframe, scm_t_ptrdiff offset, + scm_t_info_frame *iframe) { scm_t_bits flags = SCM_UNPACK (SCM_INUM0); /* UGh. */ if (SCM_EVALFRAMEP (*dframe)) { - scm_t_debug_info * info = RELOC_INFO (dframe->info, offset); - if ((info - dframe->vect) & 1) + scm_t_debug_info *info = RELOC_INFO (dframe->info, offset); + scm_t_debug_info *vect = RELOC_INFO (dframe->vect, offset); + if ((info - vect) & 1) { /* Debug.vect ends with apply info. */ --info; @@ -179,9 +183,10 @@ } else { + scm_t_debug_info *vect = RELOC_INFO (dframe->vect, offset); flags |= SCM_FRAMEF_PROC; - iframe->proc = dframe->vect[0].a.proc; - iframe->args = dframe->vect[0].a.args; + iframe->proc = vect[0].a.proc; + iframe->args = vect[0].a.args; } iframe->flags = flags; } @@ -223,10 +228,11 @@ */ static scm_t_bits -read_frames (scm_t_debug_frame *dframe, long offset, long n, scm_t_info_frame *iframes) +read_frames (scm_t_debug_frame *dframe, scm_t_ptrdiff offset, + long n, scm_t_info_frame *iframes) { scm_t_info_frame *iframe = iframes; - scm_t_debug_info *info; + scm_t_debug_info *info, *vect; static SCM applybody = SCM_UNDEFINED; /* The value of applybody has to be setup after r4rs.scm has executed. */ @@ -248,7 +254,8 @@ --iframe; } info = RELOC_INFO (dframe->info, offset); - if ((info - dframe->vect) & 1) + vect = RELOC_INFO (dframe->vect, offset); + if ((info - vect) & 1) --info; /* Data in the apply part of an eval info frame comes from previous stack frame if the scm_t_debug_info vector is @@ -265,7 +272,7 @@ iframe->flags |= SCM_FRAMEF_OVERFLOW; info -= 2; NEXT_FRAME (iframe, n, quit); - while (info >= dframe->vect) + while (info >= vect) { if (!SCM_UNBNDP (info[1].a.proc)) { @@ -435,12 +442,9 @@ } else if (SCM_CONTINUATIONP (obj)) { - offset = ((SCM_STACKITEM *) ((char *) SCM_CONTREGS (obj) + sizeof (scm_t_contregs)) - - SCM_BASE (obj)); -#if SCM_STACK_GROWS_UP - offset += SCM_CONTINUATION_LENGTH (obj); -#endif - dframe = RELOC_FRAME (SCM_DFRAME (obj), offset); + scm_t_contregs *cont = SCM_CONTREGS (obj); + offset = cont->offset; + dframe = RELOC_FRAME (cont->dframe, offset); } else { @@ -463,7 +467,7 @@ SCM_STACK (stack) -> frames = iframe; /* Translate the current chain of stack frames into debugging information. */ - n = read_frames (RELOC_FRAME (dframe, offset), offset, n, iframe); + n = read_frames (dframe, offset, n, iframe); SCM_STACK (stack) -> length = n; /* Narrow the stack according to the arguments given to scm_make_stack. */ @@ -519,12 +523,9 @@ } else if (SCM_CONTINUATIONP (stack)) { - offset = ((SCM_STACKITEM *) ((char *) SCM_CONTREGS (stack) + sizeof (scm_t_contregs)) - - SCM_BASE (stack)); -#if SCM_STACK_GROWS_UP - offset += SCM_CONTINUATION_LENGTH (stack); -#endif - dframe = RELOC_FRAME (SCM_DFRAME (stack), offset); + scm_t_contregs *cont = SCM_CONTREGS (stack); + offset = cont->offset; + dframe = RELOC_FRAME (cont->dframe, offset); } else if (SCM_STACKP (stack)) { @@ -538,7 +539,7 @@ while (dframe && !SCM_VOIDFRAMEP (*dframe)) dframe = RELOC_FRAME (dframe->prev, offset); if (dframe && SCM_VOIDFRAMEP (*dframe)) - return dframe->vect[0].id; + return RELOC_INFO (dframe->vect, offset)[0].id; return SCM_BOOL_F; } #undef FUNC_NAME @@ -595,12 +596,9 @@ } else if (SCM_CONTINUATIONP (obj)) { - offset = ((SCM_STACKITEM *) ((char *) SCM_CONTREGS (obj) + sizeof (scm_t_contregs)) - - SCM_BASE (obj)); -#if SCM_STACK_GROWS_UP - offset += SCM_CONTINUATION_LENGTH (obj); -#endif - dframe = RELOC_FRAME (SCM_DFRAME (obj), offset); + scm_t_contregs *cont = SCM_CONTREGS (obj); + offset = cont->offset; + dframe = RELOC_FRAME (cont->dframe, offset); } else { _______________________________________________ Bug-guile mailing list Bug-guile@gnu.org http://lists.gnu.org/mailman/listinfo/bug-guile