unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] lei_to_mail: drop awkward duplication of $lei object
Date: Fri, 22 Sep 2023 21:13:15 +0000	[thread overview]
Message-ID: <20230922211316.3060039-4-e@80x24.org> (raw)
In-Reply-To: <20230922211316.3060039-1-e@80x24.org>

Our awaitpid API now exists and ProcessPipe uses it, so it's
immune to cyclic references.  Thus there's no need to create
a duplicate of the lei object to prevent leaks.
---
 lib/PublicInbox/LeiToMail.pm | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 7c7967c8..4adcc33e 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -151,10 +151,9 @@ sub git_to_mail { # git->cat_async callback
 }
 
 sub reap_compress { # awaitpid callback
-	my ($pid, $lei) = @_;
-	my $cmd = delete $lei->{"pid.$pid"};
-	return if $? == 0;
-	$lei->fail($?, "@$cmd failed");
+	my ($pid, $lei, $cmd, $old_out) = @_;
+	$lei->{1} = $old_out;
+	$lei->fail($?, "@$cmd failed") if $?;
 }
 
 sub _post_augment_mbox { # open a compressor process from top-level process
@@ -165,9 +164,8 @@ sub _post_augment_mbox { # open a compressor process from top-level process
 	my $rdr = { 0 => $r, 1 => $lei->{1}, 2 => $lei->{2}, pgid => 0 };
 	my $pid = spawn($cmd, undef, $rdr);
 	my $pp = gensym;
-	my $dup = bless { "pid.$pid" => $cmd }, ref($lei);
-	$dup->{$_} = $lei->{$_} for qw(2 sock);
-	tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w, \&reap_compress, $dup;
+	tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w,
+			\&reap_compress, $lei, $cmd, $lei->{1};
 	$lei->{1} = $pp;
 }
 

  parent reply	other threads:[~2023-09-22 21:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 21:13 [PATCH 0/4] small lei fixes Eric Wong
2023-09-22 21:13 ` [PATCH 1/4] lei blob|rediff: fix usage of lei->fail Eric Wong
2023-09-22 21:13 ` [PATCH 2/4] lei: improve ->fail internal API Eric Wong
2023-09-22 21:13 ` Eric Wong [this message]
2023-09-22 21:13 ` [PATCH 4/4] lei: use File::Temp for listing saved searches 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=20230922211316.3060039-4-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.
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).