diff options
author | Karl Williamson <khw@cpan.org> | 2017-10-31 12:11:12 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-11-06 12:50:05 -0700 |
commit | bdb7e3f0f6e41516d2c50d43e5f3f1373db014b0 (patch) | |
tree | e4df1a5eaccf25e2de3d8efc81351ab65659f79a | |
parent | f55ac4a45513e50ae06769ee748ea079c9577a7f (diff) | |
download | perl-bdb7e3f0f6e41516d2c50d43e5f3f1373db014b0.tar.gz |
Add memBEGINs(), memENDs() and use them in APItest
memBEGINs() is like strBEGINs(), but can be used for buffers without
trailing NULs. It can also be used when there is a trailing NUL, and
the length is known, as it should be somewhat faster, only having to
check for one ending condition.
Same for memENDs vs strENDs
-rw-r--r-- | ext/XS-APItest/APItest.xs | 13 | ||||
-rw-r--r-- | handy.h | 7 |
2 files changed, 14 insertions, 6 deletions
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 5dc1b27635..99a3957e6c 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -2312,6 +2312,7 @@ PREINIT: I32 retcnt; SV * errsv; char * errstr; + STRLEN errlen; SV * miscsv = sv_newmortal(); HV * hv = (HV*)sv_2mortal((SV*)newHV()); CODE: @@ -2345,8 +2346,8 @@ CODE: SPAGAIN; SP -= retcnt; errsv = ERRSV; - errstr = SvPV_nolen(errsv); - if(strBEGINs(errstr, "Undefined subroutine &main:: called at")) { + errstr = SvPV(errsv, errlen); + if(memBEGINs(errstr, errlen, "Undefined subroutine &main:: called at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -2357,8 +2358,8 @@ CODE: SPAGAIN; SP -= retcnt; errsv = ERRSV; - errstr = SvPV_nolen(errsv); - if(strBEGINs(errstr, "Can't use an undefined value as a subroutine reference at")) { + errstr = SvPV(errsv, errlen); + if(memBEGINs(errstr, errlen, "Can't use an undefined value as a subroutine reference at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -2369,8 +2370,8 @@ CODE: SPAGAIN; SP -= retcnt; errsv = ERRSV; - errstr = SvPV_nolen(errsv); - if(strBEGINs(errstr, "Not a CODE reference at")) { + errstr = SvPV(errsv, errlen); + if(memBEGINs(errstr, errlen, "Not a CODE reference at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -492,6 +492,13 @@ Returns zero if non-equal, or non-zero if equal. (memEQ((s1), ("" s2 ""), (sizeof(s2)-1))) #define _memNEs(s1, s2) (memNE((s1),("" s2 ""),(sizeof(s2)-1))) +#define memBEGINs(s1, l, s2) \ + ( (l) >= sizeof(s2) - 1 \ + && memEQ(s1, "" s2 "", sizeof(s2)-1)) +#define memENDs(s1, l, s2) \ + ( (l) >= sizeof(s2) - 1 \ + && memEQ(s1 + (l) - (sizeof(s2) - 1), "" s2 "", sizeof(s2)-1)) + #define memLT(s1,s2,l) (memcmp(s1,s2,l) < 0) #define memLE(s1,s2,l) (memcmp(s1,s2,l) <= 0) #define memGT(s1,s2,l) (memcmp(s1,s2,l) > 0) |