diff options
author | Dominique Leuenberger <dimstar@opensuse.org> | 2020-12-30 11:10:06 +0100 |
---|---|---|
committer | Dominique Leuenberger <dimstar@opensuse.org> | 2020-12-30 11:10:06 +0100 |
commit | aaf838b11fead511851ea58ec4edf61c21ab6066 (patch) | |
tree | 789200bb020e12787fbbb0551e3a1cc4bdc085d0 | |
parent | e1c5a4baec923e5ef2162bd1a6e334cdf2be12aa (diff) | |
download | libproxy-git-aaf838b11fead511851ea58ec4edf61c21ab6066.tar.gz |
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
-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 |