This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Abolish cop_io (the simple way) by storing the value in cop_hints_hash.
[perl5.git] / ext / Devel / PPPort / parts / inc / misc
CommitLineData
adfe19db
MHM
1################################################################################
2##
0d0f8426 3## $Revision: 30 $
adfe19db 4## $Author: mhx $
0d0f8426 5## $Date: 2006/01/14 18:08:03 +0100 $
adfe19db
MHM
6##
7################################################################################
8##
0d0f8426 9## Version 3.x, Copyright (C) 2004-2006, Marcus Holland-Moritz.
adfe19db
MHM
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
20__UNDEFINED__
21PERL_UNUSED_DECL
a745474a 22PERL_GCC_BRACE_GROUPS_FORBIDDEN
adfe19db
MHM
23NVTYPE
24INT2PTR
25PTRV
26NUM2PTR
27PTR2IV
28PTR2UV
29PTR2NV
30PTR2ul
a745474a
MHM
31START_EXTERN_C
32END_EXTERN_C
33EXTERN_C
34STMT_START
35STMT_END
0d0f8426 36XSRETURN
adfe19db
MHM
37/PL_\w+/
38
39=implementation
40
0d0f8426 41#if { VERSION <= 5.004_05 }
adfe19db 42/* Replace: 1 */
96ad942f
MHM
43# define PL_DBsingle DBsingle
44# define PL_DBsub DBsub
45# define PL_Sv Sv
46# define PL_compiling compiling
47# define PL_copline copline
48# define PL_curcop curcop
49# define PL_curstash curstash
50# define PL_debstash debstash
51# define PL_defgv defgv
52# define PL_diehook diehook
53# define PL_dirty dirty
54# define PL_dowarn dowarn
55# define PL_errgv errgv
56# define PL_hexdigit hexdigit
57# define PL_hints hints
58# define PL_na na
59# define PL_no_modify no_modify
60# define PL_perl_destruct_level perl_destruct_level
61# define PL_perldb perldb
62# define PL_ppaddr ppaddr
63# define PL_rsfp_filters rsfp_filters
64# define PL_rsfp rsfp
65# define PL_stack_base stack_base
66# define PL_stack_sp stack_sp
67# define PL_stdingv stdingv
68# define PL_sv_arenaroot sv_arenaroot
69# define PL_sv_no sv_no
70# define PL_sv_undef sv_undef
71# define PL_sv_yes sv_yes
72# define PL_tainted tainted
73# define PL_tainting tainting
adfe19db
MHM
74/* Replace: 0 */
75#endif
76
62093c1c
NC
77#ifndef PERL_UNUSED_DECL
78# ifdef HASATTRIBUTE
79# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
80# define PERL_UNUSED_DECL
81# else
82# define PERL_UNUSED_DECL __attribute__((unused))
83# endif
adfe19db 84# else
62093c1c 85# define PERL_UNUSED_DECL
adfe19db 86# endif
adfe19db
MHM
87#endif
88
89__UNDEFINED__ NOOP (void)0
90__UNDEFINED__ dNOOP extern int Perl___notused PERL_UNUSED_DECL
91
92#ifndef NVTYPE
93# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
94# define NVTYPE long double
95# else
96# define NVTYPE double
97# endif
98typedef NVTYPE NV;
99#endif
100
101#ifndef INT2PTR
102
103# if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
104# define PTRV UV
105# define INT2PTR(any,d) (any)(d)
106# else
107# if PTRSIZE == LONGSIZE
108# define PTRV unsigned long
109# else
110# define PTRV unsigned
111# endif
112# define INT2PTR(any,d) (any)(PTRV)(d)
113# endif
114
115# define NUM2PTR(any,d) (any)(PTRV)(d)
116# define PTR2IV(p) INT2PTR(IV,p)
117# define PTR2UV(p) INT2PTR(UV,p)
118# define PTR2NV(p) NUM2PTR(NV,p)
119
120# if PTRSIZE == LONGSIZE
121# define PTR2ul(p) (unsigned long)(p)
122# else
4a582685 123# define PTR2ul(p) INT2PTR(unsigned long,p)
adfe19db
MHM
124# endif
125
126#endif /* !INT2PTR */
127
a745474a
MHM
128#undef START_EXTERN_C
129#undef END_EXTERN_C
130#undef EXTERN_C
131#ifdef __cplusplus
132# define START_EXTERN_C extern "C" {
133# define END_EXTERN_C }
134# define EXTERN_C extern "C"
135#else
136# define START_EXTERN_C
137# define END_EXTERN_C
138# define EXTERN_C extern
139#endif
140
141#ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
142# if defined(__STRICT_ANSI__) && defined(PERL_GCC_PEDANTIC)
143# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
144# endif
145#endif
146
147#undef STMT_START
148#undef STMT_END
149#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
150# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
151# define STMT_END )
152#else
153# if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
154# define STMT_START if (1)
155# define STMT_END else (void)0
156# else
157# define STMT_START do
158# define STMT_END while (0)
159# endif
160#endif
161
adfe19db
MHM
162__UNDEFINED__ boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
163
164/* DEFSV appears first in 5.004_56 */
165__UNDEFINED__ DEFSV GvSV(PL_defgv)
166__UNDEFINED__ SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
167
168/* Older perls (<=5.003) lack AvFILLp */
169__UNDEFINED__ AvFILLp AvFILL
170
171__UNDEFINED__ ERRSV get_sv("@",FALSE)
172
173__UNDEFINED__ newSVpvn(data,len) ((data) \
174 ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \
175 : newSV(0))
176
177/* Hint: gv_stashpvn
178 * This function's backport doesn't support the length parameter, but
179 * rather ignores it. Portability can only be ensured if the length
180 * parameter is used for speed reasons, but the length can always be
181 * correctly computed from the string argument.
182 */
183
184__UNDEFINED__ gv_stashpvn(str,len,create) gv_stashpv(str,create)
185
186/* Replace: 1 */
187__UNDEFINED__ get_cv perl_get_cv
188__UNDEFINED__ get_sv perl_get_sv
189__UNDEFINED__ get_av perl_get_av
190__UNDEFINED__ get_hv perl_get_hv
191/* Replace: 0 */
192
adfe19db
MHM
193__UNDEFINED__ dUNDERBAR dNOOP
194__UNDEFINED__ UNDERBAR DEFSV
195
196__UNDEFINED__ dAX I32 ax = MARK - PL_stack_base + 1
197__UNDEFINED__ dITEMS I32 items = SP - MARK
198
9132e1a3
MHM
199__UNDEFINED__ dXSTARG SV * targ = sv_newmortal()
200
0d0f8426
MHM
201__UNDEFINED__ dAXMARK I32 ax = POPMARK; \
202 register SV ** const mark = PL_stack_base + ax++
203
204
205__UNDEFINED__ XSprePUSH (sp = PL_stack_base + ax - 1)
206
207#if { VERSION < 5.005 }
208# undef XSRETURN
209# define XSRETURN(off) \
210 STMT_START { \
211 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
212 return; \
213 } STMT_END
214#endif
215
9132e1a3
MHM
216=xsmisc
217
218XS(XS_Devel__PPPort_dXSTARG); /* prototype */
219XS(XS_Devel__PPPort_dXSTARG)
220{
221 dXSARGS;
222 dXSTARG;
2dd69576 223 IV iv;
9132e1a3 224 SP -= items;
2dd69576 225 iv = SvIV(ST(0)) + 1;
9132e1a3
MHM
226 PUSHi(iv);
227 XSRETURN(1);
228}
229
0d0f8426
MHM
230XS(XS_Devel__PPPort_dAXMARK); /* prototype */
231XS(XS_Devel__PPPort_dAXMARK)
232{
233 dSP;
234 dAXMARK;
235 dITEMS;
236 IV iv;
237 SP -= items;
238 iv = SvIV(ST(0)) - 1;
239 PUSHs(sv_2mortal(newSViv(iv)));
240 XSRETURN(1);
241}
242
9132e1a3
MHM
243=xsboot
244
245newXS("Devel::PPPort::dXSTARG", XS_Devel__PPPort_dXSTARG, file);
0d0f8426 246newXS("Devel::PPPort::dAXMARK", XS_Devel__PPPort_dAXMARK, file);
9132e1a3 247
adfe19db
MHM
248=xsubs
249
250int
251gv_stashpvn(name, create)
252 char *name
253 I32 create
254 CODE:
255 RETVAL = gv_stashpvn(name, strlen(name), create) != NULL;
256 OUTPUT:
257 RETVAL
258
259int
260get_sv(name, create)
261 char *name
262 I32 create
263 CODE:
264 RETVAL = get_sv(name, create) != NULL;
265 OUTPUT:
266 RETVAL
267
268int
269get_av(name, create)
270 char *name
271 I32 create
272 CODE:
273 RETVAL = get_av(name, create) != NULL;
274 OUTPUT:
275 RETVAL
276
277int
278get_hv(name, create)
279 char *name
280 I32 create
281 CODE:
282 RETVAL = get_hv(name, create) != NULL;
283 OUTPUT:
284 RETVAL
285
286int
287get_cv(name, create)
288 char *name
289 I32 create
290 CODE:
291 RETVAL = get_cv(name, create) != NULL;
292 OUTPUT:
293 RETVAL
294
295void
296newSVpvn()
297 PPCODE:
298 XPUSHs(newSVpvn("test", 4));
299 XPUSHs(newSVpvn("test", 2));
300 XPUSHs(newSVpvn("test", 0));
301 XPUSHs(newSVpvn(NULL, 2));
302 XPUSHs(newSVpvn(NULL, 0));
303 XSRETURN(5);
304
0d0f8426
MHM
305void
306xsreturn(two)
307 int two
308 PPCODE:
309 XPUSHs(newSVpvn("test1", 5));
310 if (two)
311 XPUSHs(newSVpvn("test2", 5));
312 if (two)
313 XSRETURN(2);
314 else
315 XSRETURN(1);
316
adfe19db
MHM
317SV *
318PL_sv_undef()
319 CODE:
320 RETVAL = newSVsv(&PL_sv_undef);
321 OUTPUT:
322 RETVAL
323
324SV *
325PL_sv_yes()
326 CODE:
327 RETVAL = newSVsv(&PL_sv_yes);
328 OUTPUT:
329 RETVAL
330
331SV *
332PL_sv_no()
333 CODE:
334 RETVAL = newSVsv(&PL_sv_no);
335 OUTPUT:
336 RETVAL
337
338int
339PL_na(string)
340 char *string
341 CODE:
342 PL_na = strlen(string);
343 RETVAL = PL_na;
344 OUTPUT:
345 RETVAL
346
347SV*
348boolSV(value)
349 int value
350 CODE:
351 RETVAL = newSVsv(boolSV(value));
352 OUTPUT:
353 RETVAL
354
355SV*
356DEFSV()
357 CODE:
358 RETVAL = newSVsv(DEFSV);
359 OUTPUT:
360 RETVAL
361
362int
363ERRSV()
364 CODE:
365 RETVAL = SvTRUE(ERRSV);
366 OUTPUT:
367 RETVAL
368
369SV*
370UNDERBAR()
371 CODE:
372 {
373 dUNDERBAR;
374 RETVAL = newSVsv(UNDERBAR);
375 }
376 OUTPUT:
377 RETVAL
378
0d0f8426
MHM
379void
380prepush()
381 CODE:
382 {
383 dXSTARG;
384 XSprePUSH;
385 PUSHi(42);
386 XSRETURN(1);
387 }
388
389=tests plan => 38
adfe19db
MHM
390
391use vars qw($my_sv @my_av %my_hv);
392
393my @s = &Devel::PPPort::newSVpvn();
394ok(@s == 5);
395ok($s[0], "test");
396ok($s[1], "te");
397ok($s[2], "");
398ok(!defined($s[3]));
399ok(!defined($s[4]));
400
401ok(!defined(&Devel::PPPort::PL_sv_undef()));
402ok(&Devel::PPPort::PL_sv_yes());
403ok(!&Devel::PPPort::PL_sv_no());
404ok(&Devel::PPPort::PL_na("abcd"), 4);
405
406ok(&Devel::PPPort::boolSV(1));
407ok(!&Devel::PPPort::boolSV(0));
408
409$_ = "Fred";
410ok(&Devel::PPPort::DEFSV(), "Fred");
411ok(&Devel::PPPort::UNDERBAR(), "Fred");
412
0d0f8426
MHM
413if ($] >= 5.009002) {
414 eval q{
415 my $_ = "Tony";
416 ok(&Devel::PPPort::DEFSV(), "Fred");
417 ok(&Devel::PPPort::UNDERBAR(), "Tony");
418 };
419}
420else {
421 ok(1);
422 ok(1);
423}
424
adfe19db
MHM
425eval { 1 };
426ok(!&Devel::PPPort::ERRSV());
427eval { cannot_call_this_one() };
428ok(&Devel::PPPort::ERRSV());
429
430ok(&Devel::PPPort::gv_stashpvn('Devel::PPPort', 0));
431ok(!&Devel::PPPort::gv_stashpvn('does::not::exist', 0));
432ok(&Devel::PPPort::gv_stashpvn('does::not::exist', 1));
433
434$my_sv = 1;
435ok(&Devel::PPPort::get_sv('my_sv', 0));
436ok(!&Devel::PPPort::get_sv('not_my_sv', 0));
437ok(&Devel::PPPort::get_sv('not_my_sv', 1));
438
439@my_av = (1);
440ok(&Devel::PPPort::get_av('my_av', 0));
441ok(!&Devel::PPPort::get_av('not_my_av', 0));
442ok(&Devel::PPPort::get_av('not_my_av', 1));
443
444%my_hv = (a=>1);
445ok(&Devel::PPPort::get_hv('my_hv', 0));
446ok(!&Devel::PPPort::get_hv('not_my_hv', 0));
447ok(&Devel::PPPort::get_hv('not_my_hv', 1));
448
449sub my_cv { 1 };
450ok(&Devel::PPPort::get_cv('my_cv', 0));
451ok(!&Devel::PPPort::get_cv('not_my_cv', 0));
452ok(&Devel::PPPort::get_cv('not_my_cv', 1));
453
9132e1a3 454ok(Devel::PPPort::dXSTARG(42), 43);
0d0f8426
MHM
455ok(Devel::PPPort::dAXMARK(4711), 4710);
456
457ok(Devel::PPPort::prepush(), 42);
9132e1a3 458
0d0f8426
MHM
459ok(join(':', Devel::PPPort::xsreturn(0)), 'test1');
460ok(join(':', Devel::PPPort::xsreturn(1)), 'test1:test2');