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] over*: avoid defined-or hash assignments with side-effects
Date: Tue, 10 Oct 2023 10:07:56 +0000	[thread overview]
Message-ID: <20231010100756.6268-1-e@80x24.org> (raw)

These may've been causing strange errors[1] in t/imapd.t from
the -watch daemon, such as:

	Cannot copy to HASH in scalar assignment ../PublicInbox/Over.pm

in the Over->dbh() sub.  I've only noticed this failure on
FreeBSD 13.2 (Perl 5.32.1, DBD::SQLite 1.72 (bundled SQLite
3.39.4), DBI 1.643) so far, so it could also be something to do
with the versions used and/or memory layout differences
with libc or build toolchain.
---
 lib/PublicInbox/Over.pm    | 13 +++++++++++--
 lib/PublicInbox/OverIdx.pm |  4 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm
index e3a8adb1..4eed4f46 100644
--- a/lib/PublicInbox/Over.pm
+++ b/lib/PublicInbox/Over.pm
@@ -82,7 +82,13 @@ sub dbh_close {
 	}
 }
 
-sub dbh ($) { $_[0]->{dbh} //= $_[0]->dbh_new } # dbh_new may be subclassed
+sub dbh ($) {
+	my ($self) = @_;
+	$self->{dbh} // do {
+		my $dbh = $self->dbh_new; # dbh_new may be subclassed
+		$self->{dbh} = $dbh;
+	}
+}
 
 sub load_from_row ($;$) {
 	my ($smsg, $cull) = @_;
@@ -256,9 +262,12 @@ SELECT ts,ds,ddd FROM over WHERE $s
 sub get_art {
 	my ($self, $num) = @_;
 	# caching $sth ourselves is faster than prepare_cached
-	my $sth = $self->{-get_art} //= dbh($self)->prepare(<<'');
+	my $sth = $self->{-get_art} // do {
+		my $sth = dbh($self)->prepare(<<'');
 SELECT num,tid,ds,ts,ddd FROM over WHERE num = ? LIMIT 1
 
+		$self->{-get_art} = $sth;
+	};
 	$sth->execute($num);
 	my $smsg = $sth->fetchrow_hashref;
 	$smsg ? load_from_row($smsg) : undef;
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index aead375a..c9c25828 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -520,7 +520,7 @@ EOM
 # used for cross-inbox search
 sub eidx_prep ($) {
 	my ($self) = @_;
-	$self->{-eidx_prep} //= do {
+	$self->{-eidx_prep} // do {
 		my $dbh = $self->dbh;
 		$dbh->do(<<'');
 INSERT OR IGNORE INTO counter (key) VALUES ('eidx_docid')
@@ -565,7 +565,7 @@ CREATE TABLE IF NOT EXISTS eidx_meta (
 		$dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS eidxq (docid INTEGER PRIMARY KEY NOT NULL)
 
-		1;
+		$self->{-eidx_prep} = 1;
 	};
 }
 

                 reply	other threads:[~2023-10-10 10:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231010100756.6268-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).