1 ################################################################################
5 ## $Date: 2010/03/07 13:15:48 +0100 $
7 ################################################################################
9 ## Version 3.x, Copyright (C) 2004-2010, 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 ################################################################################
25 PERL_GCC_BRACE_GROUPS_FORBIDDEN
26 PERL_USE_GCC_BRACE_GROUPS
48 #ifndef PERL_UNUSED_DECL
50 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
51 # define PERL_UNUSED_DECL
53 # define PERL_UNUSED_DECL __attribute__((unused))
56 # define PERL_UNUSED_DECL
60 #ifndef PERL_UNUSED_ARG
61 # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
63 # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))
65 # define PERL_UNUSED_ARG(x) ((void)x)
69 #ifndef PERL_UNUSED_VAR
70 # define PERL_UNUSED_VAR(x) ((void)x)
73 #ifndef PERL_UNUSED_CONTEXT
75 # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl)
77 # define PERL_UNUSED_CONTEXT
81 __UNDEFINED__ NOOP /*EMPTY*/(void)0
82 __UNDEFINED__ dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL
85 # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
86 # define NVTYPE long double
88 # define NVTYPE double
94 # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
96 # define INT2PTR(any,d) (any)(d)
98 # if PTRSIZE == LONGSIZE
99 # define PTRV unsigned long
101 # define PTRV unsigned
103 # define INT2PTR(any,d) (any)(PTRV)(d)
108 # if PTRSIZE == LONGSIZE
109 # define PTR2ul(p) (unsigned long)(p)
111 # define PTR2ul(p) INT2PTR(unsigned long,p)
115 __UNDEFINED__ PTR2nat(p) (PTRV)(p)
116 __UNDEFINED__ NUM2PTR(any,d) (any)PTR2nat(d)
117 __UNDEFINED__ PTR2IV(p) INT2PTR(IV,p)
118 __UNDEFINED__ PTR2UV(p) INT2PTR(UV,p)
119 __UNDEFINED__ PTR2NV(p) NUM2PTR(NV,p)
121 #undef START_EXTERN_C
125 # define START_EXTERN_C extern "C" {
126 # define END_EXTERN_C }
127 # define EXTERN_C extern "C"
129 # define START_EXTERN_C
130 # define END_EXTERN_C
131 # define EXTERN_C extern
134 #if defined(PERL_GCC_PEDANTIC)
135 # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
136 # define PERL_GCC_BRACE_GROUPS_FORBIDDEN
140 #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
141 # ifndef PERL_USE_GCC_BRACE_GROUPS
142 # define PERL_USE_GCC_BRACE_GROUPS
148 #ifdef PERL_USE_GCC_BRACE_GROUPS
149 # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
152 # if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
153 # define STMT_START if (1)
154 # define STMT_END else (void)0
156 # define STMT_START do
157 # define STMT_END while (0)
161 __UNDEFINED__ boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
163 /* DEFSV appears first in 5.004_56 */
164 __UNDEFINED__ DEFSV GvSV(PL_defgv)
165 __UNDEFINED__ SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
166 __UNDEFINED__ DEFSV_set(sv) (DEFSV = (sv))
168 /* Older perls (<=5.003) lack AvFILLp */
169 __UNDEFINED__ AvFILLp AvFILL
171 __UNDEFINED__ ERRSV get_sv("@",FALSE)
174 * This function's backport doesn't support the length parameter, but
175 * rather ignores it. Portability can only be ensured if the length
176 * parameter is used for speed reasons, but the length can always be
177 * correctly computed from the string argument.
180 __UNDEFINED__ gv_stashpvn(str,len,create) gv_stashpv(str,create)
183 __UNDEFINED__ get_cv perl_get_cv
184 __UNDEFINED__ get_sv perl_get_sv
185 __UNDEFINED__ get_av perl_get_av
186 __UNDEFINED__ get_hv perl_get_hv
189 __UNDEFINED__ dUNDERBAR dNOOP
190 __UNDEFINED__ UNDERBAR DEFSV
192 __UNDEFINED__ dAX I32 ax = MARK - PL_stack_base + 1
193 __UNDEFINED__ dITEMS I32 items = SP - MARK
195 __UNDEFINED__ dXSTARG SV * targ = sv_newmortal()
197 __UNDEFINED__ dAXMARK I32 ax = POPMARK; \
198 register SV ** const mark = PL_stack_base + ax++
201 __UNDEFINED__ XSprePUSH (sp = PL_stack_base + ax - 1)
203 #if { VERSION < 5.005 }
205 # define XSRETURN(off) \
207 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
212 __UNDEFINED__ XSPROTO(name) void name(pTHX_ CV* cv)
213 __UNDEFINED__ SVfARG(p) ((void*)(p))
215 __UNDEFINED__ PERL_ABS(x) ((x) < 0 ? -(x) : (x))
217 __UNDEFINED__ dVAR dNOOP
219 __UNDEFINED__ SVf "_"
221 __UNDEFINED__ UTF8_MAXBYTES UTF8_MAXLEN
223 __UNDEFINED__ CPERLscope(x) x
225 __UNDEFINED__ PERL_HASH(hash,str,len) \
227 const char *s_PeRlHaSh = str; \
228 I32 i_PeRlHaSh = len; \
229 U32 hash_PeRlHaSh = 0; \
230 while (i_PeRlHaSh--) \
231 hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \
232 (hash) = hash_PeRlHaSh; \
235 #ifndef PERLIO_FUNCS_DECL
236 # ifdef PERLIO_FUNCS_CONST
237 # define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
238 # define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
240 # define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs
241 # define PERLIO_FUNCS_CAST(funcs) (funcs)
245 /* provide these typedefs for older perls */
246 #if { VERSION < 5.9.3 }
249 typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto);
251 typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX);
254 typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*);
258 __UNDEFINED__ isPSXSPC(c) (isSPACE(c) || (c) == '\v')
259 __UNDEFINED__ isBLANK(c) ((c) == ' ' || (c) == '\t')
261 __UNDEFINED__ isALNUMC(c) isalnum(c)
262 __UNDEFINED__ isASCII(c) isascii(c)
263 __UNDEFINED__ isCNTRL(c) iscntrl(c)
264 __UNDEFINED__ isGRAPH(c) isgraph(c)
265 __UNDEFINED__ isPRINT(c) isprint(c)
266 __UNDEFINED__ isPUNCT(c) ispunct(c)
267 __UNDEFINED__ isXDIGIT(c) isxdigit(c)
269 # if { VERSION < 5.10.0 }
271 * The implementation in older perl versions includes all of the
272 * isSPACE() characters, which is wrong. The version provided by
273 * Devel::PPPort always overrides a present buggy version.
277 __UNDEFINED__ isALNUMC(c) (isALPHA(c) || isDIGIT(c))
278 __UNDEFINED__ isASCII(c) ((c) <= 127)
279 __UNDEFINED__ isCNTRL(c) ((c) < ' ' || (c) == 127)
280 __UNDEFINED__ isGRAPH(c) (isALNUM(c) || isPUNCT(c))
281 __UNDEFINED__ isPRINT(c) (((c) >= 32 && (c) < 127))
282 __UNDEFINED__ isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
283 __UNDEFINED__ isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
288 typedef XSPROTO(XSPROTO_test_t);
289 typedef XSPROTO_test_t *XSPROTO_test_t_ptr;
291 XS(XS_Devel__PPPort_dXSTARG); /* prototype */
292 XS(XS_Devel__PPPort_dXSTARG)
298 iv = SvIV(ST(0)) + 1;
303 XS(XS_Devel__PPPort_dAXMARK); /* prototype */
304 XS(XS_Devel__PPPort_dAXMARK)
311 iv = SvIV(ST(0)) - 1;
319 XSPROTO_test_t_ptr p = &XS_Devel__PPPort_dXSTARG;
320 newXS("Devel::PPPort::dXSTARG", *p, file);
322 newXS("Devel::PPPort::dAXMARK", XS_Devel__PPPort_dAXMARK, file);
333 RETVAL += PTR2nat(p) != 0 ? 1 : 0;
334 RETVAL += PTR2ul(p) != 0UL ? 2 : 0;
335 RETVAL += PTR2UV(p) != (UV) 0 ? 4 : 0;
336 RETVAL += PTR2IV(p) != (IV) 0 ? 8 : 0;
337 RETVAL += PTR2NV(p) != (NV) 0 ? 16 : 0;
338 RETVAL += p > NUM2PTR(int *, 0) ? 32 : 0;
344 gv_stashpvn(name, create)
348 RETVAL = gv_stashpvn(name, strlen(name), create) != NULL;
357 RETVAL = get_sv(name, create) != NULL;
366 RETVAL = get_av(name, create) != NULL;
375 RETVAL = get_hv(name, create) != NULL;
384 RETVAL = get_cv(name, create) != NULL;
404 RETVAL = newSVsv(boolSV(value));
411 RETVAL = newSVsv(DEFSV);
418 XPUSHs(sv_mortalcopy(DEFSV));
421 DEFSV_set(newSVpvs("DEFSV"));
422 XPUSHs(sv_mortalcopy(DEFSV));
423 /* Yes, this leaks the above scalar; 5.005 with threads for some reason */
424 /* frees it upon LEAVE, thus mortalizing it causes "attempt to free..." */
425 /* sv_2mortal(DEFSV); */
427 XPUSHs(sv_mortalcopy(DEFSV));
433 RETVAL = SvTRUE(ERRSV);
442 RETVAL = newSVsv(UNDERBAR);
465 #if { VERSION >= 5.004 }
466 x = sv_2mortal(newSVpvf("[%"SVf"]", SVfARG(x)));
472 Perl_ppaddr_t(string)
477 lower = PL_ppaddr[OP_LC];
478 mXPUSHs(newSVpv(string, 0));
481 (void)*(lower)(aTHXR);
488 use vars qw($my_sv @my_av %my_hv);
490 ok(&Devel::PPPort::boolSV(1));
491 ok(!&Devel::PPPort::boolSV(0));
494 ok(&Devel::PPPort::DEFSV(), "Fred");
495 ok(&Devel::PPPort::UNDERBAR(), "Fred");
497 if ($] >= 5.009002) {
500 ok(&Devel::PPPort::DEFSV(), "Fred");
501 ok(&Devel::PPPort::UNDERBAR(), "Tony");
509 my @r = &Devel::PPPort::DEFSV_modify();
516 ok(&Devel::PPPort::DEFSV(), "Fred");
519 ok(!&Devel::PPPort::ERRSV());
520 eval { cannot_call_this_one() };
521 ok(&Devel::PPPort::ERRSV());
523 ok(&Devel::PPPort::gv_stashpvn('Devel::PPPort', 0));
524 ok(!&Devel::PPPort::gv_stashpvn('does::not::exist', 0));
525 ok(&Devel::PPPort::gv_stashpvn('does::not::exist', 1));
528 ok(&Devel::PPPort::get_sv('my_sv', 0));
529 ok(!&Devel::PPPort::get_sv('not_my_sv', 0));
530 ok(&Devel::PPPort::get_sv('not_my_sv', 1));
533 ok(&Devel::PPPort::get_av('my_av', 0));
534 ok(!&Devel::PPPort::get_av('not_my_av', 0));
535 ok(&Devel::PPPort::get_av('not_my_av', 1));
538 ok(&Devel::PPPort::get_hv('my_hv', 0));
539 ok(!&Devel::PPPort::get_hv('not_my_hv', 0));
540 ok(&Devel::PPPort::get_hv('not_my_hv', 1));
543 ok(&Devel::PPPort::get_cv('my_cv', 0));
544 ok(!&Devel::PPPort::get_cv('not_my_cv', 0));
545 ok(&Devel::PPPort::get_cv('not_my_cv', 1));
547 ok(Devel::PPPort::dXSTARG(42), 43);
548 ok(Devel::PPPort::dAXMARK(4711), 4710);
550 ok(Devel::PPPort::prepush(), 42);
552 ok(join(':', Devel::PPPort::xsreturn(0)), 'test1');
553 ok(join(':', Devel::PPPort::xsreturn(1)), 'test1:test2');
555 ok(Devel::PPPort::PERL_ABS(42), 42);
556 ok(Devel::PPPort::PERL_ABS(-13), 13);
558 ok(Devel::PPPort::SVf(42), $] >= 5.004 ? '[42]' : '42');
559 ok(Devel::PPPort::SVf('abc'), $] >= 5.004 ? '[abc]' : 'abc');
561 ok(&Devel::PPPort::Perl_ppaddr_t("FOO"), "foo");
563 ok(&Devel::PPPort::ptrtests(), 63);