Apache2-ModXml2
view release on metacpan or search on metacpan
Av_CharPtrPtr.c view on Meta::CPAN
/* Modified from API Cookbook A Example 8 */
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "Av_CharPtrPtr.h" /* XS_*_charPtrPtr() */
#ifdef __cplusplus
}
#endif
#if defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
#endif
/* Used by the INPUT typemap for char**.
* Will convert a Perl AV* (containing strings) to a C char**.
*/
char ** XS_unpack_charPtrPtr(SV* rv )
{
AV *av;
SV **ssv;
char **s;
int avlen;
int x;
if( SvROK( rv ) && (SvTYPE(SvRV(rv)) == SVt_PVAV) )
av = (AV*)SvRV(rv);
else {
return( (char**)NULL );
}
/* is it empty? */
avlen = av_len(av);
if( avlen < 0 ){
return( (char**)NULL );
}
/* av_len+2 == number of strings, plus 1 for an end-of-array sentinel.
*/
s = (char **)safemalloc( sizeof(char*) * (avlen + 2) );
if( s == NULL ){
warn("XS_unpack_charPtrPtr: unable to malloc char**");
return( (char**)NULL );
}
for( x = 0; x <= avlen; ++x ){
ssv = av_fetch( av, x, 0 );
if( ssv != NULL ){
if( SvPOK( *ssv ) ){
s[x] = (char *)safemalloc( SvCUR(*ssv) + 1 );
if( s[x] == NULL )
warn("XS_unpack_charPtrPtr: unable to malloc char*");
else
strcpy( s[x], SvPV( *ssv, PL_na ) );
}
else
warn("XS_unpack_charPtrPtr: array elem %d was not a string.", x );
( run in 2.168 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )