in reply to Perl, C and deallocation responsibility

I believe (having been dabbling in XS stuff recently for PDL and PDL::OpenCV) that your best bet here would be to return an SV* from your XS function. Then your CODE section would do:
char *tmp = proc_desc(a,b); sv_setpv(RETVAL, tmp, 0); free(tmp);

Replies are listed 'Best First'.
Re^2: Perl, C and deallocation responsibility
by etj (Priest) on Apr 28, 2023 at 01:14 UTC
    A belated further thought: you could typedef the return type (char*) to a new type-name, then have a typemap entry that handles the OUTPUT of that with that code-snippet: https://perldoc.perl.org/perlxstypemap.

      Thanks for those suggestions. I'll see if I can get time to play with them today.

      Given time constraints I came up with a much hackier solution (static pointer to a string which is used every call. Not thread safe, but in this case, not an issue), but I want to do it cleanly!