develooper Front page | perl.perl5.porters | Postings from November 2017

Patch for AnyEvent::HTTP

Thread Next
From:
Sawyer X
Date:
November 19, 2017 14:08
Subject:
Patch for AnyEvent::HTTP
Message ID:
CAMvkq_RBErEYJ8D+n5txzH0og5q3t-XkhzqzMT+EWd6Onf_ubA@mail.gmail.com
Hi Marc,

An optimization to in-place array sorting has caused a breakage of
AnyEvent::HTTP. We are tracking this in RT 132142[1].

We have a patch prepared for AnyEvent::HTTP, available here as both inlined
and an attachment, for your comfort. We would appreciate it if you could
please apply it and release a new version, at your convenience

Thank you,
Sawyer.

[1] https://rt.perl.org/Ticket/Display.html?id=132142

----

From 8e12a666543e50043419630d5e4ff00c7dd277e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Fri, 17 Nov 2017 23:59:30 +0000
Subject: [PATCH] Re-weaken timer references after sorting

Perl 5.27.4 fixes the in-place sort optimisation (@a = sort @a) to
strengthen references, like assignment should.

However, we need to keep the references to timers weak, so callers can
cancel them by dropping their reference.
---
 lib/AnyEvent/Loop.pm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/AnyEvent/Loop.pm b/lib/AnyEvent/Loop.pm
index fb9351a..f7145fd 100644
--- a/lib/AnyEvent/Loop.pm
+++ b/lib/AnyEvent/Loop.pm
@@ -173,6 +173,9 @@ BEGIN {
    $round = 0.001 if $round < 0.001; # 1ms is enough for us
    $round -= $round * 1e-2; # 0.1 => 0.099
    eval "sub ROUNDUP() { $round }";
+
+   my $unweakens = $] >= 5.027004 ? 1 : 0;
+   eval "sub INPLACE_SORT_UNWEAKENS() { $unweakens }";
 }

 _update_clock;
@@ -203,6 +206,9 @@ sub one_event {
    if ($MNOW >= $need_sort) {
       $need_sort = 1e300;
       @timer = sort { $a->[0] <=> $b->[0] } @timer;
+      if (INPLACE_SORT_UNWEAKENS) {
+          weaken($_) for @timer;
+      }
    }

    # handle all pending timers
--
2.7.4

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About