Author: petdance
Date: Thu May 31 13:45:48 2007
New Revision: 18713

Modified:
   trunk/include/parrot/stacks.h
   trunk/src/exceptions.c
   trunk/src/stacks.c

Log:
consting and localizing

Modified: trunk/include/parrot/stacks.h
==============================================================================
--- trunk/include/parrot/stacks.h       (original)
+++ trunk/include/parrot/stacks.h       Thu May 31 13:45:48 2007
@@ -1,5 +1,5 @@
 /* stacks.h
- *  Copyright (C) 2001-2003, The Perl Foundation.
+ *  Copyright (C) 2001-2007, The Perl Foundation.
  *  SVN Info
  *     $Id$
  *  Overview:
@@ -88,7 +88,7 @@
 PARROT_API void *stack_peek(Interp *interp, Stack_Chunk_t *stack,
                 Stack_entry_type *type);
 
-PARROT_API Stack_entry_type get_entry_type(Interp *interp, Stack_Entry_t 
*entry)
+PARROT_API Stack_entry_type get_entry_type(Interp *interp, const Stack_Entry_t 
*entry)
     __attribute__nonnull__(2);
 
 void Parrot_dump_dynamic_environment(Interp *, struct Stack_Chunk *);

Modified: trunk/src/exceptions.c
==============================================================================
--- trunk/src/exceptions.c      (original)
+++ trunk/src/exceptions.c      Thu May 31 13:45:48 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2006, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -222,8 +222,6 @@
 static PMC *
 find_exception_handler(Interp *interp, PMC *exception)
 {
-    PMC *handler;
-    STRING *message;
     char *m;
     int exit_status, print_location;
     int depth = 0;
@@ -232,12 +230,13 @@
     /* for now, we don't check the exception class and we don't
      * look for matching handlers.  [this is being redesigned anyway.]
      */
-    message = VTABLE_get_string_keyed_int(interp, exception, 0);
+    STRING * const message = VTABLE_get_string_keyed_int(interp, exception, 0);
+
     /* [TODO: replace quadratic search with something linear, hopefully without
        trashing abstraction layers.  -- rgr, 17-Sep-06.] */
     while ((e = stack_entry(interp, interp->dynamic_env, depth)) != NULL) {
         if (e->entry_type == STACK_ENTRY_PMC) {
-            handler = UVal_pmc(e->entry);
+            PMC * const handler = UVal_pmc(e->entry);
             if (handler && handler->vtable->base_type ==
                     enum_class_Exception_Handler) {
                 return handler;
@@ -260,6 +259,7 @@
         fputs(m, stderr);
         if (m[strlen(m)-1] != '\n')
             fprintf(stderr, "%c", '\n');
+        string_cstring_free(m);
     }
     else {
         const INTVAL severity =
@@ -272,8 +272,6 @@
         else
             fprintf(stderr, "No exception handler and no message\n");
     }
-    if (m)
-        string_cstring_free(m);
     /* caution against output swap (with PDB_backtrace) */
     fflush(stderr);
     if (print_location)
@@ -400,7 +398,7 @@
     /* address = VTABLE_get_pointer(interp, handler); */
     if (PObj_get_FLAGS(handler) & SUB_FLAG_C_HANDLER) {
         /* its a C exception handler */
-        Parrot_exception *jb = (Parrot_exception *) address;
+        Parrot_exception * const jb = (Parrot_exception *) address;
         longjmp(jb->destination, 1);
     }
     /* return the address of the handler */
@@ -622,11 +620,8 @@
 void
 really_destroy_exception_list(Parrot_exception *e)
 {
-    Parrot_exception *prev;
-
-    while (e != NULL)
-    {
-        prev = e->prev;
+    while (e != NULL) {
+        Parrot_exception * const prev = e->prev;
         mem_sys_free(e);
         e    = prev;
     }

Modified: trunk/src/stacks.c
==============================================================================
--- trunk/src/stacks.c  (original)
+++ trunk/src/stacks.c  Thu May 31 13:45:48 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -182,9 +182,7 @@
                Stack_Chunk_t **stack_p /*NN*/,
                INTVAL num_entries)
 {
-    Stack_Chunk_t *stack = *stack_p;
-    Stack_Entry_t temp;
-    INTVAL i;
+    Stack_Chunk_t * const stack = *stack_p;
     INTVAL depth = num_entries - 1;
 
     if (num_entries >= -1 && num_entries <= 1) {
@@ -193,6 +191,9 @@
 
 
     if (num_entries < 0) {
+        INTVAL i;
+        Stack_Entry_t temp;
+
         num_entries = -num_entries;
         depth = num_entries - 1;
 
@@ -209,6 +210,8 @@
         *stack_entry(interp, stack, 0) = temp;
     }
     else {
+        INTVAL i;
+        Stack_Entry_t temp;
 
         if (stack_height(interp, stack) < (size_t)num_entries) {
             internal_exception(ERROR_STACK_SHALLOW, "Stack too shallow!");
@@ -378,7 +381,7 @@
 
 void *
 stack_peek(Interp *interp, Stack_Chunk_t *stack_base /*NN*/,
-           Stack_entry_type *type)
+           Stack_entry_type *type /*NULLOK*/)
 {
     Stack_Entry_t * const entry = stack_entry(interp, stack_base, 0);
     if (entry == NULL) {
@@ -399,17 +402,12 @@
 
 /*
 
-=item C<Stack_entry_type
-get_entry_type(Interp *interp, Stack_Entry_t *entry)>
-
 Returns the stack entry type of C<entry>.
 
-=cut
-
 */
 
 Stack_entry_type
-get_entry_type(Interp *interp, Stack_Entry_t *entry /*NN*/)
+get_entry_type(Interp *interp, const Stack_Entry_t *entry /*NN*/)
 {
     return entry->entry_type;
 }
@@ -434,7 +432,7 @@
     int height = (int) stack_height(interp, dynamic_env);
 
     while (dynamic_env->prev != dynamic_env) {
-        Stack_Entry_t *e = stack_entry(interp, dynamic_env, 0);
+        const Stack_Entry_t * const e = stack_entry(interp, dynamic_env, 0);
         if (! e)
             internal_exception(1, "Control stack damaged");
 
@@ -444,7 +442,7 @@
                     e->entry_type, e->cleanup);
         if (e->entry_type == STACK_ENTRY_PMC
                 || e->entry_type == STACK_ENTRY_ACTION) {
-            PMC *thing = UVal_pmc(e->entry);
+            PMC * const thing = UVal_pmc(e->entry);
 
             PIO_eprintf(interp, "[        PMC %p type %d => %Ss]\n",
                         thing, thing->vtable->base_type,

Reply via email to