You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure whether this is a "bug" or a "doc bug"... there is clearly some intent in the code to cause nativecasting something to prevent it from being GCd from under the resulting pointer, but the limitations of this protection are not spelled out.
Here is one case where a GC can cause a Pointer to point to garbage:
$ perl6 -e 'use NativeCall; use nqp; my $anchor; my $c = nativecast(Pointer[uint8], Buf.new(1,2,3,4,5,6)); class f is repr("CStruct") { has uint16 $.a; has uint32 $.b }; my $d = nativecast(f,$c); my $f = $d.a; nqp::force_gc; $d = nativecast(f,$c); say $f == $d.a'
False
Assigning the Buf to a variable seems to restore the protection (but this may just be due to optimization not yet getting around to realizing $anchor is not used?)
$ perl6 -e 'use NativeCall; use nqp; my $anchor; my $c = nativecast(Pointer[uint8], $anchor = Buf.new(1,2,3,4,5,6)); class f is repr("CStruct") { has uint16 $.a; has uint32 $.b }; my $d = nativecast(f,$c); my $f = $d.a; nqp::force_gc; $d = nativecast(f,$c); say $f == $d.a'
True
Obviously it is necessary to have some level of protection in order for nativecast pointers to objects allocated by rakudo to be at all useful; how far it is technically possible to accomplish this probably has limits and whatever rules users need to follow should be spelled out in docs.
Migrated from rt.perl.org#130792 (status was 'new')
Searchable as RT130792$
The text was updated successfully, but these errors were encountered: