in reply to Testing DESTROY Methods?
I find that it is best, when you free() a pointer, to also set the pointer to NULL. So have your DESTROY method croak if the pointer is already NULL. Then your test script can call DESTROY by hand and then let the object go out of scope and trap the error:
my $fail= eval { { my $obj= My::Mod->new(); $obj->DESTROY(); } 1 }; print "not " unless $fail && $@ =~ /destroyed NULL/; print "ok 19\n";
I hope that eval traps XS-based croak().
And, of course, this won't work in Perl 6 if it doesn't implement reference counting.
- tye (instruction at 0xBADC0DE5 tried to read 0x00000000)
|
|---|