From: Harald van Dijk <harald@gigawatt.nl>
To: dash@vger.kernel.org
Cc: Jilles Tjoelker <jilles@stack.nl>
Subject: Re: [PATCH] Improved LINENO support
Date: Thu, 11 Nov 2010 21:32:07 +0059 [thread overview]
Message-ID: <4CDC52DF.1090205@gigawatt.nl> (raw)
In-Reply-To: <20101110220008.GC17871@stack.nl>
On 10/11/10 22:59, Jilles Tjoelker wrote:
> What I was thinking of was adding a lineno field to narg instead of to
> all command types. The lineno variable would then be set by expand.c. I
> think that leads to a smaller patch and it should still give a sensible
> value for almost all errors. Downside is a few more int-to-ascii
> conversions. A few divisions is not that bad relative to other things
> that are done but printf in modern libcs is bloated and slow and might
> slow down things measurably.
I made an attempt at this, but managed to keep the printing in one place
by making LINENO a special variable, which is stored in an int and set
in expandarg. When $LINENO is evaluated, the code checks to see if the
variable is LINENO, and if so, converts the value to a string. This is
one simple pointer comparison in the common case in lookupvar:
if (v == &vlineno && v->text == linenovar)
and avoids sprintf in scripts that don't use LINENO.
> FreeBSD's code subtracts the function's starting line number in the
> parser rather than at run time. I wonder which is best. (FreeBSD
> neglects to save and restore the value, so nested function definitions
> may lead to incorrect line numbers, but that could be fixed.)
I used this approach in my updated patch, by resetting plinno to 0 in
simplecmd, and restoring it after calling command().
> I think this patch will increase dash's code size at least a little,
> which is always a consideration here.
The code size varies little: the current limited LINENO support gives an
executable size of 67680 bytes (default configure settings, no libedit,
gcc 4.5.1, CFLAGS=-Os, strip after compilation), my previous patch gives
67688 bytes, my latest patch gives 67704 bytes. I do not think 24 bytes
should be a problem.
> I can also look at getting this
> into FreeBSD sh.
That would be great.
I will send the updated patch when I can properly test it. Basic testing
shows it works, but more extensive testing fails. As it turns out, this
is unrelated to my changes: current git, unmodified, has a problem:
$ cat test.sh
echo
cat <<_ACEOF
$0 $@
_ACEOF
echo
$ src/dash test.sh wtf
test.sh wtf
�����
$
I had not noticed it with my earlier patch, because I actually did my
testing with modified 0.5.6.1 sources.
Thanks for the comments.
Cheers,
Harald
next prev parent reply other threads:[~2010-11-11 20:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-08 20:33 [PATCH] Improved LINENO support Harald van Dijk
2010-11-10 22:00 ` Jilles Tjoelker
2010-11-11 20:33 ` Harald van Dijk [this message]
2010-11-12 18:17 ` Harald van Dijk
2010-11-12 18:35 ` Eric Blake
2010-11-12 19:08 ` Harald van Dijk
2010-11-12 19:40 ` Harald van Dijk
2010-11-12 21:29 ` Jilles Tjoelker
2010-11-27 16:56 ` Harald van Dijk
2011-03-10 8:10 ` Herbert Xu
2011-03-11 21:56 ` Harald van Dijk
2011-03-15 7:52 ` Herbert Xu
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=4CDC52DF.1090205@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--cc=jilles@stack.nl \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox