Last active
September 12, 2016 18:36
-
-
Save Xliff/5d9fe7c62af791144df8f449bcb521ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6.c; | |
use nqp; | |
use NativeCall; | |
class A is repr('CStruct') { | |
has int32 $.one; | |
has int32 $.two; | |
has int32 $.three; | |
has Pointer $.four; | |
} | |
class B is A is repr('CStruct') { | |
method getA { | |
nativecast(A, self); | |
} | |
} | |
sub setObjAttr($obj, $attr, $val) is export { | |
nqp::bindattr( | |
nqp::decont($obj), $obj.WHAT, $attr, nqp::decont($val) | |
); | |
} | |
sub MAIN { | |
my $a = A.new(:one(1), :two(22), :three(333)); | |
my $b = B.new(:one(2), :two(66), :three(888)); | |
my $p = nativecast(Pointer, $a); | |
# cw: This works. | |
setObjAttr($a, '$!four', $p); | |
# cw: This causes segfault. | |
#setObjAttr($b, '$!four', $p); | |
# cw: Should not cause a segfault. | |
setObjAttr($b.getA, '$!four', $p); | |
# cw: This still causes segfault. | |
setObjAttr($b, '$!four', $p, :what(A)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment