Skip Menu |
Report information
Id: 124057
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: john.haltiwanger [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
Subject: [BUG] Proxy class attribute interaction segfaults
From: John Haltiwanger <john.haltiwanger [...] gmail.com>
Date: Fri, 13 Mar 2015 00:15:08 +0100
Download (untitled) / with headers
text/plain 1.8k
I encountered a consistent segfault while working out a trivial proxy example in hopes of documenting the class.

How this might be condensed further is beyond me at the moment. After removing the $!scrambler attribute, the code will no longer segfault, which would defeat the purpose of this rakudobug.

Weirdly enough, if I remove $!string, it also stops segfaulting -- even though it is never used. The name of the attribute doesn't seem to matter.

This class is modeled off of what I saw in the proxy-related spec tests. The mutator test seems to do something very similar, but I haven't been able to extend it.


## codeword.p6

class Codeword {
    has Sub $.scrambler is rw;
    has $!string;
    has $!encoded-string;

    submethod BUILD {
        my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii }
        $!scrambler = &scrambler;
    }

    method codeword returns Str is rw {
        return Proxy.new(
            FETCH => method ()      { $!encoded-string },
            STORE => method ($s)    { $!encoded-string = $!scrambler($s) }
        );
    }
}

my $code = Codeword.new;
$code.codeword;


## perl6-debug-m output:

+ proxy-test.p6 (23 - 25)
|
| my $code = Codeword.new;
| $code.codeword;
>
+ proxy-test.p6 (15 - 22)
|
|     method codeword returns Str is rw {
|         return Proxy.new(
|             FETCH => method ()      { $!encoded-string },
|             STORE => method ($s)    { $!encoded-string = $!scrambler($s) }
|         );
|     }
| }
>
+ proxy-test.p6 (16 - 20)
|     method codeword returns Str is rw {
|         return Proxy.new(
|             FETCH => method ()      { $!encoded-string },
|             STORE => method ($s)    { $!encoded-string = $!scrambler($s) }
|         );
>
~/.rakudobrew/bin/perl6-debug-m: line 2: 14368 Segmentation fault: 11  ~/.rakudobrew/bin/../moar-HEAD/install/bin/perl6-debug-m "$@"
RT-Send-CC: rakudobug [...] perl.org
When I run this example now (Windows and Linux) I get: P6opaque: no such attribute '$!encoded-string' on type Codeword in a Proxy when trying to get a value instead of a segfault. If I tweak the code as below to use subs instead of methods for the Proxy hooks it runs fine. The P6opaque error seems reminiscent of a recent IRC conversation: https://irclog.perlgeek.de/perl6/2018-03-03#i_15879434 . Between the IRC conversation and making it work by switching to subs I suspect it might be OK to merge this ticket with RT 126198 . ## codeword.p6 class Codeword { has Sub $.scrambler is rw; has $!string; has Str $!encoded-string; submethod BUILD { my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii } $!scrambler = &scrambler; } method codeword returns Str is rw { return Proxy.new( FETCH => sub ($) { $!encoded-string }, STORE => sub ($,$s) { $!encoded-string = $!scrambler($s) } ); } } my $code = Codeword.new; $code.codeword; $code.codeword = 'abc'; say $code.codeword; Show quoted text
> prints
nop


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org