Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDYdi-00007V-JU for pgsql-committers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:50:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDYdh-0008QR-Ed for pgsql-committers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:50:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDYdg-0008QB-H2 for pgsql-committers@lists.postgresql.org; Mon, 18 Jul 2022 21:50:53 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDYdc-0001Mm-6Q for pgsql-committers@lists.postgresql.org; Mon, 18 Jul 2022 21:50:52 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4EE4E3200922; Mon, 18 Jul 2022 17:50:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 18 Jul 2022 17:50:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1658181043; x=1658267443; bh=Au86Jb5WgY 2tDEhyChBdwmt1RAPgppO2JdKmO6U/sYk=; b=PTe+zsL7Xx2AzpnC8oJ787qd5o IfU4W1N6iwcXYV2MfBdyul5Kiyaj7/4EJiORwCit2GSj5zpOiN+1/0JcBfpbxQ4a NKuCx/Sa3TSjVBfMp/fPZ1dT7XA9B1+V9ZDsdkhc3q0KujKWcJ9GPTXz+bMC5ikc wt+4aPouucWWFs8eGpkd9b2Z+u7iLRHYNDI3JBJZ1288A9GMmK00WMb3xlAJyRni vO0BkBi8SmPbdU0Q2An9gcybLBW9XjHc+YWz4A8qSvO/n6dfDsDKEmHlmHBft9l4 PuP/iKXL/Xg6b+TsTTnExtqKcSNQPQMguOap2o0EYz5dkbashsAX7UM0Azlg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1658181043; x=1658267443; bh=Au86Jb5WgY2tDEhyChBdwmt1RAPg ppO2JdKmO6U/sYk=; b=yM8v5XfjBxjSEmRwUsl/ITO72QSMRb6GN80rckC5RGiH kk3iDxfqlwz/X5rxodbHEnzGCW23eBMWS5PXmArfHvPPKzTsTFsXsWCYx2FX81KK cm1fxNQ+HIt+6PvXNJMM1YgjZZ2dE3uU3ODa/c8Rmbbi/H6DHRg26nzvZscjbz87 l+tTN7ARNYD3kExwumCTaWTkY4Zg9loxtuwR4+1hIvRI0p5Ba9Myt1TwW9fTLRMc 77W7slHtU54DwJ/5wyNwwROt6udccGEJ4bUNf5Ggub/TA7yIpJdLrqpJxdJGAgI+ jVm1hzCj7Wzi0+XcSJAPd3vr9tsvjJR5/Bg0BopLmQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudekledgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetvedu ieettddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Jul 2022 17:50:43 -0400 (EDT) Date: Mon, 18 Jul 2022 14:50:42 -0700 From: Andres Freund To: Tom Lane Cc: pgsql-committers@lists.postgresql.org, Andrew Dunstan Subject: Re: pgsql: ecpg: Output dir, source dir, stamp file argument for preproc/*. Message-ID: <20220718215042.sl3hivoupdb7lkwv@awork3.anarazel.de> References: <20220718211408.o2uyu5kvud56ihlj@awork3.anarazel.de> <822625.1658179641@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <822625.1658179641@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-07-18 17:27:21 -0400, Tom Lane wrote: > Andres Freund writes: > > Jul 18 16:48:25 ./src/interfaces/ecpg/preproc/parse.pl: Bareword file handle opened at line 30, column 1. See pages 202,204 of PBP. ([InputOutput::ProhibitBarewordFileHandles] Severity: 5) > > Jul 18 16:48:25 ./src/interfaces/ecpg/preproc/parse.pl: Bareword file handle opened at line 31, column 1. See pages 202,204 of PBP. ([InputOutput::ProhibitBarewordFileHandles] Severity: 5) > > > afaict that's bogus. It's unnecessary that the code uses "our" instead of > > "my", but there's no bareword there and replacing our with my fixes that > > complaint. > > Ah, I think I've got it. Per "man perlfunc": > > "our" has the same scoping rules as "my" or "state", meaning that > it is only valid within a lexical scope. Unlike "my" and "state", > which both declare new (lexical) variables, "our" only creates an > alias to an existing variable: a package variable of the same name. > Since there's not actually any such package variable, the net effect is > that the first argument of open() is an undeclared name. I can more or > less see why perl might treat that the same as a bareword, though I > definitely agree that this error message is more confusing than helpful. That'd make some sense - but it doesn't look like perlcritic is digging that deep. Even if I make sure that the our references an existing variable in package scope, perlcritic's complaint is the the same. I suspect perlcritic simply has an exception for 'my' somewhere... [digs a little] Yep: /usr/share/perl5/Perl/Critic/Policy/InputOutput/ProhibitBarewordFileHandles.pm if ( $first_token->isa('PPI::Token::Word') ) { if ( ($first_token ne 'my') && ($first_token !~ m/^STD(?:IN|OUT|ERR)$/xms ) ) { return $self->violation( $DESC, $EXPL, $elem ); } I'll push the obvious fix in a bit. I find the references to some book, with an abbreviation that I certainly didn't know and which seems ambiguous even in perl context, not helpful. --verbose 10 makes the above warning instead be: Bareword file handle opened at line 31, column 1. InputOutput::ProhibitBarewordFileHandles (Severity: 5) Using bareword symbols to refer to file handles is particularly evil because they are global, and you have no idea if that symbol already points to some other file handle. You can mitigate some of that risk by `local'izing the symbol first, but that's pretty ugly. Since Perl 5.6, you can use an undefined scalar variable as a lexical reference to an anonymous filehandle. Alternatively, see the IO::Handle or IO::File or FileHandle modules for an object-oriented approach. open FH, '<', $some_file; #not ok open my $fh, '<', $some_file; #ok my $fh = IO::File->new($some_file); #ok There are three exceptions: STDIN, STDOUT and STDERR. These three standard filehandles are always package variables. Perhaps we should tweak the default format in our perlcriticrc? Greetings, Andres Freund