Skip Menu |

This queue is for tickets about the Inline-Struct CPAN distribution.

Report information
The Basics
Id: 99555
Status: resolved
Worked: 6 hours (360 min)
Priority: 0/
Queue: Inline-Struct

People
Owner: ETJ [...] cpan.org
Requestors: heinz.knutzen [...] gmail.com
Cc:
AdminCc:

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



Subject: Bug when retrieving values from reassigned struct
Date: Fri, 17 Oct 2014 22:53:53 +0200
To: bug-Inline-Struct [...] rt.cpan.org
From: Heinz Knutzen <heinz.knutzen [...] gmail.com>
This test case ============================================ use strict; use warnings; use Test::More; use Inline C => <<'END', structs => 1, force_build => 1, clean_after_build => 0; struct Foo { SV *src; SV *dst; char *prt; }; END my $o = Inline::Struct::Foo->new(); my $str = 'a'; $o->src($str)->dst($str)->prt($str); my %vals = (src => $str, dst => $str, prt => $str); is_deeply $o->$_(), $vals{$_}, $_ for qw(src dst prt); my $copy = $o; is_deeply $copy->$_(), $vals{$_}, $_ for qw(src dst prt); done_testing; ============================================ fails with not ok 5 - dst # Failed test 'dst' # at inline-struct-free-unrefd.pl line 20. # got: '0' # expected: 'a' not ok 6 - prt # Failed test 'prt' # at inline-struct-free-unrefd.pl line 20. # got: '`�E__' # expected: 'a' and it prints "Attempt to free unreferenced scalar: SV 0x98c0538." on exit. Used versions: - Inline-Struct-0.12 - Perl v5.18.2
You aren't "reassigning" in this case, you are attempting an object copy by simple assignment. I am going to call the behaviour on this undefined; it would only work in the case of an explicit method for duplication. I am therefore rejecting this as a bug. Please feel free to comment further if you disagree, though!
Subject: Re: [rt.cpan.org #99555] Bug when retrieving values from reassigned struct
Date: Sun, 19 Oct 2014 00:33:17 +0200
To: bug-Inline-Struct [...] rt.cpan.org
From: Heinz Knutzen <heinz.knutzen [...] gmail.com>
If a struct is created and assigned to a variable like this: my $o = Inline::Struct::Foo->new(); then $o holds a reference to the newly created struct. When assigning the value of $o to some other variable, then only the reference should be copied. If assignment isn't allowed, we couldn't pass a reference to a struct as parameter to any function at all. This would be a serious restriction. In my use case I would like to substitute millions of small hashes with a fixed set of attributes by structs. I would like to be able to pass references to structs as easy as hash references.
This is fixed in commit 9fba124c8459891bf8e09334fb8e4e78136484b6 (and 0.14) Was in fact an error in settor/gettor methods unconditionally mortalising retval when should only have done so on settor methods that returned a ref to main object. Please feel free, going forward, to use the github issues interface, and/or to issue a github PR with a changed/new *.t file.