pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: abysmal check-portability speed



(using a different eMail address; hopefully, this time,
the Ccs come through)

On Wed, 25 Sep 2024, tlaronde%kergis.com@localhost wrote:

>Bash man page:

GNU bash is not the measure of all things. I kept a 2.05b
around at the time I wrote this, but I do not generally look
into how other shells do things other than for naming (which
is how mksh has $BASHPID, and zsh’s $EPOCHREALTIME).

I *think* read -N is the same in both, though.

It came first anyway, and then I added -n as logical extension
from -N.

>And just to add fuel to the fire, in the (more common)

You’ll need a switch case anyway. There even already is one.

Perhaps something like this, and once added to TNF /bin/sh,
you can add it in the obvious place.

Index: check-portability.sh
===================================================================
RCS file: /cvsroot/pkgsrc/mk/check/check-portability.sh,v
retrieving revision 1.23
diff -u -p -r1.23 check-portability.sh
--- check-portability.sh	4 Jan 2021 21:10:01 -0000	1.23
+++ check-portability.sh	26 Sep 2024 16:19:21 -0000
@@ -17,6 +17,9 @@ checkdir=`dirname "$0"`
 cs_setprogname "$0"

 : ${SKIP_FILTER:=""}
+# literal newline
+nl='
+'

 # usage: check_shell <fname>
 check_shell() {
@@ -87,13 +90,23 @@ find ./* -type f -print 2>/dev/null \
 			continue
 		fi

-		case "$opsys" in
-		SunOS-5.9)
+		case $opsys:${KSH_VERSION-}:${BASH_VERSION-} in
+		*LEGACY\ KSH*|*MIRBSD\ KSH*)
+			read -rn 128 firstline < "$fname" || continue
+			eval 'firstline=${firstline%%"$nl"*}'
+			;;
+		*PD\ KSH*)
+			read firstline < "$fname" || continue
+			;;
+		*:?*:|*::?*)
+			# ksh93 or GNU bash
+			read -rn 128 firstline < "$fname" || continue
+			;;
+		SunOS-5.9:*)
 			# See also (if you can):
 			# http://sunsolve.sun.com/search/document.do?assetkey=1-1-4250902-1
 			firstline=`sed 1q < "$fname"`
 			;;
-
 		*)	read firstline < "$fname" || continue
 			;;
 		esac


On Thu, 26 Sep 2024, Robert Elz wrote:

>  | What exactly is unclear with that?
>
>read is defined to stop reading at the delimiter, "read up to z bytes"
[…]
>Your doc doesn't say that the delimiter is ignored.

Oh, but it does:

>  |     -n z   Instead of reading till end-of-line, read up to z bytes but
                ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

>And since you're apparently ignoring the delimiter, do you also
>ignore the splitting, it appears (from experimentation) not, but
>the doc doesn't say.

It doesn’t need to say it when it doesn’t change the default.

I normally use it as read -raN-1 (characters) or read -rAN-1
(words). -a obviously ignores IFS but documents that as well.

>I guess the printf's happen fast enough that both of them
>produce output before mksh is ready to read it.

Sure. I just cobbled together a q&d testcase that produced
shorter, split read(2)s on my system. You will be skilled
enough to produce one for yours.

>  | So, I fear that the method you want to implement is impossible.
>
>No, it isn't, the actual read reads 1 byte at a time, stopping

Ah, yes, if you go back to one-byte read(2)s, then of course
it can be implemented.

But not doing thousands of one-byte read(2) syscalls was the
entire *point* of read -N/-n, so… *shrug*.

bye,
//mirabilos
-- 
22:20⎜<asarch> The crazy that persists in his craziness becomes a master
22:21⎜<asarch> And the distance between the craziness and geniality is
only measured by the success 18:35⎜<asarch> "Psychotics are consistently
inconsistent. The essence of sanity is to be inconsistently inconsistent


Home | Main Index | Thread Index | Old Index