Make expand-macro.pl accept macro expressions, i.e. macros with
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / SvPV
CommitLineData
adfe19db 1################################################################################
2##
8d2082b0 3## $Revision: 20 $
adfe19db 4## $Author: mhx $
8d2082b0 5## $Date: 2008/05/13 21:05:51 +0200 $
adfe19db 6##
7################################################################################
8##
c1a049cb 9## Version 3.x, Copyright (C) 2004-2008, Marcus Holland-Moritz.
adfe19db 10## Version 2.x, Copyright (C) 2001, Paul Marquess.
11## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12##
13## This program is free software; you can redistribute it and/or
14## modify it under the same terms as Perl itself.
15##
16################################################################################
17
18=provides
19
679ad62d 20__UNDEFINED__
adfe19db 21SvPVbyte
22sv_2pvbyte
679ad62d 23sv_2pv_flags
24sv_pvn_force_flags
adfe19db 25
679ad62d 26=dontwarn
adfe19db 27
679ad62d 28NEED_sv_2pv_flags
af36fda7 29NEED_sv_2pv_flags_GLOBAL
8d2082b0 30DPPP_SVPV_NOLEN_LP_ARG
adfe19db 31
679ad62d 32=implementation
adfe19db 33
679ad62d 34/* Backwards compatibility stuff... :-( */
35#if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen)
36# define NEED_sv_2pv_flags
37#endif
38#if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL)
39# define NEED_sv_2pv_flags_GLOBAL
adfe19db 40#endif
41
42/* Hint: sv_2pv_nolen
679ad62d 43 * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen().
adfe19db 44 */
45
679ad62d 46__UNDEFINED__ sv_2pv_nolen(sv) SvPV_nolen(sv)
adfe19db 47
48#ifdef SvPVbyte
49
50/* Hint: SvPVbyte
51 * Does not work in perl-5.6.1, ppport.h implements a version
52 * borrowed from perl-5.7.3.
53 */
54
55#if { VERSION < 5.7.0 }
56
57#if { NEED sv_2pvbyte }
58
59char *
aab9a3b6 60sv_2pvbyte(pTHX_ SV *sv, STRLEN *lp)
4a582685 61{
adfe19db 62 sv_utf8_downgrade(sv,0);
63 return SvPV(sv,*lp);
64}
65
66#endif
67
68/* Hint: sv_2pvbyte
69 * Use the SvPVbyte() macro instead of sv_2pvbyte().
70 */
71
72#undef SvPVbyte
73
adfe19db 74#define SvPVbyte(sv, lp) \
75 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
76 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
77
78#endif
79
80#else
81
82# define SvPVbyte SvPV
83# define sv_2pvbyte sv_2pv
84
85#endif
86
679ad62d 87__UNDEFINED__ sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv)
adfe19db 88
89/* Hint: sv_pvn
90 * Always use the SvPV() macro instead of sv_pvn().
91 */
adfe19db 92
04fc8b94 93/* Hint: sv_pvn_force
adfe19db 94 * Always use the SvPV_force() macro instead of sv_pvn_force().
95 */
adfe19db 96
679ad62d 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
108
109#if { VERSION < 5.7.2 }
110
111#if { NEED sv_2pv_flags }
112
113char *
114sv_2pv_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
115{
116 STRLEN n_a = (STRLEN) flags;
117 return sv_2pv(sv, lp ? lp : &n_a);
118}
119
120#endif
121
122#if { NEED sv_pvn_force_flags }
123
124char *
125sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
126{
127 STRLEN n_a = (STRLEN) flags;
128 return sv_pvn_force(sv, lp ? lp : &n_a);
129}
130
131#endif
132
133#endif
134
8d2082b0 135#if { VERSION < 5.8.8 } || ( { VERSION >= 5.9.0 } && { VERSION < 5.9.3 } )
136# define DPPP_SVPV_NOLEN_LP_ARG &PL_na
137#else
138# define DPPP_SVPV_NOLEN_LP_ARG 0
139#endif
140
679ad62d 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)
143
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))
147
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))
152
153__UNDEFINED__ SvPV_flags_const_nolen(sv, flags) \
154 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
155 ? SvPVX_const(sv) : \
8d2082b0 156 (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN))
679ad62d 157
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))
162
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)
168
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))
172
173__UNDEFINED__ SvPV_force_flags_nolen(sv, flags) \
174 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
8d2082b0 175 ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags))
679ad62d 176
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))
181
182__UNDEFINED__ SvPV_nolen(sv) \
183 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
8d2082b0 184 ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC))
679ad62d 185
186__UNDEFINED__ SvPV_nolen_const(sv) \
187 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
8d2082b0 188 ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN))
679ad62d 189
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)
193
adfe19db 194=xsinit
195
679ad62d 196#define NEED_sv_2pv_flags
197#define NEED_sv_pvn_force_flags
adfe19db 198#define NEED_sv_2pvbyte
199
200=xsubs
201
202IV
203SvPVbyte(sv)
204 SV *sv
205 PREINIT:
679ad62d 206 char *str;
adfe19db 207 STRLEN len;
adfe19db 208 CODE:
209 str = SvPVbyte(sv, len);
0d0f8426 210 RETVAL = strEQ(str, "mhx") ? (IV) len : (IV) -1;
adfe19db 211 OUTPUT:
212 RETVAL
213
214IV
215SvPV_nolen(sv)
216 SV *sv
217 PREINIT:
679ad62d 218 char *str;
adfe19db 219 CODE:
220 str = SvPV_nolen(sv);
9132e1a3 221 RETVAL = strEQ(str, "mhx") ? 42 : 0;
adfe19db 222 OUTPUT:
223 RETVAL
224
679ad62d 225IV
226SvPV_const(sv)
227 SV *sv
228 PREINIT:
229 const char *str;
230 STRLEN len;
231 CODE:
232 str = SvPV_const(sv, len);
233 RETVAL = len + (strEQ(str, "mhx") ? 40 : 0);
234 OUTPUT:
235 RETVAL
236
237IV
238SvPV_mutable(sv)
239 SV *sv
240 PREINIT:
241 char *str;
242 STRLEN len;
243 CODE:
244 str = SvPV_mutable(sv, len);
245 RETVAL = len + (strEQ(str, "mhx") ? 41 : 0);
246 OUTPUT:
247 RETVAL
248
249IV
250SvPV_flags(sv)
251 SV *sv
252 PREINIT:
253 char *str;
254 STRLEN len;
255 CODE:
256 str = SvPV_flags(sv, len, SV_GMAGIC);
257 RETVAL = len + (strEQ(str, "mhx") ? 42 : 0);
258 OUTPUT:
259 RETVAL
260
261IV
262SvPV_flags_const(sv)
263 SV *sv
264 PREINIT:
265 const char *str;
266 STRLEN len;
267 CODE:
268 str = SvPV_flags_const(sv, len, SV_GMAGIC);
269 RETVAL = len + (strEQ(str, "mhx") ? 43 : 0);
270 OUTPUT:
271 RETVAL
272
273IV
274SvPV_flags_const_nolen(sv)
275 SV *sv
276 PREINIT:
277 const char *str;
278 CODE:
279 str = SvPV_flags_const_nolen(sv, SV_GMAGIC);
280 RETVAL = strEQ(str, "mhx") ? 47 : 0;
281 OUTPUT:
282 RETVAL
283
284IV
285SvPV_flags_mutable(sv)
286 SV *sv
287 PREINIT:
288 char *str;
289 STRLEN len;
290 CODE:
291 str = SvPV_flags_mutable(sv, len, SV_GMAGIC);
292 RETVAL = len + (strEQ(str, "mhx") ? 45 : 0);
293 OUTPUT:
294 RETVAL
295
296IV
297SvPV_force(sv)
298 SV *sv
299 PREINIT:
300 char *str;
301 STRLEN len;
302 CODE:
303 str = SvPV_force(sv, len);
304 RETVAL = len + (strEQ(str, "mhx") ? 46 : 0);
305 OUTPUT:
306 RETVAL
307
308IV
309SvPV_force_nolen(sv)
310 SV *sv
311 PREINIT:
312 char *str;
313 CODE:
314 str = SvPV_force_nolen(sv);
315 RETVAL = strEQ(str, "mhx") ? 50 : 0;
316 OUTPUT:
317 RETVAL
318
319IV
320SvPV_force_mutable(sv)
321 SV *sv
322 PREINIT:
323 char *str;
324 STRLEN len;
325 CODE:
326 str = SvPV_force_mutable(sv, len);
327 RETVAL = len + (strEQ(str, "mhx") ? 48 : 0);
328 OUTPUT:
329 RETVAL
330
331IV
332SvPV_force_nomg(sv)
333 SV *sv
334 PREINIT:
335 char *str;
336 STRLEN len;
337 CODE:
338 str = SvPV_force_nomg(sv, len);
339 RETVAL = len + (strEQ(str, "mhx") ? 49 : 0);
340 OUTPUT:
341 RETVAL
342
343IV
344SvPV_force_nomg_nolen(sv)
345 SV *sv
346 PREINIT:
347 char *str;
348 CODE:
349 str = SvPV_force_nomg_nolen(sv);
350 RETVAL = strEQ(str, "mhx") ? 53 : 0;
351 OUTPUT:
352 RETVAL
353
354IV
355SvPV_force_flags(sv)
356 SV *sv
357 PREINIT:
358 char *str;
359 STRLEN len;
360 CODE:
361 str = SvPV_force_flags(sv, len, SV_GMAGIC);
362 RETVAL = len + (strEQ(str, "mhx") ? 51 : 0);
363 OUTPUT:
364 RETVAL
365
366IV
367SvPV_force_flags_nolen(sv)
368 SV *sv
369 PREINIT:
370 char *str;
371 CODE:
372 str = SvPV_force_flags_nolen(sv, SV_GMAGIC);
373 RETVAL = strEQ(str, "mhx") ? 55 : 0;
374 OUTPUT:
375 RETVAL
376
377IV
378SvPV_force_flags_mutable(sv)
379 SV *sv
380 PREINIT:
381 char *str;
382 STRLEN len;
383 CODE:
384 str = SvPV_force_flags_mutable(sv, len, SV_GMAGIC);
385 RETVAL = len + (strEQ(str, "mhx") ? 53 : 0);
386 OUTPUT:
387 RETVAL
388
389IV
390SvPV_nolen_const(sv)
391 SV *sv
392 PREINIT:
393 const char *str;
394 CODE:
395 str = SvPV_nolen_const(sv);
396 RETVAL = strEQ(str, "mhx") ? 57 : 0;
397 OUTPUT:
398 RETVAL
399
400IV
401SvPV_nomg(sv)
402 SV *sv
403 PREINIT:
404 char *str;
405 STRLEN len;
406 CODE:
407 str = SvPV_nomg(sv, len);
408 RETVAL = len + (strEQ(str, "mhx") ? 55 : 0);
409 OUTPUT:
410 RETVAL
411
412IV
413SvPV_nomg_const(sv)
414 SV *sv
415 PREINIT:
416 const char *str;
417 STRLEN len;
418 CODE:
419 str = SvPV_nomg_const(sv, len);
420 RETVAL = len + (strEQ(str, "mhx") ? 56 : 0);
421 OUTPUT:
422 RETVAL
423
424IV
425SvPV_nomg_const_nolen(sv)
426 SV *sv
427 PREINIT:
428 const char *str;
429 CODE:
430 str = SvPV_nomg_const_nolen(sv);
431 RETVAL = strEQ(str, "mhx") ? 60 : 0;
432 OUTPUT:
433 RETVAL
434
435
8d2082b0 436=tests plan => 39
679ad62d 437
438my $mhx = "mhx";
439
440ok(&Devel::PPPort::SvPVbyte($mhx), 3);
441
442my $i = 42;
443
444ok(&Devel::PPPort::SvPV_nolen($mhx), $i++);
445ok(&Devel::PPPort::SvPV_const($mhx), $i++);
446ok(&Devel::PPPort::SvPV_mutable($mhx), $i++);
447ok(&Devel::PPPort::SvPV_flags($mhx), $i++);
448ok(&Devel::PPPort::SvPV_flags_const($mhx), $i++);
449
450ok(&Devel::PPPort::SvPV_flags_const_nolen($mhx), $i++);
451ok(&Devel::PPPort::SvPV_flags_mutable($mhx), $i++);
452ok(&Devel::PPPort::SvPV_force($mhx), $i++);
453ok(&Devel::PPPort::SvPV_force_nolen($mhx), $i++);
454ok(&Devel::PPPort::SvPV_force_mutable($mhx), $i++);
455
456ok(&Devel::PPPort::SvPV_force_nomg($mhx), $i++);
457ok(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), $i++);
458ok(&Devel::PPPort::SvPV_force_flags($mhx), $i++);
459ok(&Devel::PPPort::SvPV_force_flags_nolen($mhx), $i++);
460ok(&Devel::PPPort::SvPV_force_flags_mutable($mhx), $i++);
adfe19db 461
679ad62d 462ok(&Devel::PPPort::SvPV_nolen_const($mhx), $i++);
463ok(&Devel::PPPort::SvPV_nomg($mhx), $i++);
464ok(&Devel::PPPort::SvPV_nomg_const($mhx), $i++);
465ok(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), $i++);
adfe19db 466
8d2082b0 467$mhx = 42; ok(&Devel::PPPort::SvPV_nolen($mhx), 0);
468$mhx = 42; ok(&Devel::PPPort::SvPV_const($mhx), 2);
469$mhx = 42; ok(&Devel::PPPort::SvPV_mutable($mhx), 2);
470$mhx = 42; ok(&Devel::PPPort::SvPV_flags($mhx), 2);
471$mhx = 42; ok(&Devel::PPPort::SvPV_flags_const($mhx), 2);
472
473$mhx = 42; ok(&Devel::PPPort::SvPV_flags_const_nolen($mhx), 0);
474$mhx = 42; ok(&Devel::PPPort::SvPV_flags_mutable($mhx), 2);
475$mhx = 42; ok(&Devel::PPPort::SvPV_force($mhx), 2);
476$mhx = 42; ok(&Devel::PPPort::SvPV_force_nolen($mhx), 0);
477$mhx = 42; ok(&Devel::PPPort::SvPV_force_mutable($mhx), 2);
478
479$mhx = 42; ok(&Devel::PPPort::SvPV_force_nomg($mhx), 2);
480$mhx = 42; ok(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), 0);
481$mhx = 42; ok(&Devel::PPPort::SvPV_force_flags($mhx), 2);
482$mhx = 42; ok(&Devel::PPPort::SvPV_force_flags_nolen($mhx), 0);
483$mhx = 42; ok(&Devel::PPPort::SvPV_force_flags_mutable($mhx), 2);
484
485$mhx = 42; ok(&Devel::PPPort::SvPV_nolen_const($mhx), 0);
486$mhx = 42; ok(&Devel::PPPort::SvPV_nomg($mhx), 2);
487$mhx = 42; ok(&Devel::PPPort::SvPV_nomg_const($mhx), 2);
488$mhx = 42; ok(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), 0);
489