user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] idx_stack: avoid conditional hash assignment weirdness
Date: Mon,  1 Nov 2021 19:06:08 +0000	[thread overview]
Message-ID: <20211101190609.32278-2-e@80x24.org> (raw)
In-Reply-To: <20211101190609.32278-1-e@80x24.org>

I've been seeing the following error on occasion during "make check-run":
$PWD/t/data-gen/reindex-time-range.v1-master index failed: Modification of a read-only value attempted at $DIR/lib/PublicInbox/SearchIdx.pm line 899, <$r> line 1.

Perhaps this fixes it.  In any case, a construct of:

	 $h->{k} //= do { $h->{x} = ...; $val };

seems wrong and may cause Perl to error out depending on how
hashes are randomized.
---
 lib/PublicInbox/IdxStack.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/IdxStack.pm b/lib/PublicInbox/IdxStack.pm
index d5123006..54d480bd 100644
--- a/lib/PublicInbox/IdxStack.pm
+++ b/lib/PublicInbox/IdxStack.pm
@@ -20,12 +20,12 @@ sub new {
 sub push_rec {
 	my ($self, $file_char, $at, $ct, $blob_oid, $cmt_oid) = @_;
 	my $rec = pack(PACK_FMT, $file_char, $at, $ct, $blob_oid, $cmt_oid);
-	$self->{unpack_fmt} //= do {
+	$self->{unpack_fmt} // do {
 		my $len = length($cmt_oid);
 		my $fmt = PACK_FMT;
 		$fmt =~ s/H\*/H$len/g;
 		$self->{rec_size} = length($rec);
-		$fmt;
+		$self->{unpack_fmt} = $fmt;
 	};
 	print { $self->{wr} } $rec or die "print: $!";
 	$self->{tot_size} += length($rec);

  reply	other threads:[~2021-11-01 19:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 19:06 [PATCH 0/2] avoid problematic conditional hash assignments Eric Wong
2021-11-01 19:06 ` Eric Wong [this message]
2021-11-01 19:06 ` [PATCH 2/2] treewide: kill problematic "$h->{k} //= do {" assignments Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101190609.32278-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 1/2] idx_stack: avoid conditional hash assignment weirdness' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).