Perl XS and C ++ pass a pointer to a buffer

I hardly know C ++, so as not to help, and my XS is not much better. I am creating an XS interface for the C ++ library, and almost all of my methods work for me, except for one.

The method in Perl should look like this:

$return_data = $obj->readPath( $path );

The method is defined as this .h file:

int readPath(const char* path, char* &buffer, bool flag=true);

The "buffer" will be allocated if it passed in NULL.

There are two additional versions of readPath with different signatures, but they are not the ones I need. (And I wonder when I try to compile, he tells me that the “candidates” are the ones that I don’t need.) Is it because he doesn’t understand “char * &”?

Can someone help with xsub i need to write?

I am on Perl 5.14.2.

BTW - "long long int" T_IV. , . , ?

,

+5
1

++ C XS. C, :

void
readPath(SV* sv_path)
   PPCODE:
      {
         char*  path   = SvPVbyte_nolen(sv_path, len);
         char*  buffer = NULL;

         if (!readPath(path, &buffer, 0))
            XSRETURN_UNDEF;

         ST(0) = sv_2mortal(newSVpv(buffer, 0));
         free(buffer);

         XSRETURN(1);
      }

, .


:

  • readPath true/false /.
  • buffer .
  • buffer - free.
+3

All Articles