From: Nick Ing-Simmons Date: Sat, 24 Jan 1998 12:02:34 +0000 (+0000) Subject: Gisle's av_unshift tweak, two small patches from chip X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67a38de0970070c8aa928e300768e725698b3516;p=p5sagit%2Fp5-mst-13.2.git Gisle's av_unshift tweak, two small patches from chip and check for NULL in hv_delete in case '~' and tie magic are present p4raw-id: //depot/ansiperl@438 --- diff --git a/av.c b/av.c index 5925a17..20c77d8 100644 --- a/av.c +++ b/av.c @@ -436,7 +436,7 @@ void av_unshift(register AV *av, register I32 num) { register I32 i; - register SV **sstr,**dstr; + register SV **ary; MAGIC* mg; if (!av || num <= 0) @@ -471,22 +471,15 @@ av_unshift(register AV *av, register I32 num) AvFILLp(av) += i; SvPVX(av) = (char*)(AvARRAY(av) - i); } - if (num) { - av_extend(av,AvFILLp(av)+num); + if (num) { + i = AvFILLp(av); + av_extend(av, i + num); AvFILLp(av) += num; - dstr = AvARRAY(av) + AvFILLp(av); - sstr = dstr - num; -#ifdef BUGGY_MSC5 - # pragma loop_opt(off) /* don't loop-optimize the following code */ -#endif /* BUGGY_MSC5 */ - for (i = AvFILLp(av) - num; i >= 0; --i) { - *dstr-- = *sstr--; -#ifdef BUGGY_MSC5 - # pragma loop_opt() /* loop-optimization back to command-line setting */ -#endif /* BUGGY_MSC5 */ - } - while (num) - AvARRAY(av)[--num] = &sv_undef; + ary = AvARRAY(av); + Move(ary, ary + num, i + 1, SV*); + do { + ary[--num] = &sv_undef; + } while (num); } } diff --git a/hv.c b/hv.c index 5a0f9d2..25f1422 100644 --- a/hv.c +++ b/hv.c @@ -423,6 +423,7 @@ hv_delete(HV *hv, char *key, U32 klen, I32 flags) register U32 hash; register HE *entry; register HE **oentry; + SV **svp; SV *sv; if (!hv) @@ -432,8 +433,8 @@ hv_delete(HV *hv, char *key, U32 klen, I32 flags) bool needs_store; hv_magic_check (hv, &needs_copy, &needs_store); - if (needs_copy) { - sv = *hv_fetch(hv, key, klen, TRUE); + if (needs_copy && (svp = hv_fetch(hv, key, klen, TRUE))) { + sv = *svp; mg_clear(sv); if (!needs_store) { if (mg_find(sv, 'p')) { @@ -501,8 +502,7 @@ hv_delete_ent(HV *hv, SV *keysv, I32 flags, U32 hash) bool needs_store; hv_magic_check (hv, &needs_copy, &needs_store); - if (needs_copy) { - entry = hv_fetch_ent(hv, keysv, TRUE, hash); + if (needs_copy && (entry = hv_fetch_ent(hv, keysv, TRUE, hash))) { sv = HeVAL(entry); mg_clear(sv); if (!needs_store) { diff --git a/pp_ctl.c b/pp_ctl.c index 9590271..68bf5d2 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2162,6 +2162,7 @@ doeval(int gimme, OP** startop) HV *newstash; CV *caller; AV* comppadlist; + I32 i; in_eval = 1; @@ -2178,6 +2179,16 @@ doeval(int gimme, OP** startop) SAVEI32(max_intro_pending); caller = compcv; + for (i = cxstack_ix - 1; i >= 0; i--) { + PERL_CONTEXT *cx = &cxstack[i]; + if (cx->cx_type == CXt_EVAL) + break; + else if (cx->cx_type == CXt_SUB) { + caller = cx->blk_sub.cv; + break; + } + } + SAVESPTR(compcv); compcv = (CV*)NEWSV(1104,0); sv_upgrade((SV *)compcv, SVt_PVCV); diff --git a/scope.c b/scope.c index bca1c2b..61bc731 100644 --- a/scope.c +++ b/scope.c @@ -205,11 +205,14 @@ AV * save_ary(GV *gv) { dTHR; - AV *oav, *av; + AV *oav = GvAVn(gv); + AV *av; + if (!AvREAL(oav) && AvREIFY(oav)) + av_reify(oav); SSCHECK(3); SSPUSHPTR(gv); - SSPUSHPTR(oav = GvAVn(gv)); + SSPUSHPTR(oav); SSPUSHINT(SAVEt_AV); GvAV(gv) = Null(AV*);