in reply to Trying dirty trick with Imager and Inline C, but having difficulties. Can you help?

See perlcapi, perlapi, call one of copy funcs, or Safefree, New
  • Comment on Re: Trying dirty trick with Imager and Inline C, but having difficulties. Can you help?

Replies are listed 'Best First'.
Re^2: Trying dirty trick with Imager and Inline C, but having difficulties. Can you help?
by vr (Curate) on Aug 01, 2015 at 11:28 UTC

    I was hoping to avoid copying i.e. re-use allocated string data. Thanks to your tip, I think a working solution can be:

    void _replace( Imager img, SV* str ) { sv_force_normal( str ); unsigned char* ptr = SvPV_nolen( str ); myfree( img-> idata ); img-> idata = ptr; SvPV_set( str, savepv( "" ) ); }

    It works, though I'm still not sure, is it really OK? Or too ugly? Or scandalously incorrect and will bite me some time later?

        Thank you. Yes, it works with Strawberry 5.20.2, gcc 4.8.3 (i686-w64-mingw32).