zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Re: Two more wordcode problems, probably
Date: Fri, 21 Jan 2000 10:09:52 +0100 (MET)	[thread overview]
Message-ID: <200001210909.KAA01281@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Peter Stephenson's message of Thu, 20 Jan 2000 19:57:03 +0000


Peter Stephenson wrote:

> These are presumably both a result of the wordcode changes:
> 
> 1) Bad results using ksh-format autoload:
> 
> % ./zsh -f
> % fpath=(.)
> % cat tst
> tst() {
>   print hello
> }
> % autoload tst
> % tst
> % which tst
> tst () {
> 
> }
> 
> Basically, every single line is messed up, although it doesn't seem to dump
> core (it has more fun without...)

The patch changes stripkshdef(). It seems like I forgot it change it
when I finally added the Patprog caching.

> 2) completion after `cvs add' dumps core.

The array created in ecgetarr() wasn't NULL-terminated. I had tested
this, obviously I was just (un)lucky to get a piece of memory with a
zero after it.

>  Do you want the whole backtrace?
> No? Bad luck.  (Phew.  I sometimes wonder what we've got ourselves into.)

That's why I want to change the execution code to be (mostly)
non-recursive some day (I don't think I'll try this any time soon,
though). That would leave us with only the frames for the shell
functions called (and some at the beginning/end, of course). I'd also
like to get rid of the func_wrapper() wrapper. I was really tempted to 
make the core keep a simple stack-allocated stack of functions
currently active (func_wrapper() only keeps track of the function
names for the $funcstack array).

Bye
 Sven

diff -ru ../z.old/Src/exec.c Src/exec.c
--- ../z.old/Src/exec.c	Fri Jan 21 09:25:08 2000
+++ Src/exec.c	Fri Jan 21 10:03:39 2000
@@ -3281,7 +3281,6 @@
 {
     Wordcode pc = prog->prog;
     wordcode code;
-    Eprog ret;
 
     if (!prog)
 	return NULL;
@@ -3301,16 +3300,33 @@
 	*pc != 1 || strcmp(name, ecrawstr(prog, pc + 1)))
 	return prog;
 
-    ret = (Eprog) zhalloc(sizeof(*prog));
-    ret->len = (WC_FUNCDEF_SKIP(code) - 3) * sizeof(wordcode);
-    ret->prog = pc + 3;
-    ret->strs = (char *) (pc + pc[3]);
-    ret->shf = NULL;
-    ret->pats = prog->pats;
-    ret->npats = prog->npats;
-    ret->heap = 1;
+    {
+	Eprog ret;
+	Wordcode end = pc + WC_FUNCDEF_SKIP(code);
+	int nprg = pc[2] - 4;
+	int npats = pc[3];
+	int plen, len, i;
+	Patprog *pp;
 
-    return ret;
+	pc += 4;
+
+	plen = (end - pc) * sizeof(wordcode);
+	len = plen + (npats * sizeof(Patprog));
+
+	ret = (Eprog) zhalloc(sizeof(*ret));
+	ret->heap = 1;
+	ret->len = len;
+	ret->npats = npats;
+	ret->pats = pp = (Patprog *) zhalloc(len);
+	ret->prog = (Wordcode) (ret->pats + npats);
+	for (i = npats; i--; pp++)
+	    *pp = dummy_patprog1;
+	memcpy(ret->prog, pc, plen);
+	ret->strs = (char *) (ret->prog + nprg);
+	ret->shf = NULL;
+
+	return ret;
+    }
 }
 
 /* check to see if AUTOCD applies here */
diff -ru ../z.old/Src/parse.c Src/parse.c
--- ../z.old/Src/parse.c	Fri Jan 21 09:25:10 2000
+++ Src/parse.c	Fri Jan 21 09:57:56 2000
@@ -2467,10 +2467,11 @@
 {
     char **ret, **rp;
 
-    ret = rp = (char **) zhalloc(num * sizeof(char *));
+    ret = rp = (char **) zhalloc((num + 1) * sizeof(char *));
 
     while (num--)
 	*rp++ = ecgetstr(s, dup);
+    *rp = NULL;
 
     return ret;
 }
diff -ru ../z.old/Src/text.c Src/text.c
--- ../z.old/Src/text.c	Fri Jan 21 09:25:11 2000
+++ Src/text.c	Fri Jan 21 10:00:51 2000
@@ -636,6 +636,7 @@
 			break;
 		    case COND_MOD:
 			taddstr(ecgetstr(state, 0));
+			taddchr(' ');
 			taddlist(state, WC_COND_SKIP(code));
 			stack = 1;
 			break;

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~2000-01-21  9:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-21  9:09 Sven Wischnowsky [this message]
2000-01-21 12:01 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200001210909.KAA01281@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).