From 0d96b528ff0140192b273a677f66f80ee54f3fc4 Mon Sep 17 00:00:00 2001 From: Chip Salzenberg Date: Mon, 23 Jul 2012 22:40:46 -0700 Subject: [PATCH] Unify code that initializes constants yes, no, and undef --- embed.fnc | 1 + embed.h | 1 + perl.c | 24 +----------------------- proto.h | 1 + sv.c | 58 +++++++++++++++++++++++++++++++++------------------------- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/embed.fnc b/embed.fnc index 262428b..e4e2649 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1696,6 +1696,7 @@ Adpbm |void |sv_nounlocking |NULLOK SV *sv Adpb |void |sv_nounlocking |NULLOK SV *sv #endif Adp |int |nothreadhook +p |void |init_constants #if defined(PERL_IN_DOOP_C) sR |I32 |do_trans_simple |NN SV * const sv diff --git a/embed.h b/embed.h index 2078f94..560aa65 100644 --- a/embed.h +++ b/embed.h @@ -1092,6 +1092,7 @@ #define hv_ename_add(a,b,c,d) Perl_hv_ename_add(aTHX_ a,b,c,d) #define hv_ename_delete(a,b,c,d) Perl_hv_ename_delete(aTHX_ a,b,c,d) #define init_argv_symbols(a,b) Perl_init_argv_symbols(aTHX_ a,b) +#define init_constants() Perl_init_constants(aTHX) #define init_debugger() Perl_init_debugger(aTHX) #define intro_my() Perl_intro_my(aTHX) #define invert(a) Perl_invert(aTHX_ a) diff --git a/perl.c b/perl.c index a4a05f5..bba4688 100644 --- a/perl.c +++ b/perl.c @@ -242,29 +242,7 @@ perl_construct(pTHXx) #endif PL_curcop = &PL_compiling; /* needed by ckWARN, right away */ - /* set read-only and try to insure than we wont see REFCNT==0 - very often */ - - SvREADONLY_on(&PL_sv_undef); - SvREFCNT(&PL_sv_undef) = (~(U32)0)/2; - - sv_setpv(&PL_sv_no,PL_No); - /* value lookup in void context - happens to have the side effect - of caching the numeric forms. However, as &PL_sv_no doesn't contain - a string that is a valid numer, we have to turn the public flags by - hand: */ - SvNV(&PL_sv_no); - SvIV(&PL_sv_no); - SvIOK_on(&PL_sv_no); - SvNOK_on(&PL_sv_no); - SvREADONLY_on(&PL_sv_no); - SvREFCNT(&PL_sv_no) = (~(U32)0)/2; - - sv_setpv(&PL_sv_yes,PL_Yes); - SvNV(&PL_sv_yes); - SvIV(&PL_sv_yes); - SvREADONLY_on(&PL_sv_yes); - SvREFCNT(&PL_sv_yes) = (~(U32)0)/2; + init_constants(); SvREADONLY_on(&PL_sv_placeholder); SvREFCNT(&PL_sv_placeholder) = (~(U32)0)/2; diff --git a/proto.h b/proto.h index 77d891f..9c9030a 100644 --- a/proto.h +++ b/proto.h @@ -1619,6 +1619,7 @@ PERL_CALLCONV void Perl_init_argv_symbols(pTHX_ int argc, char **argv) #define PERL_ARGS_ASSERT_INIT_ARGV_SYMBOLS \ assert(argv) +PERL_CALLCONV void Perl_init_constants(pTHX); PERL_CALLCONV void Perl_init_dbargs(pTHX); PERL_CALLCONV void Perl_init_debugger(pTHX); PERL_CALLCONV int Perl_init_i18nl10n(pTHX_ int printwarn); diff --git a/sv.c b/sv.c index 2d5444e..3176ec0 100644 --- a/sv.c +++ b/sv.c @@ -12906,18 +12906,6 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, PL_hash_seed = proto_perl->Ihash_seed; PL_rehash_seed = proto_perl->Irehash_seed; - SvANY(&PL_sv_undef) = NULL; - SvREFCNT(&PL_sv_undef) = (~(U32)0)/2; - SvFLAGS(&PL_sv_undef) = SVf_READONLY|SVt_NULL; - SvREFCNT(&PL_sv_no) = (~(U32)0)/2; - SvFLAGS(&PL_sv_no) = SVp_IOK|SVf_IOK|SVp_NOK|SVf_NOK - |SVp_POK|SVf_POK|SVf_READONLY|SVt_PVNV; - - SvANY(&PL_sv_yes) = new_XPVNV(); - SvREFCNT(&PL_sv_yes) = (~(U32)0)/2; - SvFLAGS(&PL_sv_yes) = SVp_IOK|SVf_IOK|SVp_NOK|SVf_NOK - |SVp_POK|SVf_POK|SVf_READONLY|SVt_PVNV; - /* dbargs array probably holds garbage */ PL_dbargs = NULL; @@ -13146,21 +13134,9 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, PL_ptr_table = ptr_table_new(); /* initialize these special pointers as early as possible */ + init_constants(); ptr_table_store(PL_ptr_table, &proto_perl->Isv_undef, &PL_sv_undef); - - SvANY(&PL_sv_no) = new_XPVNV(); - SvPV_set(&PL_sv_no, savepvn(PL_No, 0)); - SvCUR_set(&PL_sv_no, 0); - SvLEN_set(&PL_sv_no, 1); - SvIV_set(&PL_sv_no, 0); - SvNV_set(&PL_sv_no, 0); ptr_table_store(PL_ptr_table, &proto_perl->Isv_no, &PL_sv_no); - - SvPV_set(&PL_sv_yes, savepvn(PL_Yes, 1)); - SvCUR_set(&PL_sv_yes, 1); - SvLEN_set(&PL_sv_yes, 2); - SvIV_set(&PL_sv_yes, 1); - SvNV_set(&PL_sv_yes, 1); ptr_table_store(PL_ptr_table, &proto_perl->Isv_yes, &PL_sv_yes); /* create (a non-shared!) shared string table */ @@ -13690,6 +13666,38 @@ Perl_clone_params_new(PerlInterpreter *const from, PerlInterpreter *const to) #endif /* USE_ITHREADS */ +void +Perl_init_constants(pTHX) +{ + SvREFCNT(&PL_sv_undef) = (~(U32)0)/2; + SvFLAGS(&PL_sv_undef) = SVf_READONLY|SVt_NULL; + SvANY(&PL_sv_undef) = NULL; + + SvANY(&PL_sv_no) = new_XPVNV(); + SvREFCNT(&PL_sv_no) = (~(U32)0)/2; + SvFLAGS(&PL_sv_no) = SVt_PVNV|SVf_READONLY + |SVp_IOK|SVf_IOK|SVp_NOK|SVf_NOK + |SVp_POK|SVf_POK; + + SvANY(&PL_sv_yes) = new_XPVNV(); + SvREFCNT(&PL_sv_yes) = (~(U32)0)/2; + SvFLAGS(&PL_sv_yes) = SVt_PVNV|SVf_READONLY + |SVp_IOK|SVf_IOK|SVp_NOK|SVf_NOK + |SVp_POK|SVf_POK; + + SvPV_set(&PL_sv_no, (char*)PL_No); + SvCUR_set(&PL_sv_no, 0); + SvLEN_set(&PL_sv_no, 0); + SvIV_set(&PL_sv_no, 0); + SvNV_set(&PL_sv_no, 0); + + SvPV_set(&PL_sv_yes, (char*)PL_Yes); + SvCUR_set(&PL_sv_yes, 1); + SvLEN_set(&PL_sv_yes, 0); + SvIV_set(&PL_sv_yes, 1); + SvNV_set(&PL_sv_yes, 1); +} + /* =head1 Unicode Support -- 2.7.4