From aaf838b11fead511851ea58ec4edf61c21ab6066 Mon Sep 17 00:00:00 2001 From: Dominique Leuenberger Date: Wed, 30 Dec 2020 11:10:06 +0100 Subject: perl: Add XS_unpack_charPtrPtr function Commit d52cc34458 introduced a new requirement on XS_unpack_charPtrPtr, but did not add the code for it. Use the template code form https://www.perlmonks.org/?node_id=680842 Fixes #123 --- bindings/perl/src/Libproxy.xs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 -- cgit v1.2.1