Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy class attribute interaction segfaults #3731

Open
p6rt opened this issue Mar 12, 2015 · 3 comments
Open

Proxy class attribute interaction segfaults #3731

p6rt opened this issue Mar 12, 2015 · 3 comments
Labels
SEGV Segmentation fault, bus error, etc.

Comments

@p6rt
Copy link

p6rt commented Mar 12, 2015

Migrated from rt.perl.org#124057 (status was 'open')

Searchable as RT124057$

@p6rt
Copy link
Author

p6rt commented Mar 12, 2015

From john.haltiwanger@gmail.com

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 "$@​"

@p6rt
Copy link
Author

p6rt commented Mar 14, 2018

From @ronaldxs

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;

prints
nop

@p6rt
Copy link
Author

p6rt commented Mar 14, 2018

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the SEGV Segmentation fault, bus error, etc. label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SEGV Segmentation fault, bus error, etc.
Projects
None yet
Development

No branches or pull requests

1 participant