tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: ${LINENO} implementation change for /bin/sh
Date: Mon, 8 May 2017 21:15:41 +0200
From: Edgar =?iso-8859-1?B?RnXf?= <ef%math.uni-bonn.de@localhost>
Message-ID: <20170508191541.GZ1038%trav.math.uni-bonn.de@localhost>
| > So, what does everyone think about [local LINENO]?
| If I understand you correctly, if I had a script relying on the old behaviour
| (I don't), I would need to add "local LINENO" to each and every function?
If implemented that way, and if we don't (also) implement the option, then yes.
(for all of your zero functions that actually use LINENO ...)
Note that it is hard to actually write code that relies upon LINENO in
any way, as it tends to be a more or less random value (but not random
enough to use in any way as a source of random numbers). Add a comment
somewhere, and LINENO changes... Its only real use is in diagnostic
output, for humans to read.
As long as we keep the option to number functions from 1, at all, there
are costs to the implementation in making that work, it isn't natural
in any way, but the option itself is almost cost free (just the space for the
string which is its name, an int and a pointer (to that string) in the
table of options, and one extra test in the code executed when a function
starts to be defined ... (and of course, documentation for it in the man page)
so if we can come up with a name for the option, there is no particular
reason not to keep it, regardless of whatever else we decide on this topic
(unless we decide to go the bash way, and simply remove the possibility to
number locally inside a function.)
Note that it is quite unlikely that (if we change this) that anything will
break, anywhere, as the most common shells in actual use in the open
source world (bash and dash) do it the opposite ways (from each other),
and no-one is complaining (or even noticing.) And in the commercial world,
the SysVR4 shell, and ksh, (which might be more or less the same thing) both
do it the "other way" from us.
If I had silently changed this (just deleted numbering in functions from 1
completely, and told no-one) I suspect that the only thing anyone would
have noticed is that the shell got (a very very tiny bit) smaller and faster...
No-one would really care.
kre
ps: note that the extra cost of implementing the "count from 1 inside a
function" is very small in the NetBSD sh in use today, but it gets a bit
bigger with LINENO implemented properly (we have to track line numbers
a lot more accurately, in more places.) Still not going to be noticeable,
but it is there. For this, just being able to do it is the cost, not whether
or not it is actually being used.
Home |
Main Index |
Thread Index |
Old Index