summaryrefslogtreecommitdiff
path: root/src/if_perl.xs
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-12 22:47:31 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-12 22:47:31 +0100
commit6e5ea8d2a995b32bbc5972edc4f827b959f2702f (patch)
treeb1ad7d6a83f53220227122719d5eb97dd32ff1e6 /src/if_perl.xs
parente3c74d249ac36404d8af25f74baf335d143b30e3 (diff)
downloadvim-git-6e5ea8d2a995b32bbc5972edc4f827b959f2702f.tar.gz
patch 8.1.0735: cannot handle binary datav8.1.0735
Problem: Cannot handle binary data. Solution: Add the Blob type. (Yasuhiro Matsumoto, closes #3638)
Diffstat (limited to 'src/if_perl.xs')
-rw-r--r--src/if_perl.xs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/if_perl.xs b/src/if_perl.xs
index 627f43707..251daf424 100644
--- a/src/if_perl.xs
+++ b/src/if_perl.xs
@@ -236,6 +236,7 @@ typedef int perl_key;
# else
# define Perl_sv_2pv dll_Perl_sv_2pv
# endif
+# define Perl_sv_2pvbyte dll_Perl_sv_2pvbyte
# define Perl_sv_bless dll_Perl_sv_bless
# if (PERL_REVISION == 5) && (PERL_VERSION >= 8)
# define Perl_sv_catpvn_flags dll_Perl_sv_catpvn_flags
@@ -388,6 +389,7 @@ static char* (*Perl_sv_2pv_nolen)(pTHX_ SV*);
# else
static char* (*Perl_sv_2pv)(pTHX_ SV*, STRLEN*);
# endif
+static char* (*Perl_sv_2pvbyte)(pTHX_ SV*, STRLEN*);
static SV* (*Perl_sv_bless)(pTHX_ SV*, HV*);
# if (PERL_REVISION == 5) && (PERL_VERSION >= 8)
static void (*Perl_sv_catpvn_flags)(pTHX_ SV* , const char*, STRLEN, I32);
@@ -543,6 +545,7 @@ static struct {
# else
{"Perl_sv_2pv", (PERL_PROC*)&Perl_sv_2pv},
# endif
+ {"Perl_sv_2pvbyte", (PERL_PROC*)&Perl_sv_2pvbyte},
# ifdef PERL589_OR_LATER
{"Perl_sv_2iv_flags", (PERL_PROC*)&Perl_sv_2iv_flags},
{"Perl_newXS_flags", (PERL_PROC*)&Perl_newXS_flags},
@@ -1556,6 +1559,27 @@ Eval(str)
vim_free(value);
}
+SV*
+Blob(SV* sv)
+ PREINIT:
+ STRLEN len;
+ char *s;
+ int i;
+ char buf[3];
+ SV* newsv;
+
+ CODE:
+ s = SvPVbyte(sv, len);
+ newsv = newSVpv("0z", 2);
+ for (i = 0; i < len; i++)
+ {
+ sprintf(buf, "%02X", s[i]);
+ sv_catpvn(newsv, buf, 2);
+ }
+ RETVAL = newsv;
+ OUTPUT:
+ RETVAL
+
void
Buffers(...)