Third consting batch
[p5sagit/p5-mst-13.2.git] / scope.c
diff --git a/scope.c b/scope.c
index 492ce60..56ea96f 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1,7 +1,7 @@
 /*    scope.c
  *
  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
+ *    2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -13,7 +13,7 @@
  * levels..."
  */
 
-/* This file contains functions to manipulate various of perl's stacks;
+/* This file contains functions to manipulate several of Perl's stacks;
  * in particular it contains code to push various types of things onto
  * the savestack, then to pop them off and perform the correct restorative
  * action for each one. This corresponds to the cleanup Perl does at
 #define PERL_IN_SCOPE_C
 #include "perl.h"
 
-#if defined(PERL_FLEXIBLE_EXCEPTIONS)
-void *
-Perl_default_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt,
-                    protect_body_t body, ...)
-{
-    void *ret;
-    va_list args;
-    va_start(args, body);
-    ret = vdefault_protect(pcur_env, excpt, body, &args);
-    va_end(args);
-    return ret;
-}
-
-void *
-Perl_vdefault_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt,
-                     protect_body_t body, va_list *args)
-{
-    int ex;
-    void *ret;
-
-    JMPENV_PUSH(ex);
-    if (ex)
-       ret = NULL;
-    else
-       ret = CALL_FPTR(body)(aTHX_ *args);
-    *excpt = ex;
-    JMPENV_POP;
-    return ret;
-}
-#endif
-
 SV**
 Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
 {
@@ -121,15 +90,15 @@ Perl_push_scope(pTHX)
 void
 Perl_pop_scope(pTHX)
 {
-    I32 oldsave = PL_scopestack[--PL_scopestack_ix];
+    const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
     LEAVE_SCOPE(oldsave);
 }
 
 void
 Perl_markstack_grow(pTHX)
 {
-    I32 oldmax = PL_markstack_max - PL_markstack;
-    I32 newmax = GROW(oldmax);
+    const I32 oldmax = PL_markstack_max - PL_markstack;
+    const I32 newmax = GROW(oldmax);
 
     Renew(PL_markstack, newmax, I32);
     PL_markstack_ptr = PL_markstack + oldmax;
@@ -168,7 +137,7 @@ void
 Perl_free_tmps(pTHX)
 {
     /* XXX should tmps_floor live in cxstack? */
-    I32 myfloor = PL_tmps_floor;
+    const I32 myfloor = PL_tmps_floor;
     while (PL_tmps_ix > myfloor) {      /* clean up after last statement */
        SV* sv = PL_tmps_stack[PL_tmps_ix];
        PL_tmps_stack[PL_tmps_ix--] = Nullsv;
@@ -190,7 +159,7 @@ S_save_scalar_at(pTHX_ SV **sptr)
        MAGIC *mg;
        sv_upgrade(sv, SvTYPE(osv));
        if (SvGMAGICAL(osv)) {
-           bool oldtainted = PL_tainted;
+           const bool oldtainted = PL_tainted;
            mg_get(osv);                /* note, can croak! */
            if (PL_tainting && PL_tainted &&
                        (mg = mg_find(osv, PERL_MAGIC_taint))) {
@@ -381,9 +350,8 @@ Perl_save_hash(pTHX_ GV *gv)
 void
 Perl_save_item(pTHX_ register SV *item)
 {
-    register SV *sv = NEWSV(0,0);
+    register SV *sv = newSVsv(item);
 
-    sv_setsv(sv,item);
     SSCHECK(3);
     SSPUSHPTR(item);           /* remember the pointer */
     SSPUSHPTR(sv);             /* remember the value */
@@ -614,7 +582,7 @@ Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
 }
 
 void
-Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
+Perl_save_aelem(pTHX_ const AV *av, I32 idx, SV **sptr)
 {
     SV *sv;
     SSCHECK(4);
@@ -624,7 +592,7 @@ Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
     SSPUSHINT(SAVEt_AELEM);
     /* if it gets reified later, the restore will have the wrong refcnt */
     if (!AvREAL(av) && AvREIFY(av))
-       SvREFCNT_inc(*sptr);
+        (void)SvREFCNT_inc(*sptr);
     save_scalar_at(sptr);
     sv = *sptr;
     /* If we're localizing a tied array element, this new sv
@@ -665,9 +633,9 @@ Perl_save_op(pTHX)
 I32
 Perl_save_alloc(pTHX_ I32 size, I32 pad)
 {
-    register I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
+    register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
                                - (char*)PL_savestack);
-    register I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
+    register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
 
     /* SSCHECK may not be good enough */
     while (PL_savestack_ix + elems + 2 > PL_savestack_max)
@@ -783,7 +751,7 @@ Perl_leave_scope(pTHX_ I32 base)
            av = (AV*)SSPOPPTR;
            gv = (GV*)SSPOPPTR;
            if (GvAV(gv)) {
-               AV *goner = GvAV(gv);
+               AV * const goner = GvAV(gv);
                SvMAGIC(av) = SvMAGIC(goner);
                SvFLAGS((SV*)av) |= SvMAGICAL(goner);
                SvMAGICAL_off(goner);
@@ -801,7 +769,7 @@ Perl_leave_scope(pTHX_ I32 base)
            hv = (HV*)SSPOPPTR;
            gv = (GV*)SSPOPPTR;
            if (GvHV(gv)) {
-               HV *goner = GvHV(gv);
+               HV * const goner = GvHV(gv);
                SvMAGIC(hv) = SvMAGIC(goner);
                SvFLAGS(hv) |= SvMAGICAL(goner);
                SvMAGICAL_off(goner);
@@ -934,13 +902,13 @@ Perl_leave_scope(pTHX_ I32 base)
                case SVt_PVCV:
                    Perl_croak(aTHX_ "panic: leave_scope pad code");
                default:
-                   (void)SvOK_off(sv);
+                   SvOK_off(sv);
                    break;
                }
                SvPADSTALE_on(sv); /* mark as no longer live */
            }
            else {      /* Someone has a claim on this, so abandon it. */
-               U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
+               const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
                switch (SvTYPE(sv)) {   /* Console ourselves with a new value */
                case SVt_PVAV:  *(SV**)ptr = (SV*)newAV();      break;
                case SVt_PVHV:  *(SV**)ptr = (SV*)newHV();      break;
@@ -1001,7 +969,7 @@ Perl_leave_scope(pTHX_ I32 base)
            hv = (HV*)SSPOPPTR;
            ptr = hv_fetch_ent(hv, sv, 1, 0);
            if (ptr) {
-               SV *oval = HeVAL((HE*)ptr);
+               const SV * const oval = HeVAL((HE*)ptr);
                if (oval && oval != &PL_sv_undef) {
                    ptr = &HeVAL((HE*)ptr);
                    if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied))
@@ -1039,7 +1007,7 @@ Perl_leave_scope(pTHX_ I32 base)
            break;
        case SAVEt_PADSV:
            {
-               PADOFFSET off = (PADOFFSET)SSPOPLONG;
+               const PADOFFSET off = (PADOFFSET)SSPOPLONG;
                ptr = SSPOPPTR;
                if (ptr)
                    AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR;
@@ -1056,8 +1024,8 @@ Perl_leave_scope(pTHX_ I32 base)
            break;
        case SAVEt_SET_SVFLAGS:
            {
-               U32 val  = (U32)SSPOPINT;
-               U32 mask = (U32)SSPOPINT;
+               const U32 val  = (U32)SSPOPINT;
+               const U32 mask = (U32)SSPOPINT;
                sv = (SV*)SSPOPPTR;
                SvFLAGS(sv) &= ~mask;
                SvFLAGS(sv) |= val;
@@ -1178,3 +1146,13 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
     }
 #endif /* DEBUGGING */
 }
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vim: shiftwidth=4:
+*/