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