From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BD1351F64C for ; Thu, 6 Jun 2024 07:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1717659856; bh=sT/bRlcPx2/fmoRECo6mSthjE0pbHoFQGuAnTWxlWX4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=p0RaC2PrsmCfu+wFuKVAj1TeVQkNat9QIENLRPMDuGQkWqz7nP2juKZ9Sw2nGWGGW sT3o4dbMBA9mfFoYOBzEaxGCC523B+mPZjt0rOrezYgHIHoIIOB+NvzXSY+4U4GlQd TYpqcnnSSeubcJxME0lDEhB27hs48boiYXOM2ky4= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] treewide: use \*STD(IN|OUT|ERR) consistently Date: Thu, 6 Jun 2024 07:44:12 +0000 Message-ID: <20240606074416.3900983-2-e@80x24.org> In-Reply-To: <20240606074416.3900983-1-e@80x24.org> References: <20240606074416.3900983-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Referencing the {IO} slot may not always be populated or work (e.g. with `-t' filetest) if there's no IO handle. Using merely using `\*' is shorter than typing out `{GLOB}', so just use the shortest form consistently. This may fix occasional and difficult-to-reproduce failures from redirecting STDERR in t/imap_searchqp.t --- lib/PublicInbox/Admin.pm | 2 +- lib/PublicInbox/HTTP.pm | 2 +- lib/PublicInbox/LEI.pm | 6 +++--- lib/PublicInbox/TestCommon.pm | 3 +-- lib/PublicInbox/WwwCoderepo.pm | 2 +- script/lei | 2 +- script/public-inbox-clone | 2 +- script/public-inbox-fetch | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index a1b1fc07..a2045b37 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -317,7 +317,7 @@ sub progress_prepare ($;$) { $opt->{1} = $null; # suitable for spawn() redirect } else { $opt->{verbose} ||= 1; - $dst //= *STDERR{GLOB}; + $dst //= \*STDERR; $opt->{-progress} = sub { print $dst '# ', @_ }; } } diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 7162732e..b7728bd2 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -47,7 +47,7 @@ open(my $null_io, '<', '/dev/null') or die "open /dev/null: $!"; { my @n = stat($null_io) or die "stat(/dev/null): $!"; my @i = stat(STDIN) or die "stat(STDIN): $!"; - $null_io = *STDIN{IO} if "@n[0, 1]" eq "@i[0, 1]"; + $null_io = \*STDIN if "@n[0, 1]" eq "@i[0, 1]"; } my $http_date; diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index e9a0de6c..309d290d 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -506,12 +506,12 @@ sub x_it ($$) { sub err ($;@) { my $self = shift; - my $err = $self->{2} // ($self->{pgr} // [])->[2] // *STDERR{GLOB}; + my $err = $self->{2} // ($self->{pgr} // [])->[2] // \*STDERR; my @eor = (substr($_[-1]//'', -1, 1) eq "\n" ? () : ("\n")); print $err @_, @eor and return; my $old_err = delete $self->{2}; $old_err->close if $! == EPIPE && $old_err; - $err = $self->{2} = ($self->{pgr} // [])->[2] // *STDERR{GLOB}; + $err = $self->{2} = ($self->{pgr} // [])->[2] // \*STDERR; print $err @_, @eor or print STDERR @_, @eor; } @@ -1556,7 +1556,7 @@ sub sto_barrier_request { eval { $lei->{sto}->wq_do('schedule_commit', $n) }; } else { my $s = ($wq ? $wq->{lei_sock} : undef) // $lei->{sock}; - my $errfh = $lei->{2} // *STDERR{GLOB}; + my $errfh = $lei->{2} // \*STDERR; my @io = $s ? ($errfh, $s) : ($errfh); eval { $lei->{sto}->wq_io_do('barrier', \@io, 1) }; } diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 3a67ab54..a01949a3 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -281,8 +281,7 @@ sub key2script ($) { 'blib/script/'.$key; } -my @io_mode = ([ *STDIN{IO}, '+<&' ], [ *STDOUT{IO}, '+>&' ], - [ *STDERR{IO}, '+>&' ]); +my @io_mode = ([ \*STDIN, '+<&' ], [ \*STDOUT, '+>&' ], [ \*STDERR, '+>&' ]); sub _prepare_redirects ($) { my ($fhref) = @_; diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 8587f530..8d825284 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -87,7 +87,7 @@ sub new { my @s = stat(STDIN) or die "stat(STDIN): $!"; if ("@l[0, 1]" eq "@s[0, 1]") { my $f = fcntl(STDIN, F_GETFL, 0); - $self->{log_fh} = *STDIN{IO} if $f & O_RDWR; + $self->{log_fh} = \*STDIN if $f & O_RDWR; } $self; } diff --git a/script/lei b/script/lei index 087afc33..a5aef956 100755 --- a/script/lei +++ b/script/lei @@ -37,7 +37,7 @@ my $exec_cmd = sub { my ($fds, $argc, @argv) = @_; my $parent = $$; require POSIX; - my @old = (*STDIN{IO}, *STDOUT{IO}, *STDERR{IO}); + my @old = (\*STDIN, \*STDOUT, \*STDERR); my @rdr; for my $fd (@$fds) { open(my $newfh, '+<&=', $fd) or die "open +<&=$fd: $!"; diff --git a/script/public-inbox-clone b/script/public-inbox-clone index c3e64485..5ecf11ae 100755 --- a/script/public-inbox-clone +++ b/script/public-inbox-clone @@ -54,7 +54,7 @@ require PublicInbox::LeiMirror; $url = PublicInbox::LeiExternal::ext_canonicalize($url); my $lei = bless { env => \%ENV, opt => $opt, cmd => 'public-inbox-clone', - 0 => *STDIN{GLOB}, 2 => *STDERR{GLOB}, + 0 => \*STDIN, 2 => \*STDERR, }, 'PublicInbox::LEI'; open $lei->{1}, '+<&=', 1 or die "dup: $!"; open $lei->{3}, '.' or die "open . $!"; diff --git a/script/public-inbox-fetch b/script/public-inbox-fetch index 6fd15328..1ae31171 100755 --- a/script/public-inbox-fetch +++ b/script/public-inbox-fetch @@ -33,7 +33,7 @@ $SIG{PIPE} = 'IGNORE'; my $lei = bless { env => \%ENV, opt => $opt, cmd => 'public-inbox-fetch', - 0 => *STDIN{GLOB}, 1 => *STDOUT{GLOB}, 2 => *STDERR{GLOB}, + 0 => \*STDIN, 1 => \*STDOUT, 2 => \*STDERR, }, 'PublicInbox::LEI'; PublicInbox::Fetch->do_fetch($lei, '.'); exit(($lei->{child_error} // 0) >> 8);