diff options
author | Dominique Leuenberger <dimstar@opensuse.org> | 2022-06-20 16:18:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-20 16:18:24 +0200 |
commit | 98c22257133fd4e7381afe7e730de0857ee561b3 (patch) | |
tree | 5c4550669f17e511f0adb7e4d5930205c18d3a0e | |
parent | 6b9aff168d7538f585e8a0edce40d97728dc379d (diff) | |
parent | aaf838b11fead511851ea58ec4edf61c21ab6066 (diff) | |
download | libproxy-git-98c22257133fd4e7381afe7e730de0857ee561b3.tar.gz |
Merge pull request #152 from DimStar77/issue123
perl: Add XS_unpack_charPtrPtr function
-rw-r--r-- | bindings/perl/src/Libproxy.xs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bindings/perl/src/Libproxy.xs b/bindings/perl/src/Libproxy.xs index 32c3200..bf5c2bb 100644 --- a/bindings/perl/src/Libproxy.xs +++ b/bindings/perl/src/Libproxy.xs @@ -15,6 +15,37 @@ void XS_pack_charPtrPtr( SV * arg, char ** array, int count) { SvSetSV( arg, newRV((SV*)avref)); } +/* http://www.perlmonks.org/?node_id=680842 */ +static char ** +XS_unpack_charPtrPtr (SV *arg) { + char **ret; + AV *av; + I32 i; + + if (!arg || !SvOK (arg) || !SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) + croak ("array reference expected"); + + av = (AV *)SvRV (arg); + ret = malloc ((av_len (av) + 1 + 1) * sizeof (char *)); + if (!ret) + croak ("malloc failed"); + + for (i = 0; i <= av_len (av); i++) { + SV **elem = av_fetch (av, i, 0); + + if (!elem || !*elem) { + free (ret); + croak ("missing element in list"); + } + + ret[i] = SvPV_nolen (*elem); + } + + ret[i] = NULL; + + return ret; +} + MODULE = Net::Libproxy PACKAGE = Net::Libproxy |