1 ################################################################################
3 ## Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
4 ## Version 2.x, Copyright (C) 2001, Paul Marquess.
5 ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
7 ## This program is free software; you can redistribute it and/or
8 ## modify it under the same terms as Perl itself.
10 ################################################################################
23 * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen().
26 __UNDEFINED__ sv_2pv_nolen(sv) SvPV_nolen(sv)
31 * Does not work in perl-5.6.1, ppport.h implements a version
32 * borrowed from perl-5.7.3.
35 #if { VERSION < 5.7.0 }
37 __UNDEFINED__ sv_2pvbyte(sv, lp) (sv_utf8_downgrade((sv), 0), SvPV((sv), *(lp)))
40 * Use the SvPVbyte() macro instead of sv_2pvbyte().
43 /* Replace sv_2pvbyte with SvPVbyte */
47 #define SvPVbyte(sv, lp) \
48 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
49 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
55 # define SvPVbyte SvPV
56 # define sv_2pvbyte sv_2pv
60 __UNDEFINED__ sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv)
63 * Always use the SvPV() macro instead of sv_pvn().
66 /* Replace sv_pvn with SvPV */
69 * Always use the SvPV_force() macro instead of sv_pvn_force().
72 /* Replace sv_pvn_force with SvPV_force */
74 /* If these are undefined, they're not handled by the core anyway */
75 __UNDEFINED__ SV_IMMEDIATE_UNREF 0
76 __UNDEFINED__ SV_GMAGIC 0
77 __UNDEFINED__ SV_COW_DROP_PV 0
78 __UNDEFINED__ SV_UTF8_NO_ENCODING 0
79 __UNDEFINED__ SV_CONST_RETURN 0
80 __UNDEFINED__ SV_MUTABLE_RETURN 0
81 __UNDEFINED__ SV_SMAGIC 0
82 __UNDEFINED__ SV_HAS_TRAILING_NUL 0
83 __UNDEFINED__ SV_COW_SHARED_HASH_KEYS 0
85 #if defined(PERL_USE_GCC_BRACE_GROUPS)
86 __UNDEFINED__ sv_2pv_flags(sv, lp, flags) ({ SV *_sv = (sv); const I32 _flags = (flags); STRLEN *_lp = lp; _lp = _lp ? : &PL_na; (!(_flags & SV_GMAGIC) && SvGMAGICAL(_sv)) ? ({ char *_pv; SvGMAGICAL_off(_sv); _pv = sv_2pv(_sv, _lp); SvGMAGICAL_on(_sv); _pv; }) : sv_2pv(_sv, _lp); })
87 __UNDEFINED__ sv_pvn_force_flags(sv, lp, flags) ({ SV *_sv = (sv); const I32 _flags = (flags); STRLEN *_lp = lp; _lp = _lp ? : &PL_na; (!(_flags & SV_GMAGIC) && SvGMAGICAL(_sv)) ? ({ char *_pv; SvGMAGICAL_off(_sv); _pv = sv_pvn_force(_sv, _lp); SvGMAGICAL_on(_sv); _pv; }) : sv_pvn_force(_sv, _lp); })
89 __UNDEFINED__ sv_2pv_flags(sv, lp, flags) ((PL_Sv = (sv)), (!((flags) & SV_GMAGIC) && SvGMAGICAL(PL_Sv)) ? (SvGMAGICAL_off(PL_Sv), (PL_Xpv = (XPV *)sv_2pv(PL_Sv, (lp) ? (lp) : &PL_na)), SvGMAGICAL_on(PL_Sv), (char *)PL_Xpv) : sv_2pv(PL_Sv, (lp) ? (lp) : &PL_na))
90 __UNDEFINED__ sv_pvn_force_flags(sv, lp, flags) ((PL_Sv = (sv)), (!((flags) & SV_GMAGIC) && SvGMAGICAL(PL_Sv)) ? (SvGMAGICAL_off(PL_Sv), (PL_Xpv = (XPV *)sv_pvn_force(PL_Sv, (lp) ? (lp) : &PL_na)), SvGMAGICAL_on(PL_Sv), (char *)PL_Xpv) : sv_pvn_force(PL_Sv, (lp) ? (lp) : &PL_na))
93 #if { VERSION < 5.8.8 } || ( { VERSION >= 5.9.0 } && { VERSION < 5.9.3 } )
94 # define D_PPP_SVPV_NOLEN_LP_ARG &PL_na
96 # define D_PPP_SVPV_NOLEN_LP_ARG 0
99 __UNDEFINED__ SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC)
100 __UNDEFINED__ SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC)
102 __UNDEFINED__ SvPV_flags(sv, lp, flags) \
103 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
104 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
106 __UNDEFINED__ SvPV_flags_const(sv, lp, flags) \
107 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
108 ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \
109 (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))
111 __UNDEFINED__ SvPV_flags_const_nolen(sv, flags) \
112 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
113 ? SvPVX_const(sv) : \
114 (const char*) sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN))
116 __UNDEFINED__ SvPV_flags_mutable(sv, lp, flags) \
117 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
118 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \
119 sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
121 __UNDEFINED__ SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
122 __UNDEFINED__ SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC)
123 __UNDEFINED__ SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)
124 __UNDEFINED__ SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
125 __UNDEFINED__ SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0)
127 __UNDEFINED__ SvPV_force_flags(sv, lp, flags) \
128 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
129 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
131 __UNDEFINED__ SvPV_force_flags_nolen(sv, flags) \
132 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
133 ? SvPVX(sv) : sv_pvn_force_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, flags))
135 __UNDEFINED__ SvPV_force_flags_mutable(sv, lp, flags) \
136 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
137 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \
138 : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
140 __UNDEFINED__ SvPV_nolen(sv) \
141 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
142 ? SvPVX(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC))
144 __UNDEFINED__ SvPV_nolen_const(sv) \
145 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
146 ? SvPVX_const(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN))
147 # if defined(PERL_USE_GCC_BRACE_GROUPS)
148 __UNDEFINED__ SvPVx_nolen_const(sv) ({SV *sV_ = (sv); SvPV_nolen_const(sV_); })
150 __UNDEFINED__ SvPVx_nolen_const(sv) (PL_Sv = sv, SvPV_nolen_const(PL_Sv))
153 __UNDEFINED__ SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
154 __UNDEFINED__ SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0)
155 __UNDEFINED__ SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)
156 __UNDEFINED__ SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
157 ? SvPVX(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, 0))
159 __UNDEFINED__ SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \
160 SvPV_set((sv), (char *) saferealloc( \
161 (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \
164 __UNDEFINED__ SvPVCLEAR(sv) sv_setpvs((sv), "")
175 str = SvPVbyte(sv, len);
176 RETVAL = strEQ(str, "mhx") ? (IV) len : (IV) -1;
186 str = SvPV_nolen(sv);
187 RETVAL = strEQ(str, "mhx") ? 42 : 0;
198 str = SvPV_const(sv, len);
199 RETVAL = len + (strEQ(str, "mhx") ? 40 : 0);
210 str = SvPV_mutable(sv, len);
211 RETVAL = len + (strEQ(str, "mhx") ? 41 : 0);
222 str = SvPV_flags(sv, len, SV_GMAGIC);
223 RETVAL = len + (strEQ(str, "mhx") ? 42 : 0);
234 str = SvPV_flags_const(sv, len, SV_GMAGIC);
235 RETVAL = len + (strEQ(str, "mhx") ? 43 : 0);
240 SvPV_flags_const_nolen(sv)
245 str = SvPV_flags_const_nolen(sv, SV_GMAGIC);
246 RETVAL = strEQ(str, "mhx") ? 47 : 0;
251 SvPV_flags_mutable(sv)
257 str = SvPV_flags_mutable(sv, len, SV_GMAGIC);
258 RETVAL = len + (strEQ(str, "mhx") ? 45 : 0);
269 str = SvPV_force(sv, len);
270 RETVAL = len + (strEQ(str, "mhx") ? 46 : 0);
280 str = SvPV_force_nolen(sv);
281 RETVAL = strEQ(str, "mhx") ? 50 : 0;
286 SvPV_force_mutable(sv)
292 str = SvPV_force_mutable(sv, len);
293 RETVAL = len + (strEQ(str, "mhx") ? 48 : 0);
304 str = SvPV_force_nomg(sv, len);
305 RETVAL = len + (strEQ(str, "mhx") ? 49 : 0);
310 SvPV_force_nomg_nolen(sv)
315 str = SvPV_force_nomg_nolen(sv);
316 RETVAL = strEQ(str, "mhx") ? 53 : 0;
327 str = SvPV_force_flags(sv, len, SV_GMAGIC);
328 RETVAL = len + (strEQ(str, "mhx") ? 51 : 0);
333 SvPV_force_flags_nolen(sv)
338 str = SvPV_force_flags_nolen(sv, SV_GMAGIC);
339 RETVAL = strEQ(str, "mhx") ? 55 : 0;
344 SvPV_force_flags_mutable(sv)
350 str = SvPV_force_flags_mutable(sv, len, SV_GMAGIC);
351 RETVAL = len + (strEQ(str, "mhx") ? 53 : 0);
361 str = SvPV_nolen_const(sv);
362 RETVAL = strEQ(str, "mhx") ? 57 : 0;
373 str = SvPV_nomg(sv, len);
374 RETVAL = len + (strEQ(str, "mhx") ? 55 : 0);
385 str = SvPV_nomg_const(sv, len);
386 RETVAL = len + (strEQ(str, "mhx") ? 56 : 0);
391 SvPV_nomg_const_nolen(sv)
396 str = SvPV_nomg_const_nolen(sv);
397 RETVAL = strEQ(str, "mhx") ? 60 : 0;
407 str = SvPV_nomg_nolen(sv);
408 RETVAL = strEQ(str, "mhx") ? 61 : 0;
413 SvPV_renew(sv, nlen, insv)
421 str = SvPV_const(insv, slen);
424 SvPV_renew(sv, nlen);
425 Copy(str, SvPVX(sv), slen + 1, char);
440 is(&Devel::PPPort::SvPVbyte($mhx), 3);
444 is(&Devel::PPPort::SvPV_nolen($mhx), $i++);
445 is(&Devel::PPPort::SvPV_const($mhx), $i++);
446 is(&Devel::PPPort::SvPV_mutable($mhx), $i++);
447 is(&Devel::PPPort::SvPV_flags($mhx), $i++);
448 is(&Devel::PPPort::SvPV_flags_const($mhx), $i++);
450 is(&Devel::PPPort::SvPV_flags_const_nolen($mhx), $i++);
451 is(&Devel::PPPort::SvPV_flags_mutable($mhx), $i++);
452 is(&Devel::PPPort::SvPV_force($mhx), $i++);
453 is(&Devel::PPPort::SvPV_force_nolen($mhx), $i++);
454 is(&Devel::PPPort::SvPV_force_mutable($mhx), $i++);
456 is(&Devel::PPPort::SvPV_force_nomg($mhx), $i++);
457 is(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), $i++);
458 is(&Devel::PPPort::SvPV_force_flags($mhx), $i++);
459 is(&Devel::PPPort::SvPV_force_flags_nolen($mhx), $i++);
460 is(&Devel::PPPort::SvPV_force_flags_mutable($mhx), $i++);
462 is(&Devel::PPPort::SvPV_nolen_const($mhx), $i++);
463 is(&Devel::PPPort::SvPV_nomg($mhx), $i++);
464 is(&Devel::PPPort::SvPV_nomg_const($mhx), $i++);
465 is(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), $i++);
466 is(&Devel::PPPort::SvPV_nomg_nolen($mhx), $i++);
468 $mhx = 42; is(&Devel::PPPort::SvPV_nolen($mhx), 0);
469 $mhx = 42; is(&Devel::PPPort::SvPV_const($mhx), 2);
470 $mhx = 42; is(&Devel::PPPort::SvPV_mutable($mhx), 2);
471 $mhx = 42; is(&Devel::PPPort::SvPV_flags($mhx), 2);
472 $mhx = 42; is(&Devel::PPPort::SvPV_flags_const($mhx), 2);
474 $mhx = 42; is(&Devel::PPPort::SvPV_flags_const_nolen($mhx), 0);
475 $mhx = 42; is(&Devel::PPPort::SvPV_flags_mutable($mhx), 2);
476 $mhx = 42; is(&Devel::PPPort::SvPV_force($mhx), 2);
477 $mhx = 42; is(&Devel::PPPort::SvPV_force_nolen($mhx), 0);
478 $mhx = 42; is(&Devel::PPPort::SvPV_force_mutable($mhx), 2);
480 $mhx = 42; is(&Devel::PPPort::SvPV_force_nomg($mhx), 2);
481 $mhx = 42; is(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), 0);
482 $mhx = 42; is(&Devel::PPPort::SvPV_force_flags($mhx), 2);
483 $mhx = 42; is(&Devel::PPPort::SvPV_force_flags_nolen($mhx), 0);
484 $mhx = 42; is(&Devel::PPPort::SvPV_force_flags_mutable($mhx), 2);
486 $mhx = 42; is(&Devel::PPPort::SvPV_nolen_const($mhx), 0);
487 $mhx = 42; is(&Devel::PPPort::SvPV_nomg($mhx), 2);
488 $mhx = 42; is(&Devel::PPPort::SvPV_nomg_const($mhx), 2);
489 $mhx = 42; is(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), 0);
490 $mhx = 42; is(&Devel::PPPort::SvPV_nomg_nolen($mhx), 0);
492 &Devel::PPPort::SvPVCLEAR($mhx);
496 &Devel::PPPort::SvPV_force($str);
497 my($s2, $before, $after) = &Devel::PPPort::SvPV_renew($str, 81, "x"x80);
504 &Devel::PPPort::SvPV_force($str);
505 ($s2, $before, $after) = &Devel::PPPort::SvPV_renew($str, 41, "x"x40);