From 923e4eb5b872f0800559dcb72be02dea329298f2 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Sun, 21 Sep 2003 08:50:22 +0000 Subject: [PATCH] Macrofy the compile/runtime test. p4raw-id: //depot/perl@21297 --- cop.h | 4 ++++ gv.c | 2 +- perl.h | 2 +- pp_ctl.c | 8 ++++---- regcomp.c | 4 ++-- sv.c | 12 ++++++------ utf8.c | 6 +++--- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cop.h b/cop.h index 04eb7c0..12eecdc 100644 --- a/cop.h +++ b/cop.h @@ -572,3 +572,7 @@ typedef struct stackinfo PERL_SI; POPSTACK; \ } \ } STMT_END + +#define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) +#define IN_PERL_RUNTIME (PL_curcop != &PL_compiling) + diff --git a/gv.c b/gv.c index 2fe604b..b297cb6 100644 --- a/gv.c +++ b/gv.c @@ -720,7 +720,7 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type) if (global) stash = PL_defstash; - else if ((COP*)PL_curcop == &PL_compiling) { + else if (IN_PERL_COMPILETIME) { stash = PL_curstash; if (add && (PL_hints & HINT_STRICT_VARS) && sv_type != SVt_PVCV && diff --git a/perl.h b/perl.h index 01458d9..73aad3c 100644 --- a/perl.h +++ b/perl.h @@ -3852,7 +3852,7 @@ typedef struct am_table_short AMTS; #define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) #define IN_LOCALE \ - (PL_curcop == &PL_compiling ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) + (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) #define STORE_NUMERIC_LOCAL_SET_STANDARD() \ bool was_local = PL_numeric_local && IN_LOCALE; \ diff --git a/pp_ctl.c b/pp_ctl.c index 9bacadb..37e5c0b 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2677,7 +2677,7 @@ Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp) SAVETMPS; /* switch to eval mode */ - if (PL_curcop == &PL_compiling) { + if (IN_PERL_COMPILETIME) { SAVECOPSTASH_FREE(&PL_compiling); CopSTASH_set(&PL_compiling, PL_curstash); } @@ -2710,14 +2710,14 @@ Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp) PL_hints &= HINT_UTF8; /* we get here either during compilation, or via pp_regcomp at runtime */ - runtime = (PL_curcop != &PL_compiling); + runtime = IN_PERL_RUNTIME; if (runtime) runcv = find_runcv(NULL); PL_op = &dummy; PL_op->op_type = OP_ENTEREVAL; PL_op->op_flags = 0; /* Avoid uninit warning. */ - PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP); + PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP); PUSHEVAL(cx, 0, Nullgv); if (runtime) @@ -2733,7 +2733,7 @@ Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp) /* XXX DAPM do this properly one year */ *padp = (AV*)SvREFCNT_inc(PL_comppad); LEAVE; - if (PL_curcop == &PL_compiling) + if (IN_PERL_COMPILETIME) PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK); #ifdef OP_IN_REGISTER op = PL_opsave; diff --git a/regcomp.c b/regcomp.c index c61e548..9a6df98 100644 --- a/regcomp.c +++ b/regcomp.c @@ -2253,13 +2253,13 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp) } else { /* First pass */ if (PL_reginterp_cnt < ++RExC_seen_evals - && PL_curcop != &PL_compiling) + && IN_PERL_RUNTIME) /* No compiled RE interpolated, has runtime components ===> unsafe. */ FAIL("Eval-group not allowed at runtime, use re 'eval'"); if (PL_tainting && PL_tainted) FAIL("Eval-group in insecure regular expression"); - if (PL_curcop == &PL_compiling) + if (IN_PERL_COMPILETIME) PL_cv_has_eval = 1; } diff --git a/sv.c b/sv.c index 51bd17e..60e8874 100644 --- a/sv.c +++ b/sv.c @@ -4473,7 +4473,7 @@ Perl_sv_force_normal_flags(pTHX_ register SV *sv, U32 flags) sv_dump(sv); } } - else if (PL_curcop != &PL_compiling) + else if (IN_PERL_RUNTIME) Perl_croak(aTHX_ PL_no_modify); /* At this point I believe that I can drop the global SV mutex. */ } @@ -4490,7 +4490,7 @@ Perl_sv_force_normal_flags(pTHX_ register SV *sv, U32 flags) *SvEND(sv) = '\0'; unsharepvn(pvx, SvUTF8(sv) ? -(I32)len : len, hash); } - else if (PL_curcop != &PL_compiling) + else if (IN_PERL_RUNTIME) Perl_croak(aTHX_ PL_no_modify); } #endif @@ -4875,7 +4875,7 @@ Perl_sv_magic(pTHX_ register SV *sv, SV *obj, int how, const char *name, I32 nam sv_force_normal_flags(sv, 0); #endif if (SvREADONLY(sv)) { - if (PL_curcop != &PL_compiling + if (IN_PERL_RUNTIME && how != PERL_MAGIC_regex_global && how != PERL_MAGIC_bm && how != PERL_MAGIC_fm @@ -6396,7 +6396,7 @@ Perl_sv_gets(pTHX_ register SV *sv, register PerlIO *fp, I32 append) if (PerlIO_isutf8(fp)) SvUTF8_on(sv); - if (PL_curcop == &PL_compiling) { + if (IN_PERL_COMPILETIME) { /* we always read code in line mode */ rsptr = "\n"; rslen = 1; @@ -6731,7 +6731,7 @@ Perl_sv_inc(pTHX_ register SV *sv) if (SvIsCOW(sv)) sv_force_normal_flags(sv, 0); if (SvREADONLY(sv)) { - if (PL_curcop != &PL_compiling) + if (IN_PERL_RUNTIME) Perl_croak(aTHX_ PL_no_modify); } if (SvROK(sv)) { @@ -6887,7 +6887,7 @@ Perl_sv_dec(pTHX_ register SV *sv) if (SvIsCOW(sv)) sv_force_normal_flags(sv, 0); if (SvREADONLY(sv)) { - if (PL_curcop != &PL_compiling) + if (IN_PERL_RUNTIME) Perl_croak(aTHX_ PL_no_modify); } if (SvROK(sv)) { diff --git a/utf8.c b/utf8.c index 30bb7cf..6a665eb 100644 --- a/utf8.c +++ b/utf8.c @@ -1592,7 +1592,7 @@ Perl_swash_init(pTHX_ char* pkg, char* name, SV *listsv, I32 minbits, I32 none) SAVEI32(PL_hints); PL_hints = 0; save_re_context(); - if (PL_curcop == &PL_compiling) { + if (IN_PERL_COMPILETIME) { /* XXX ought to be handled by lex_start */ SAVEI32(PL_in_my); PL_in_my = 0; @@ -1608,7 +1608,7 @@ Perl_swash_init(pTHX_ char* pkg, char* name, SV *listsv, I32 minbits, I32 none) SvREFCNT_dec(errsv_save); LEAVE; POPSTACK; - if (PL_curcop == &PL_compiling) { + if (IN_PERL_COMPILETIME) { STRLEN len; char* pv = SvPV(tokenbufsv, len); @@ -1725,7 +1725,7 @@ Perl_swash_fetch(pTHX_ SV *sv, U8 *ptr, bool do_utf8) POPSTACK; FREETMPS; LEAVE; - if (PL_curcop == &PL_compiling) + if (IN_PERL_COMPILETIME) PL_curcop->op_private = (U8)(PL_hints & HINT_PRIVATE_MASK); svp = hv_store(hv, (char*)ptr, klen, retval, 0); -- 1.8.3.1