in reply to Passing a string from C to Perl

As you noted yourself, your method is a recipe for disaster by buffer overflow.

You should use the package Inline. The following example is straight from the Inline::C-Cookbook. It shows how it is easy it is to pass strings back and forth between C and Perl. The part of the example that interests you is getting a string of variable size from C to perl. This is done by newSVpvf() that copies a C-string formatted a la sprintf into a mortal perl-string. This means you don't have to care about allocation and deallocation.


print greeting('Ingy')

use Inline C => <<'END_OF_C_CODE';

      SV* greeting(SV* sv_name) {
         return (newSVpvf("Hello %s!\n", SvPV(sv_name, PL_na)));
      }

END_OF_C_CODE

-- stefp