At some point in my program, it seems that easiest (fastest, etc.) thing to do is to directly replace raw image data with data from Perl scalar. Needless to say, Imager API (both Perl and C) don't provide for this, but I thought I'd get away with following subroutine (here it is with a test program that, of course, makes no sense):
use strict; use warnings; use Imager; use Inline with => 'Imager'; use Inline C => << 'END_OF_C'; void _replace( Imager img, SV* str ) { unsigned char* ptr = SvPV_nolen( str ); myfree( img-> idata ); img-> idata = ptr; } END_OF_C my $i = Imager-> new( xsize => 99, ysize => 99 ); for ( 'A' .. 'F' ) { print "$_\n"; my $s; $i-> write( data => \$s, type => 'raw' ); my $j = $i-> copy(); # Here, it's rumored, some nasty things # happening, that involve $j and $s. # But maybe nothing happens. _replace( $i, $s ); } __END__ ~$ perl test.pl A B *** Error in `perl': double free or corruption (!prev): 0x0000000002d6 +7990 *** Aborted (core dumped)
Unfortunately, my C is below-zero level. I understand I should prevent Perl from freeing memory that now is Imager responsibility, but don't know how. And, actually, replacement itself works OK. There's only error freeing memory, that happens just sometimes. This program seems to reproduce it always.
In reply to Trying dirty trick with Imager and Inline C, but having difficulties. Can you help? by vr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |