From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] thread: avoid recursion in Mail::Thread::recurse_down
Date: Fri, 5 Aug 2016 01:03:06 +0000 [thread overview]
Message-ID: <20160805010306.7552-1-e@80x24.org> (raw)
Yet another monkey patch to fix a problem encountered in upstream
Mail::Thread.
ref:
- https://rt.cpan.org/Ticket/Display.html?id=116727
- http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833479
---
lib/PublicInbox/Thread.pm | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/lib/PublicInbox/Thread.pm b/lib/PublicInbox/Thread.pm
index 44a565a..8af9461 100644
--- a/lib/PublicInbox/Thread.pm
+++ b/lib/PublicInbox/Thread.pm
@@ -5,6 +5,10 @@
# - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795913
# - https://rt.cpan.org/Ticket/Display.html?id=106498
#
+# And avoid recursion in recurse_down:
+# - https://rt.cpan.org/Ticket/Display.html?id=116727
+# - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833479
+#
# License differs from the rest of public-inbox (but is compatible):
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
@@ -42,6 +46,32 @@ sub topmost {
$_[0]->SUPER::topmost || PublicInbox::Thread::CPANRTBug106498->new;
}
+# non-recursive version of recurse_down to avoid stack depth warnings
+sub recurse_down {
+ my ($self, $callback) = @_;
+ my %seen;
+ my @q = ($self);
+ while (my $cont = shift @q) {
+ $seen{$cont}++;
+ $callback->($cont);
+
+ if (my $next = $cont->next) {
+ if ($seen{$next}) {
+ $cont->next(undef);
+ } else {
+ push @q, $next;
+ }
+ }
+ if (my $child = $cont->child) {
+ if ($seen{$child}) {
+ $cont->child(undef);
+ } else {
+ push @q, $child;
+ }
+ }
+ }
+}
+
# ref:
# - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795913
# - https://rt.cpan.org/Ticket/Display.html?id=106498
--
EW
reply other threads:[~2016-08-05 1:03 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=20160805010306.7552-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.
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).