1 ################################################################################
5 ## $Date: 2009/01/18 14:10:54 +0100 $
7 ################################################################################
9 ## Version 3.x, Copyright (C) 2004-2009, Marcus Holland-Moritz.
10 ## Version 2.x, Copyright (C) 2001, Paul Marquess.
11 ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
13 ## This program is free software; you can redistribute it and/or
14 ## modify it under the same terms as Perl itself.
16 ################################################################################
29 NEED_sv_2pv_flags_GLOBAL
30 DPPP_SVPV_NOLEN_LP_ARG
34 /* Backwards compatibility stuff... :-( */
35 #if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen)
36 # define NEED_sv_2pv_flags
38 #if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL)
39 # define NEED_sv_2pv_flags_GLOBAL
43 * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen().
46 __UNDEFINED__ sv_2pv_nolen(sv) SvPV_nolen(sv)
51 * Does not work in perl-5.6.1, ppport.h implements a version
52 * borrowed from perl-5.7.3.
55 #if { VERSION < 5.7.0 }
57 #if { NEED sv_2pvbyte }
60 sv_2pvbyte(pTHX_ SV *sv, STRLEN *lp)
62 sv_utf8_downgrade(sv,0);
69 * Use the SvPVbyte() macro instead of sv_2pvbyte().
74 #define SvPVbyte(sv, lp) \
75 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
76 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
82 # define SvPVbyte SvPV
83 # define sv_2pvbyte sv_2pv
87 __UNDEFINED__ sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv)
90 * Always use the SvPV() macro instead of sv_pvn().
94 * Always use the SvPV_force() macro instead of sv_pvn_force().
97 /* If these are undefined, they're not handled by the core anyway */
98 __UNDEFINED__ SV_IMMEDIATE_UNREF 0
99 __UNDEFINED__ SV_GMAGIC 0
100 __UNDEFINED__ SV_COW_DROP_PV 0
101 __UNDEFINED__ SV_UTF8_NO_ENCODING 0
102 __UNDEFINED__ SV_NOSTEAL 0
103 __UNDEFINED__ SV_CONST_RETURN 0
104 __UNDEFINED__ SV_MUTABLE_RETURN 0
105 __UNDEFINED__ SV_SMAGIC 0
106 __UNDEFINED__ SV_HAS_TRAILING_NUL 0
107 __UNDEFINED__ SV_COW_SHARED_HASH_KEYS 0
109 #if { VERSION < 5.7.2 }
111 #if { NEED sv_2pv_flags }
114 sv_2pv_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
116 STRLEN n_a = (STRLEN) flags;
117 return sv_2pv(sv, lp ? lp : &n_a);
122 #if { NEED sv_pvn_force_flags }
125 sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
127 STRLEN n_a = (STRLEN) flags;
128 return sv_pvn_force(sv, lp ? lp : &n_a);
135 #if { VERSION < 5.8.8 } || ( { VERSION >= 5.9.0 } && { VERSION < 5.9.3 } )
136 # define DPPP_SVPV_NOLEN_LP_ARG &PL_na
138 # define DPPP_SVPV_NOLEN_LP_ARG 0
141 __UNDEFINED__ SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC)
142 __UNDEFINED__ SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC)
144 __UNDEFINED__ SvPV_flags(sv, lp, flags) \
145 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
146 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
148 __UNDEFINED__ SvPV_flags_const(sv, lp, flags) \
149 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
150 ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \
151 (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))
153 __UNDEFINED__ SvPV_flags_const_nolen(sv, flags) \
154 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
155 ? SvPVX_const(sv) : \
156 (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN))
158 __UNDEFINED__ SvPV_flags_mutable(sv, lp, flags) \
159 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
160 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \
161 sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
163 __UNDEFINED__ SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
164 __UNDEFINED__ SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC)
165 __UNDEFINED__ SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)
166 __UNDEFINED__ SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
167 __UNDEFINED__ SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0)
169 __UNDEFINED__ SvPV_force_flags(sv, lp, flags) \
170 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
171 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
173 __UNDEFINED__ SvPV_force_flags_nolen(sv, flags) \
174 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
175 ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags))
177 __UNDEFINED__ SvPV_force_flags_mutable(sv, lp, flags) \
178 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
179 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \
180 : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
182 __UNDEFINED__ SvPV_nolen(sv) \
183 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
184 ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC))
186 __UNDEFINED__ SvPV_nolen_const(sv) \
187 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
188 ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN))
190 __UNDEFINED__ SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
191 __UNDEFINED__ SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0)
192 __UNDEFINED__ SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)
194 __UNDEFINED__ SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \
195 SvPV_set((sv), (char *) saferealloc( \
196 (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \
201 #define NEED_sv_2pv_flags
202 #define NEED_sv_pvn_force_flags
203 #define NEED_sv_2pvbyte
214 str = SvPVbyte(sv, len);
215 RETVAL = strEQ(str, "mhx") ? (IV) len : (IV) -1;
225 str = SvPV_nolen(sv);
226 RETVAL = strEQ(str, "mhx") ? 42 : 0;
237 str = SvPV_const(sv, len);
238 RETVAL = len + (strEQ(str, "mhx") ? 40 : 0);
249 str = SvPV_mutable(sv, len);
250 RETVAL = len + (strEQ(str, "mhx") ? 41 : 0);
261 str = SvPV_flags(sv, len, SV_GMAGIC);
262 RETVAL = len + (strEQ(str, "mhx") ? 42 : 0);
273 str = SvPV_flags_const(sv, len, SV_GMAGIC);
274 RETVAL = len + (strEQ(str, "mhx") ? 43 : 0);
279 SvPV_flags_const_nolen(sv)
284 str = SvPV_flags_const_nolen(sv, SV_GMAGIC);
285 RETVAL = strEQ(str, "mhx") ? 47 : 0;
290 SvPV_flags_mutable(sv)
296 str = SvPV_flags_mutable(sv, len, SV_GMAGIC);
297 RETVAL = len + (strEQ(str, "mhx") ? 45 : 0);
308 str = SvPV_force(sv, len);
309 RETVAL = len + (strEQ(str, "mhx") ? 46 : 0);
319 str = SvPV_force_nolen(sv);
320 RETVAL = strEQ(str, "mhx") ? 50 : 0;
325 SvPV_force_mutable(sv)
331 str = SvPV_force_mutable(sv, len);
332 RETVAL = len + (strEQ(str, "mhx") ? 48 : 0);
343 str = SvPV_force_nomg(sv, len);
344 RETVAL = len + (strEQ(str, "mhx") ? 49 : 0);
349 SvPV_force_nomg_nolen(sv)
354 str = SvPV_force_nomg_nolen(sv);
355 RETVAL = strEQ(str, "mhx") ? 53 : 0;
366 str = SvPV_force_flags(sv, len, SV_GMAGIC);
367 RETVAL = len + (strEQ(str, "mhx") ? 51 : 0);
372 SvPV_force_flags_nolen(sv)
377 str = SvPV_force_flags_nolen(sv, SV_GMAGIC);
378 RETVAL = strEQ(str, "mhx") ? 55 : 0;
383 SvPV_force_flags_mutable(sv)
389 str = SvPV_force_flags_mutable(sv, len, SV_GMAGIC);
390 RETVAL = len + (strEQ(str, "mhx") ? 53 : 0);
400 str = SvPV_nolen_const(sv);
401 RETVAL = strEQ(str, "mhx") ? 57 : 0;
412 str = SvPV_nomg(sv, len);
413 RETVAL = len + (strEQ(str, "mhx") ? 55 : 0);
424 str = SvPV_nomg_const(sv, len);
425 RETVAL = len + (strEQ(str, "mhx") ? 56 : 0);
430 SvPV_nomg_const_nolen(sv)
435 str = SvPV_nomg_const_nolen(sv);
436 RETVAL = strEQ(str, "mhx") ? 60 : 0;
441 SvPV_renew(sv, nlen, insv)
449 str = SvPV_const(insv, slen);
452 SvPV_renew(sv, nlen);
453 Copy(str, SvPVX(sv), slen + 1, char);
462 ok(&Devel::PPPort::SvPVbyte($mhx), 3);
466 ok(&Devel::PPPort::SvPV_nolen($mhx), $i++);
467 ok(&Devel::PPPort::SvPV_const($mhx), $i++);
468 ok(&Devel::PPPort::SvPV_mutable($mhx), $i++);
469 ok(&Devel::PPPort::SvPV_flags($mhx), $i++);
470 ok(&Devel::PPPort::SvPV_flags_const($mhx), $i++);
472 ok(&Devel::PPPort::SvPV_flags_const_nolen($mhx), $i++);
473 ok(&Devel::PPPort::SvPV_flags_mutable($mhx), $i++);
474 ok(&Devel::PPPort::SvPV_force($mhx), $i++);
475 ok(&Devel::PPPort::SvPV_force_nolen($mhx), $i++);
476 ok(&Devel::PPPort::SvPV_force_mutable($mhx), $i++);
478 ok(&Devel::PPPort::SvPV_force_nomg($mhx), $i++);
479 ok(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), $i++);
480 ok(&Devel::PPPort::SvPV_force_flags($mhx), $i++);
481 ok(&Devel::PPPort::SvPV_force_flags_nolen($mhx), $i++);
482 ok(&Devel::PPPort::SvPV_force_flags_mutable($mhx), $i++);
484 ok(&Devel::PPPort::SvPV_nolen_const($mhx), $i++);
485 ok(&Devel::PPPort::SvPV_nomg($mhx), $i++);
486 ok(&Devel::PPPort::SvPV_nomg_const($mhx), $i++);
487 ok(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), $i++);
489 $mhx = 42; ok(&Devel::PPPort::SvPV_nolen($mhx), 0);
490 $mhx = 42; ok(&Devel::PPPort::SvPV_const($mhx), 2);
491 $mhx = 42; ok(&Devel::PPPort::SvPV_mutable($mhx), 2);
492 $mhx = 42; ok(&Devel::PPPort::SvPV_flags($mhx), 2);
493 $mhx = 42; ok(&Devel::PPPort::SvPV_flags_const($mhx), 2);
495 $mhx = 42; ok(&Devel::PPPort::SvPV_flags_const_nolen($mhx), 0);
496 $mhx = 42; ok(&Devel::PPPort::SvPV_flags_mutable($mhx), 2);
497 $mhx = 42; ok(&Devel::PPPort::SvPV_force($mhx), 2);
498 $mhx = 42; ok(&Devel::PPPort::SvPV_force_nolen($mhx), 0);
499 $mhx = 42; ok(&Devel::PPPort::SvPV_force_mutable($mhx), 2);
501 $mhx = 42; ok(&Devel::PPPort::SvPV_force_nomg($mhx), 2);
502 $mhx = 42; ok(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), 0);
503 $mhx = 42; ok(&Devel::PPPort::SvPV_force_flags($mhx), 2);
504 $mhx = 42; ok(&Devel::PPPort::SvPV_force_flags_nolen($mhx), 0);
505 $mhx = 42; ok(&Devel::PPPort::SvPV_force_flags_mutable($mhx), 2);
507 $mhx = 42; ok(&Devel::PPPort::SvPV_nolen_const($mhx), 0);
508 $mhx = 42; ok(&Devel::PPPort::SvPV_nomg($mhx), 2);
509 $mhx = 42; ok(&Devel::PPPort::SvPV_nomg_const($mhx), 2);
510 $mhx = 42; ok(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), 0);
513 my($s2, $before, $after) = &Devel::PPPort::SvPV_renew($str, 81, "x"x80);
520 ($s2, $before, $after) = &Devel::PPPort::SvPV_renew($str, 41, "x"x40);