Skip Menu |

This queue is for tickets about the LinkedList-Single CPAN distribution.

Report information
The Basics
Id: 133094
Status: open
Priority: 0/
Queue: LinkedList-Single

People
Owner: Nobody in particular
Requestors: jo [...] sommrey.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: List disappears with cloned head
Date: Sat, 01 Aug 2020 14:11:52 +0000
To: bug-LinkedList-Single [...] rt.cpan.org
From: Jörg Sommrey <jo [...] sommrey.de>
Hi, there is a strange behaviour in LinkedList::Simple when a cloned list head gets out of scope or is set to 'undef': the original list disappears after a reset-to-start: #!/usr/bin/perl use strict; use warnings; use LinkedList::Single; use Data::Dump 'pp'; my $lh = LinkedList::Single->new(1, 2, 3); { # When $lh_clone gets out of scope (or is set to undef), # the original list disappears after reset-to-start. my $lh_clone = $lh->clone; ; } pp $lh; $lh->head; pp $lh; __DATA__ bless(do{\(my $o = [[[[], 3], 2], 1])}, "LinkedList::Single") bless(do{\(my $o = undef)}, "LinkedList::Single")
Subject: Re: [rt.cpan.org #133094] List disappears with cloned head - patch
Date: Sun, 02 Aug 2020 11:02:31 +0000
To: Bugs in LinkedList-Single via RT <bug-LinkedList-Single [...] rt.cpan.org>
From: Jörg Sommrey <jo [...] sommrey.de>
Here is a patch for this issue: --- /usr/local/share/perl/5.20.2/LinkedList/Single.pm 2014-09-08 19:54:41.000000000 +0200 +++ LinkedList/Single.pm 2020-08-02 12:09:02.392575697 +0200 @@ -178,7 +178,9 @@ { my $head = delete $rootz{ refaddr shift }; - $#$head = -1; + # a cloned head references the same data. This must not + # be deleted when the clone is destroyed. + # $#$head = -1; return }
CC: lembark [...] wrkhors.com
Subject: Re: [rt.cpan.org #133094] List disappears with cloned head
Date: Mon, 10 Aug 2020 22:04:09 -0400
To: bug-LinkedList-Single [...] rt.cpan.org
From: Steven Lembark <lembark [...] wrkhors.com>
Apologies for the dealay in replying, I've been in the middle of moving & my mail server has been in a box. Show quoted text
> there is a strange behaviour in LinkedList::Simple when a cloned list > head gets out of scope or is set to 'undef': > the original list disappears after a reset-to-start:
The point of using the singly linked list is that if the root goes out of scope it deletes the list, regardless of the context. The main point of cloning the list head is to provide a separate, usually transient, context for traversing the list. In that case the cloned list object wouldn't be used to delete the head or root since it is a copy used for traversal only. The utility of this behavior is having a manager that creates lists and threads off workers to process a list. At that point the worker thread can clean up by removing the root. Q: How are you using the cloned list (which is nothing more than a cloned head node)? It may be that weakening the cloned copy might be what you need, or I should create a read-only copy (different from "clone") that is used for traversing the list in a cleaner fashion. Thanks -- Steven Lembark Workhorse Computing lembark@wrkhors.com +1 888 359 3508
Subject: Re: [rt.cpan.org #133094] List disappears with cloned head
Date: Tue, 11 Aug 2020 12:37:50 +0000
To: "lembark [...] wrkhors.com via RT" <bug-LinkedList-Single [...] rt.cpan.org>
From: Jörg Sommrey <jo [...] sommrey.de>
On Tue 11 Aug 2020 04:24:39 AM CEST, "lembark@wrkhors.com via RT" <bug-LinkedList-Single@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=133094 > > > Apologies for the dealay in replying, I've been in the middle of > moving & my mail server has been in a box. >
>> there is a strange behaviour in LinkedList::Simple when a cloned list >> head gets out of scope or is set to 'undef': >> the original list disappears after a reset-to-start:
> > The point of using the singly linked list is that if the root > goes out of scope it deletes the list, regardless of the context. > > The main point of cloning the list head is to provide a separate, > usually transient, context for traversing the list. In that case > the cloned list object wouldn't be used to delete the head or root > since it is a copy used for traversal only. > > The utility of this behavior is having a manager that creates lists > and threads off workers to process a list. At that point the worker > thread can clean up by removing the root. > > Q: How are you using the cloned list (which is nothing more than > a cloned head node)?
I hit this problem when I tried to use a sub for printing a complete list independently from its current position, like sub list_print { my $lh = (shift)->clone; for ($lh->head; $lh->has_next; $lh->next) { print $lh->node_data->[0], ' -> '; } print $lh->node_data->[0], "\n"; } my $lh = LinkedList::Single->new(1, 2, 3); $lh->push(4); list_print $lh; $lh->add(5); # dies! list_print $lh;