From 57a244f0776a94ef8c789376340a2fa02e838935 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 14 Jan 2017 00:33:43 +0100 Subject: Inline::C: Don't assume we can modify inplace and return the input buffer back to Perl. --- mkindex.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mkindex.pl b/mkindex.pl index 97fdf93..ed75907 100755 --- a/mkindex.pl +++ b/mkindex.pl @@ -498,7 +498,6 @@ sub expand_rgba { my $src_data = $src_band->ReadRaster(0, $y, $xSize, 1); for (my $b = 0; $b < $dst_nb; $b++) { - local $_ = $src_data; # We use an inlined C function to speed up things a bit. # Essentially what we're doing is a splice through the # lookup table. @@ -507,8 +506,8 @@ sub expand_rgba { # than our C code, can be obtained using transliteration: # my $src_str = join '', map chr, (0 .. $src_nc-1); # eval "tr/\Q$src_str\E/\Q$lookup->[$b]\E/"; - &subst ( $_, $lookup->[$b], $xSize ); - $dst_ds->Band(1+$b)->WriteRaster(0, $y, $xSize, 1, $_); + my $dst_data = &subst( $src_data, $lookup->[$b], $xSize ); + $dst_ds->Band(1+$b)->WriteRaster(0, $y, $xSize, 1, $dst_data); } &{$config{progress}}( (1+$y) / $ySize ) if $config{progress}; @@ -687,8 +686,11 @@ __END__ __C__ -void subst (unsigned char *data, unsigned char *lookup, int length) { - int i; - for (i = 0; i < length; i++) - data[i] = lookup[ data[i] ]; +SV *subst(unsigned char *data, unsigned char *lookup, int length) { + char *out = malloc(length * sizeof(unsigned char)); + for (int i = 0; i < length; i++) + out[i] = lookup[ data[i] ]; + SV* ret = newSVpvn(out, length); + free(out); + return(ret); } -- cgit v1.2.3