Skip Menu |
Report information
Id: 130792
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: bri [at] abrij.org
Cc:
AdminCc:

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



Subject: nativecast of a rakudo-allocated value doesn't GC-proof it unless assigned to variable
Download (untitled) / with headers
text/plain 1.2k
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.


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