]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
over*: avoid defined-or hash assignments with side-effects
authorEric Wong <e@80x24.org>
Tue, 10 Oct 2023 10:07:56 +0000 (10:07 +0000)
committerEric Wong <e@80x24.org>
Tue, 10 Oct 2023 19:11:45 +0000 (19:11 +0000)
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
lib/PublicInbox/OverIdx.pm

index e3a8adb1b76dcb2468362192c03875008328ffc6..4eed4f469c4e3c743432742241fbf0ffe3b53a7b 100644 (file)
@@ -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;
index aead375a31d5f3aff58ce80a47ce88bce583aeef..c9c25828a1c4b0155fdffad5ecb9eb456e9260ce 100644 (file)
@@ -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;
        };
 }