Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active September 12, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/5d9fe7c62af791144df8f449bcb521ce to your computer and use it in GitHub Desktop.
Save Xliff/5d9fe7c62af791144df8f449bcb521ce to your computer and use it in GitHub Desktop.
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