bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] close/stdin bug


From: Aharon Robbins
Subject: Re: [bug-gawk] close/stdin bug
Date: Wed, 05 Mar 2014 22:58:26 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Hello.

I cannot reproduce what you claim.  With one version of mawk I got a core
dump!  Here is what I tried:

$ cat x.in
a
b
$ cat x.awk 
BEGIN {
        n = (getline < "/dev/stdin")
        close("/dev/stdin")
        printf("n = %d, $0 = %s\n", n, $0)
        n = (getline < "/dev/stdin")
        close("/dev/stdin")
        printf("n = %d, $0 = %s\n", n, $0)
}
$ mawk -Wversion
mawk 1.3.4 20121129
Copyright 2012, Thomas E. Dickey
Copyright 1996, Michael D. Brennan

internal regex
compiled limits:
max NF             32767
sprintf buffer      2040

$ for i in mawk nawk gawk
> do echo ========== $i
> $i -f x.awk < x.in
> done
========== mawk
n = 1, $0 = a
n = 0, $0 = a
========== nawk
n = 1, $0 = a
n = -1, $0 = a
========== gawk
n = 1, $0 = a
n = 0, $0 = a

So, I think I don't need to fix anything, gawk is consistent with
the latest released mawk and with Brian Kernighan's awk.

Thanks,

Arnold

> Date: Tue, 4 Mar 2014 00:26:20 -0800 (PST)
> From: "\"Chad Kline\"" <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] close/stdin bug
>
> Hi, I am coming from the awk expert irc channel - can't remember the
> details, but I was told this is worth reporting:
> $ awk 'BEGIN { getline < "/dev/stdin"; close("/dev/stdin"); getline < 
> "/dev/stdin"; print }'
> Now, mawk 1.3.4 will request a line, perform the close function, and
> then request another line.  gawk 4.1.0 will request a line, and then
> shut down stdin permanently.
>
> INHO, mawk has the correct behavior, as one would expect.  But gawk
> seems to open stdin once, and then if a close function is called with
> it, it cannot be opened again for the rest of the program.  There are
> several logical and practical reasons why I feel this is a bug:
>
> 1. stdin, for practical purposes, and common sense purposes, should
> function like any other file.  It should be able to "suffer" a close()
> function, and be read from again just like any other file.
>
> 2. this current behavior of gawk forces every single "open/read/close"
> file-type function to perform special checks on a file to make sure
> it's not the "evil stdin" that may shut down the entire program - and
> this is a needless and wasteful burden to impose on all open/read/close
> file functions.
>
> 3. this current behavior is not compatible with mawk, which seems
> to have the natural and correct behavior, and the wrong thing to do
> would be to expect mawk to "kill common sense, apparently correct,
> and practical usage".
> 
> For these reasons, I request that gawk be "fixed" to correct the
> aforementioned defects.  Thanks :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]