convert a Perl AV* (containing strings) to a C char** 
Author Message
 convert a Perl AV* (containing strings) to a C char**

I have many C functions which I am using with perlxs to
create an extension package for my perl scripts.

All of the C functions have at least one argument which
requires a non-empty "char**" parameter and I would like
to allow perl scripts which use my package to call the
routine with a perl array variable as the arguement
which I can then have converted into the expected
C char** target data type.

Is there some generic utility library out there which
is full of common conversion routines which I can use,
and if not, then how do you do it.

Thanks,


John



Mon, 31 Jan 2000 03:00:00 GMT  
 convert a Perl AV* (containing strings) to a C char**

On Thu, 14 Aug 1997 15:16:31 -0500,

Quote:
>I have many C functions which I am using with perlxs to
>create an extension package for my perl scripts.

>All of the C functions have at least one argument which
>requires a non-empty "char**" parameter and I would like
>to allow perl scripts which use my package to call the
>routine with a perl array variable as the arguement
>which I can then have converted into the expected
>C char** target data type.

>Is there some generic utility library out there which
>is full of common conversion routines which I can use,
>and if not, then how do you do it.

XS's typemap is a form of generic utility library, though it doesn't include
what you need. You might also want to try SWIG
(http://www.cs.utah.edu/~beazley/SWIG/swig.html), which is like XS but in
some ways more powerful (and includes backends for many different scripting
languages).

If you have an AV*, you can find the number of elements in it with the
av_len() function, retrieve the elements with av_fetch(), convert them to
`char *'s using SvPV() (all these functions are described in perlguts(1)),
and put them in a malloc()d array. If the C function modifies the strings,
you'll want to pass copies of the values from the array.

--
____________________________________________________________



Wed, 02 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Detecting string containing no printing chars ?

2. reading char by char in a string

3. Char position of 1st non-word char in a string

4. Appending char to strings by char

5. finding files containing string x but not string y

6. Regexp containing plus-chars won't work?!?!?

7. how to define alphanumeric (words containing non-ASCII chars)

8. XS (converting perl array to char**..)

9. XS (converting perl array to char**..)

10. split a string not only by a single char but also by a string

11. Newbie: sprintf ('%-20s', 48 char string) returns 48 not 20 length string

12. Convert money amount to text string - convert.pl

 

 
Powered by phpBB® Forum Software