Re: [PATCH v2 5/9] chainlint.pl: check line numbers in expected output

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

 



On Wed, Aug 21, 2024 at 03:00:05AM -0400, Eric Sunshine wrote:

> > +for my $script (@ARGV) {
> > +       print $expect "# chainlint: $script\n";
> > +
> > +       open(my $expect_in, '<', "chainlint/$script.expect")
> > +               or die "unable to open chainlint/$script.expect: $!";
> > +       while (<$expect_in>) {
> > +               s/^\d+/$& + $offset/e;
> > +               print $expect $_;
> > +       }
> > +
> > +       open(my $test_in, '<', "chainlint/$script.test")
> > +               or die "unable to open chainlint/$script.test: $!";
> > +       while (<$test_in>) {
> > +               /^# LINT: / and next;
> > +               print $tests $_;
> > +               $offset++;
> > +       }
> > +}
> 
> I'm surprised that we're not closing the two file handles opened on
> each iteration of this loop. Is that intentional? Or am I forgetting
> my Perl and they are somehow getting closed anyhow (for instance, by
> the <...> operator hitting EOF)?

They're scoped to the loop with "my", so they'll both be closed for each
iteration of the outer loop when the handles go out of scope.

You can verify with something like:

  touch foo bar baz
  strace -e openat,write,close \
  perl -e '
	for my $script (@ARGV) {
		syswrite(STDOUT, "opening $script");
		open(my $in, "<", $script);
		syswrite(STDOUT, "finished $script");
	}
  ' foo bar baz >/dev/null

which should show:

  write(1, "opening foo", 11)             = 11
  openat(AT_FDCWD, "foo", O_RDONLY|O_CLOEXEC) = 3
  write(1, "finished foo", 12)            = 12
  close(3)                                = 0
  write(1, "opening bar", 11)             = 11
  [...etc...]

-Peff




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux