Code Monkey home page Code Monkey logo

clone's People

Contributors

atoomic avatar carnil avatar garu avatar gisle avatar haarg avatar jacquesg avatar manwar avatar plicease avatar rafl avatar zmughal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clone's Issues

Segmentation fault

On an Ubuntu 22.04.0 with perl v5.32 or v5.36, I have a perl module that caches and re-use a Data::UUID object, which is meant to be cached (confirmed with the author). When I use the copy of the Data::UUID object, it creates a segmentation fault.
I spent hours to find out where the segmentation fault came from.
I resolved it by not caching Data::UUID and thus avoiding Clone from cloning it.

malloc(): unaligned tcache chunk detected
[1]    9772 IOT instruction (core dumped)  perl -d:Trace -I./lib ./t/04.message.t

Using gdb, this produces:

(gdb) where
#0  0x00005555556629e9 in Perl_hfree_next_entry ()
#1  0x000055555568245d in Perl_sv_clear ()
#2  0x0000555555682d02 in Perl_sv_free2 ()
#3  0x00005555556ae6c9 in Perl_leave_scope ()
#4  0x0000555555673adf in Perl_pp_leavesub ()
#5  0x0000555555669fe6 in Perl_runops_standard ()
#6  0x00005555555cbcdc in perl_run ()
#7  0x000055555559f52a in main ()

Step to reproduce:

  1. Create a dummy class.
  2. Store an instance of Data::UUID
  3. Clone it
  4. Attempt to use the cloned version of the stored Data::UUID object, such as $obj->{cached_uuid}->create_str
  5. You will get a segmentation fault

Memory leak

Leaks memory when passed an expression that returns a non-existent hash value (which should be effectively undef). For example the following loop leaks ~70 MiB per second on my system.

use Clone;
my $data = {};
while(1) {
    Clone::clone ($data->{no_such_key});
};

However if you save the hash value in an intermediate variable, it doesn't leak:

use Clone;
my $data = {};
while(1) {
    my $tmp = $data->{no_such_key};
    Clone::clone ($tmp);
};

Environment
I was able to reproduce it in these environments:

  • Clone 0.46, perl v5.30.1, CentOS 7 x86_64
  • Clone 0.34, perl v5.16.3, CentOS 7 x86_64,

Some tests are "Artistic only" [rt.cpan.org #125815]

Migrated from rt.cpan.org#125815 (status was 'open')

Requestors:

From [email protected] on 2018-07-11 13:36:36:

t/dclone.t, t/tied.pl, and t/dump.pl files in Clone-0.39 distribution have this license declaration:

#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.

README mentions only "the same terms as Perl itself" so I believe you refer to this Artistic License <https://dev.perl.org/licenses/artistic.html>.

My issue is that some distributor do not consider this Artistic license free enough, e.g. Fedora, and cannot distribute these files. Would it be possible for you to change the license for the three files to be the same as the other files as it reads in the README:

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

I.e. GPL or Artistic?

From [email protected] on 2018-10-23 23:15:23:

Hi there! Thank you for submitting this issue and for your patience. While I am the current maintainer of Clone, I was not the author of those files. I'm going to try and contact him to see if we can make a new release with the revised test files. Otherwise, I'm not sure how to proceed (do feel free to advise if you have knowledge on possible legal implications). Finally, as a suggestion, what if the current Fedora package maintainer removes those files from the Fedora Clone package? They are not required for the installation nor the use of Clone.

Thank you!

garu

On Wed Jul 11 09:36:36 2018, ppisar wrote:
> t/dclone.t, t/tied.pl, and t/dump.pl files in Clone-0.39 distribution
> have this license declaration:
> 
> #  You may redistribute only under the terms of the Artistic License,
> #  as specified in the README file that comes with the distribution.
> 
> README mentions only "the same terms as Perl itself" so I believe you
> refer to this Artistic License
> <https://dev.perl.org/licenses/artistic.html>.
> 
> My issue is that some distributor do not consider this Artistic
> license free enough, e.g. Fedora, and cannot distribute these files.
> Would it be possible for you to change the license for the three files
> to be the same as the other files as it reads in the README:
> 
> This module is free software; you can redistribute it and/or
> modify it under the same terms as Perl itself.
> 
> I.e. GPL or Artistic?


Can't clone Math::BigInt::GMP objects [rt.cpan.org #117161]

Migrated from rt.cpan.org#117161 (status was 'new')

Requestors:

From [email protected] on 2016-08-23 13:16:25:

Math::BigInt::GMP objects cannot be cloned with Clone.pm:

$ perl5.18.4 -MMath::BigInt=only,GMP -MClone=clone -E 'say clone(Math::BigInt->new(42))->bstr'
failed to fetch mpz pointer at /opt/perl-5.18.4/lib/site_perl/5.18.4/Math/BigInt.pm line 3347.

Storable can deal with it:

$ perl5.18.4 -MMath::BigInt=only,GMP -MStorable=dclone -E 'say dclone(Math::BigInt->new(42))->bstr'
42

However, Storable cannot handle some types Clone can handle (most notably, Regexp).

A solution could be to invent a hook mechanism just as in Storable (STORABLE_freeze and STORABLE_thaw), or even better, re-use the Storable hooks if they are available.

A more simpler solution would be to just document this limitation, and point to other clone modules which may handle this (i.e. Storable).

In this special situation it would be possible to fallback to the pure perl Math::BigInt implementation (using "use Math::BigInt only => 'Calc'"), but this would be a huge performance hit when doing real calculations.

Clone::clone on shared data causes crash [rt.cpan.org #93821]

Migrated from rt.cpan.org#93821 (status was 'open')

Requestors:

From [email protected] on 2014-03-13 05:13:10:

Hi,

I'm trying to use Clone::clone to copy a hash which is shared among threads,
but when the result is accessed, Perl dies with
"Can't locate object method "FETCH" via package "threads::shared::tie" 
at ..."

Here's an example:
#!/usr/bin/perl
use strict; use warnings;
use threads;
use threads::shared;
use Clone;

my $a = shared_clone { foo => 100, bar => 200 };
my $b = Clone::clone($a);
print $b->{foo}, "\n"; #crashes here

-Jim

From [email protected] on 2014-05-15 22:16:59:

Hi Jim,

I don't think Clone is thread-safe. Are you able to reproduce the issue if you use Storable's dclone() instead of Clone's clone()?

Thanks!

From [email protected] on 2014-05-15 23:31:38:

On 05/15/2014 03:16 PM, Breno G. de Oliveira via RT wrote:
| I don't think Clone is thread-safe.
| Are you able to reproduce the issue if you use Storable's dclone() 
instead of Clone's clone()?

I'm not familiar with Storable, but gave it a try.   The result of 
dclone() can not be
de-referenced either, but the error is different:
#!/usr/bin/perl
use strict; use warnings; use threads; use threads::shared;
use Storable qw(dclone);

my $a = shared_clone { foo => 100, bar => 200 };
my $b = dclone($a);
# The next statement crashes with:
# Can't locate object method "FETCH" via package "threads::shared::tie"
print $b->{foo}, "\n";

From [email protected] on 2015-11-06 16:20:09:

Unfortunately threads::shared implements the sharing with tie-s to threads::shared::tie, but it makes zero sense to have a clone take part in the sharing -- if you wanted that, you would use the original variable, not the clone... Clone and Storable will (dirtily) have to special case that an remove all tie-s to threads::shared::tie, to be able to cooperate with threads::shared. Note that threads::shared itself has the same problem, you can't send a structure over a Thread::Queue and return the sent object over this or another Threads::Queue, this will crash after one or more iterations (I don't remember).

Ralf

From [email protected] on 2015-11-06 16:32:17:

https://rt.perl.org/Public/Bug/Display.html?id=38443

Date:	Mon, 06 Feb 2006 16:43:36 +0100

:)

t/07magic.t is chatty.

Seen in a make test run. I thought something was broken initially.

t/07magic.t ...... 1/10 SV = PVMG(0x150f510) at 0x1361a28
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK,UTF8)
  IV = 0
  NV = 0
  PV = 0x1443290 "a\r\n"\0 [UTF8 "a\r\n"]
  CUR = 3
  LEN = 10
  MAGIC = 0x1491cf0
    MG_VIRTUAL = &PL_vtbl_utf8
    MG_TYPE = PERL_MAGIC_utf8(w)
    MG_LEN = -1
    MG_PTR = 0x140ff40
       0: 2 -> 2
       1: 0 -> 0
SV = PVMG(0x150f570) at 0x14e5758
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK,UTF8)
  IV = 0
  NV = 0
  PV = 0x1490f70 "a\r\n"\0 [UTF8 "a\r\n"]
  CUR = 3
  LEN = 10
  MAGIC = 0xd81d50
    MG_VIRTUAL = &PL_vtbl_utf8
    MG_TYPE = PERL_MAGIC_utf8(w)
    MG_LEN = -1
    MG_PTR = 0x1459110
       0: 2 -> 2
       1: 0 -> 0
t/07magic.t ...... ok    

MANIFEST is out of date

The MANIFEST file in this repository is out of date. This means that some of the files are being excluded from releases, like t/cow.t. The release process should probably be updated to ensure that the MANIFEST is kept up to date.

Clone-0.40 crashes DBIx::Class

Hi!
I was trying to update my environment to the latest versions, but I failed to install DBIx::Class after updating Clone to 0.40.
Some tests suddenly crash with segmentation faults:

  • t/19retrieve_on_insert.t
  • t/prefetch/correlated.t
  • t/sqlmaker/bind_transport.t
  • t/sqlmaker/limit_dialects/first_skip.t
  • t/sqlmaker/limit_dialects/rno.t
  • t/sqlmaker/limit_dialects/skip_first.t

Tested with perl-5.28.0 and perl-5.24.3
After downgrading to Clone-0.39 the tests run fine.
Thanks,
Heinz

stack overflow with moderately complex data structures [rt.cpan.org #97525]

Migrated from rt.cpan.org#97525 (status was 'open')

Requestors:

From [email protected] on 2014-07-26 13:33:50:

This comes from the discussion of [rt.cpan.org #97508]:

$ ulimit -s
8192
$ perl -e 'use Clone qw(clone); $t = [$t] for 1..30000; clone $t'
$ perl -e 'use Clone qw(clone); $t = [$t] for 1..40000; clone $t'
Segmentation fault (core dumped)
$ ulimit -s 16348
$ perl -e 'use Clone qw(clone); $t = [$t] for 1..40000; clone $t'
$ perl -e 'use Clone qw(clone); $t = [$t] for 1..60000; clone $t'
$ perl -e 'use Clone qw(clone); $t = [$t] for 1..70000; clone $t'
Segmentation fault (core dumped)
$ dpkg -l perl libclone-perl | grep ii
ii  libclone-perl  0.36-1           amd64  module for recursively copying Perl datatypes
ii  perl           5.18.2-2ubuntu1  amd64  Larry Wall's Practical Extraction and Report Language

The same happens with:
$ perl -e 'use threads; $t = [$t] for 1..30000; (async {})->join'
Segmentation fault (core dumped)
$ perl -e 'use Storable qw(dclone); $t = [$t] for 1..30000; dclone $t'
Segmentation fault (core dumped)

From [email protected] on 2015-11-06 14:42:26:

According to this stack trace (generated by stsc) this is a recursion only involving av_clone() and sv_clone() from auto/Clone/Clone.so , which is completely internal to the Clone distribution:

http://perlpunks.de/paste/show/563ba05b.425c.da?plain=1

I would humbly suggest switching from recursion to some explicitly coded iterative traversal (e.g. maintaining an explicit recursion stack in the heap).

Ralf

Weakened refs always clone as undef [rt.cpan.org #113033]

Migrated from rt.cpan.org#113033 (status was 'new')

Requestors:

From [email protected] on 2016-03-15 06:36:21:

Hi,

Your very-useful module Clone does not seem to handle weakened refs:
They always clone as undef.

Please run the test script below to see the problem.
(bug observed in Clone version 0.38, the latest in CPAN)

Thanks,
-Jim Avera

P.S. The author email in the source ([email protected]) bounced.
#!/usr/bin/perl
use strict; use warnings;

package Parent;
sub new { bless { children => [] }, shift }

package Child;
use Scalar::Util qw(weaken);

sub new {
   my ($class, $parent) = @_;
   my $child = bless { parent => $parent }, $class;
   weaken($child->{parent});  ### COMMENT OUT TO REMOVE BUG
   push @{ $parent->{children} }, $child;
   return $child;
}

package main;
use Data::Dumper;
use Clone qw(clone);

my $p = Parent->new(foo => 123, bar => 456);
my $c = Child->new($p);
my $c_clone = clone($c);

warn Data::Dumper->Dump([$c], ["c"]);
warn Data::Dumper->Dump([$c_clone], ["c_clone"]);

die "bug" if ! defined $c->{parent};
die "bug" if ! defined $c_clone->{parent};

Kills DBHs [rt.cpan.org #21328]

Migrated from rt.cpan.org#21328 (status was 'open')

Requestors:

Attachments:

From [email protected] on 2006-09-05 09:45:42:

After cloning, my DBI database handles barf with:

Can't call prepare method on handle DBI::db=HASH(0x25755c8) after 
take_imp_data() at ../lib/Radio/Four/Programme.pm line 104.

From [email protected] on 2006-10-08 06:03:33:

A DBH is something can't be cloned (at least by Clone) since there are
too many underlying objects like C structures, file handles, etc that
Clone doesn't handle.  

A DBI database handle does have it's own clone method. I have considered
having Clone check an object for a native clone method and using that in
preference of it's own, but I think it might be a little too ambitious
for me.

From [email protected] on 2006-10-09 09:28:50:

via RT wrote:
> <URL: http://rt.cpan.org/Ticket/Display.html?id=21328 >
>
> A DBH is something can't be cloned (at least by Clone) since there are
> too many underlying objects like C structures, file handles, etc that
> Clone doesn't handle.  
>
> A DBI database handle does have it's own clone method. I have considered
> having Clone check an object for a native clone method and using that in
> preference of it's own, but I think it might be a little too ambitious
> for me.
>
>   
Having Clone check a blessed reference for a clone method should be 
really simple, using UNIVERSAL isa, so why not give it a shot?  Sounds 
like a great return for a little investment...!

Just a thought. I could supply you a patch ?

Lee

-- 
Lee Goddard
Server-side Systems Ltd
London N1 :: 0208 369 6832

From [email protected] on 2006-10-11 04:10:44:

Hi Lee,

I'm glad you wrote, I had lost your previous email when I deleted an 
entire month of archived messages.

By all means, if you want to supply a patch I will gladly look at it.

Sincerely,
Ray Finch
<[email protected]>

On Mon, 9 Oct 2006, [email protected] via RT wrote:

>
>       Queue: Clone
> Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21328 >
>
> via RT wrote:
>> <URL: http://rt.cpan.org/Ticket/Display.html?id=21328 >
>>
>> A DBH is something can't be cloned (at least by Clone) since there are
>> too many underlying objects like C structures, file handles, etc that
>> Clone doesn't handle.
>>
>> A DBI database handle does have it's own clone method. I have considered
>> having Clone check an object for a native clone method and using that in
>> preference of it's own, but I think it might be a little too ambitious
>> for me.
>>
>>
> Having Clone check a blessed reference for a clone method should be
> really simple, using UNIVERSAL isa, so why not give it a shot?  Sounds
> like a great return for a little investment...!
>
> Just a thought. I could supply you a patch ?
>
> Lee
>
> -- 
> Lee Goddard
> Server-side Systems Ltd
> London N1 :: 0208 369 6832
>
>
>

Cloning a DBI database handle results in segfault

This may be related to #14 and #17, as all circle around the topic of "don't clone database handles".
The attached script segfaults on Linux (Debian stretch, Perl 5.28).
I don't mind if Clone::clone dies if it detects a database handle, but it should somehow safeguard against segfaults.
dbhclone.txt

B::COW test dependency blocking downstream updates

Clone 0.44 introduced a test dependency on B::COW but that module fails its test suite on big-endian architectures (atoomic/B-COW/issues/1). A consequence of this is that as it stands, I cannot introduce the B::COW module in Fedora linux and thus cannot upgrade Clone beyond version 0.43 for now. This is likely to be an issue for other downstreams too unless they're content to disable the test suite for B::COW on big-endian architectures.

Test t/03scalar requires B::Cow; explodes if not loadable

When a system does not have B::Cow, t/03scalar should handle the situation
without exploding. It probably needs a test skip mechanism.

ok
t/03scalar.......Can't locate B/COW.pm in @inc (@inc contains: /csdi/src/sco507/perl/v5.8.8/Clone-0.45/blib/lib /csdi/src/sco507/perl/v5.8.8/Clone-0.45/blib/arch /usr/lib/perl5/5.8/i586-pc-sco3.2v5.0 /usr/lib/perl5/5.8 /usr/lib/perl5/site_perl/5.8/i586-pc-sco3.2v5.0 /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/sco_perl/5.8/i586-pc-sco3.2v5.0 /usr/lib/perl5/sco_perl/5.8 /usr/lib/perl5/sco_perl/5.8 .) at t/03scalar.t line 11.
BEGIN failed--compilation aborted at t/03scalar.t line 11.
dubious
Test returned status 2 (wstat 512, 0x200)
t/04tie..........1..5

Seen in Clone-0.45.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.