[svn:parrot] r46275 - in trunk: config/gen/platform/generic config/gen/platform/win32 src src/dynpmc src/pmc

jimmy at svn.parrot.org jimmy at svn.parrot.org
Tue May 4 07:50:24 UTC 2010


Author: jimmy
Date: Tue May  4 07:50:22 2010
New Revision: 46275
URL: https://trac.parrot.org/parrot/changeset/46275

Log:
random consting, removed unused vars, localize, etc.

Modified:
   trunk/config/gen/platform/generic/env.c
   trunk/config/gen/platform/generic/exec.c
   trunk/config/gen/platform/win32/env.c
   trunk/config/gen/platform/win32/exec.c
   trunk/src/dynpmc/gziphandle.pmc
   trunk/src/dynpmc/os.pmc
   trunk/src/frame_builder.c
   trunk/src/misc.c
   trunk/src/packfile.c
   trunk/src/pmc/fixedbooleanarray.pmc
   trunk/src/pmc/opcode.pmc
   trunk/src/pmc/oplib.pmc
   trunk/src/pmc/resizablebooleanarray.pmc
   trunk/src/pmc/string.pmc

Modified: trunk/config/gen/platform/generic/env.c
==============================================================================
--- trunk/config/gen/platform/generic/env.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/config/gen/platform/generic/env.c	Tue May  4 07:50:22 2010	(r46275)
@@ -37,8 +37,8 @@
 void
 Parrot_setenv(PARROT_INTERP, STRING *str_name, STRING *str_value)
 {
-    char *name  = Parrot_str_to_cstring(interp, str_name);
-    char *value = Parrot_str_to_cstring(interp, str_value);
+    char * const name  = Parrot_str_to_cstring(interp, str_name);
+    char * const value = Parrot_str_to_cstring(interp, str_value);
 #ifdef PARROT_HAS_SETENV
     setenv(name, value, 1);
 #else
@@ -96,8 +96,8 @@
 char *
 Parrot_getenv(PARROT_INTERP, STRING *str_name)
 {
-    char *name  = Parrot_str_to_cstring(interp, str_name);
-    char *value = getenv(name);
+    char * const name  = Parrot_str_to_cstring(interp, str_name);
+    char        *value = getenv(name);
     Parrot_str_free_cstring(name);
     return value;
 }

Modified: trunk/config/gen/platform/generic/exec.c
==============================================================================
--- trunk/config/gen/platform/generic/exec.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/config/gen/platform/generic/exec.c	Tue May  4 07:50:22 2010	(r46275)
@@ -55,7 +55,7 @@
     else {
         /* child */
         char * const cmd    = Parrot_str_to_cstring(interp, command);
-        int          status = execlp("sh", "sh", "-c", cmd, (void *)NULL);
+        const int    status = execlp("sh", "sh", "-c", cmd, (void *)NULL);
 
         /* if we get here, something's horribly wrong, but free anyway... */
         Parrot_str_free_cstring(cmd);

Modified: trunk/config/gen/platform/win32/env.c
==============================================================================
--- trunk/config/gen/platform/win32/env.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/config/gen/platform/win32/env.c	Tue May  4 07:50:22 2010	(r46275)
@@ -46,8 +46,8 @@
 void
 Parrot_setenv(PARROT_INTERP, STRING *str_name, STRING *str_value)
 {
-    char * name  = Parrot_str_to_cstring(interp, str_name);
-    char * value = Parrot_str_to_cstring(interp, str_value);
+    char * const name  = Parrot_str_to_cstring(interp, str_name);
+    char * const value = Parrot_str_to_cstring(interp, str_value);
     assert(name  != NULL);
     assert(value != NULL);
 
@@ -99,9 +99,9 @@
 char *
 Parrot_getenv(PARROT_INTERP, ARGIN(STRING *str_name))
 {
-    char *name       = Parrot_str_to_cstring(interp, str_name);
-    const DWORD size = GetEnvironmentVariable(name, NULL, 0);
-    char *buffer     = NULL;
+    char * const name = Parrot_str_to_cstring(interp, str_name);
+    const DWORD size  = GetEnvironmentVariable(name, NULL, 0);
+    char *buffer      = NULL;
 
     if (size == 0) {
         Parrot_str_free_cstring(name);

Modified: trunk/config/gen/platform/win32/exec.c
==============================================================================
--- trunk/config/gen/platform/win32/exec.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/config/gen/platform/win32/exec.c	Tue May  4 07:50:22 2010	(r46275)
@@ -41,10 +41,9 @@
     DWORD status = 0;
     STARTUPINFO si;
     PROCESS_INFORMATION pi;
-    int free_it = 0;
-    char* cmd = (char *)mem_sys_allocate(command->strlen + 4);
-    char* shell = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec")));
-    char* cmdin = Parrot_str_to_cstring(interp, command);
+    char* const cmd   = (char *)mem_sys_allocate(command->strlen + 4);
+    char* const shell = Parrot_getenv(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec")));
+    char* const cmdin = Parrot_str_to_cstring(interp, command);
 
     strcpy(cmd, "/c ");
     strcat(cmd, cmdin);
@@ -67,7 +66,7 @@
     }
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
-    if (free_it) free(shell);
+    Parrot_str_free_cstring(shell);
     mem_sys_free(cmd);
 
     /* Return exit code left shifted by 8 for POSIX emulation. */
@@ -108,8 +107,8 @@
 
     /* Now build command line. */
     for (i = 0; i < pmclen; i++) {
-        STRING *s = VTABLE_get_string_keyed_int(interp, cmdargs, i);
-        char *cs  = Parrot_str_to_cstring(interp, s);
+        STRING * const s  = VTABLE_get_string_keyed_int(interp, cmdargs, i);
+        char   * const cs = Parrot_str_to_cstring(interp, s);
         if (cmdlinepos + (int)s->strlen + 3 > cmdlinelen) {
             cmdlinelen += s->strlen + 4;
             cmdline = (char *)mem_sys_realloc(cmdline, cmdlinelen);

Modified: trunk/src/dynpmc/gziphandle.pmc
==============================================================================
--- trunk/src/dynpmc/gziphandle.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/dynpmc/gziphandle.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -76,11 +76,11 @@
 */
     METHOD open(STRING *filename, STRING *mode :optional,
                                INTVAL has_mode :opt_flag) {
-        char *path  = Parrot_str_to_cstring(INTERP, filename);
+        char * const path  = Parrot_str_to_cstring(INTERP, filename);
         gzFile file;
 
         if (has_mode) {
-            char *mod = Parrot_str_to_cstring(INTERP, mode);
+            char * const mod = Parrot_str_to_cstring(INTERP, mode);
             file      = gzopen(path, mod);
             Parrot_str_free_cstring(mod);
         }
@@ -161,8 +161,9 @@
     METHOD print(PMC *value) {
         gzFile file;
         STRING * const str = VTABLE_get_string(INTERP, value);
-        char *buf = Parrot_str_to_cstring(INTERP, str);
-        UINTVAL len =  Parrot_str_byte_length(INTERP, str);
+        char   * const buf = Parrot_str_to_cstring(INTERP, str);
+        const UINTVAL  len =  Parrot_str_byte_length(INTERP, str);
+
         GET_ATTR_file(INTERP, SELF, file);
         (void)gzwrite(file, buf, len);
         Parrot_str_free_cstring(buf);
@@ -181,8 +182,9 @@
     METHOD puts(STRING *value) {
         INTVAL status;
         gzFile file;
-        char *buf = Parrot_str_to_cstring(INTERP, value);
-        UINTVAL len =  Parrot_str_byte_length(INTERP, value);
+        char * const  buf = Parrot_str_to_cstring(INTERP, value);
+        const UINTVAL len =  Parrot_str_byte_length(INTERP, value);
+
         GET_ATTR_file(INTERP, SELF, file);
         status =  gzwrite(file, buf, len);
         Parrot_str_free_cstring(buf);
@@ -248,7 +250,7 @@
         char *buf;
         STRING *dst = NULL;
         UINTVAL srcLen, bufSize, dstLen;
-        char *src = Parrot_str_to_cstring(INTERP, str);
+        char * const src = Parrot_str_to_cstring(INTERP, str);
 
         if (!src)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,

Modified: trunk/src/dynpmc/os.pmc
==============================================================================
--- trunk/src/dynpmc/os.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/dynpmc/os.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -484,9 +484,8 @@
         PMC   * array = Parrot_pmc_new(INTERP, enum_class_ResizableStringArray);
 #ifndef _MSC_VER
         char  * const cpath = Parrot_str_to_cstring(INTERP, path);
-        DIR           *dir  = opendir(cpath);
+        DIR   * const   dir = opendir(cpath);
         struct dirent *dirent;
-        STRING        *retval;
 
         Parrot_str_free_cstring(cpath);
 
@@ -497,8 +496,7 @@
         }
 
         while ((dirent = readdir(dir)) != NULL) {
-            retval = Parrot_str_new(INTERP, dirent->d_name, 0) ;
-            VTABLE_push_string(INTERP, array, retval);
+            VTABLE_push_string(INTERP, array, Parrot_str_new(INTERP, dirent->d_name, 0));
         }
 
         closedir(dir);

Modified: trunk/src/frame_builder.c
==============================================================================
--- trunk/src/frame_builder.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/frame_builder.c	Tue May  4 07:50:22 2010	(r46275)
@@ -299,7 +299,7 @@
     const int ST_SIZE_OF           = 124;
     const int JIT_ALLOC_SIZE       = 1024;
 
-    char      *signature_str      = Parrot_str_to_cstring(interp, signature);
+    char    * const signature_str  = Parrot_str_to_cstring(interp, signature);
     /* skip over the result */
     char      *sig                = signature_str + 1;
     size_t     stack_space_needed = calc_signature_needs(sig,

Modified: trunk/src/misc.c
==============================================================================
--- trunk/src/misc.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/misc.c	Tue May  4 07:50:22 2010	(r46275)
@@ -113,8 +113,8 @@
                  size_t len, ARGIN(const char *pat), va_list args)
 {
     ASSERT_ARGS(Parrot_vsnprintf)
-    char   *str_ret;
-    size_t  str_len;
+    
+
     if (len == 0)
         return;
     --len;
@@ -122,8 +122,8 @@
         const STRING * const ret = Parrot_vsprintf_c(interp, pat, args);
         /* string_transcode(interp, ret, NULL, NULL, &ret); */
 
-        str_ret = Parrot_str_to_cstring(interp, ret);
-        str_len = strlen(str_ret);
+        char     * const str_ret = Parrot_str_to_cstring(interp, ret);
+        const    size_t  str_len = strlen(str_ret);
         if (len > str_len) {
             len = str_len;
         }

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/packfile.c	Tue May  4 07:50:22 2010	(r46275)
@@ -2335,7 +2335,7 @@
     size = 1 + default_packed_size(self);
 
     for (i = 0; i < dir->num_segments; ++i) {
-        char *name = Parrot_str_to_cstring(interp, dir->segments[i]->name);
+        char * const name = Parrot_str_to_cstring(interp, dir->segments[i]->name);
         /* type, offset, size */
         size += 3;
         size += PF_size_cstring(name);

Modified: trunk/src/pmc/fixedbooleanarray.pmc
==============================================================================
--- trunk/src/pmc/fixedbooleanarray.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/pmc/fixedbooleanarray.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -581,13 +581,11 @@
         SUPER(info);
 
         {
-            unsigned char * bit_array;
-            UINTVAL         threshold;
             const INTVAL    size      = VTABLE_shift_integer(INTERP, info);
             STRING * const  s         = VTABLE_shift_string(INTERP, info);
 
-            bit_array = (unsigned char *)Parrot_str_to_cstring(INTERP, s);
-            threshold = Parrot_str_byte_length(interp, s) * BITS_PER_CHAR;
+            unsigned char * const bit_array = (unsigned char *)Parrot_str_to_cstring(INTERP, s);
+            const UINTVAL   threshold = Parrot_str_byte_length(interp, s) * BITS_PER_CHAR;
 
             SET_ATTR_size(INTERP, SELF, size);
             SET_ATTR_resize_threshold(INTERP, SELF, threshold);

Modified: trunk/src/pmc/opcode.pmc
==============================================================================
--- trunk/src/pmc/opcode.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/pmc/opcode.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -45,7 +45,7 @@
     }
 
     VTABLE void set_string_native(STRING *name) {
-        char * cstr = Parrot_str_to_cstring(INTERP, name);
+        char * const cstr = Parrot_str_to_cstring(INTERP, name);
         const INTVAL num = INTERP->op_lib->op_code(INTERP, cstr, 1);
         Parrot_str_free_cstring(cstr);
         if (num == -1)

Modified: trunk/src/pmc/oplib.pmc
==============================================================================
--- trunk/src/pmc/oplib.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/pmc/oplib.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -56,7 +56,7 @@
     /* Look up an opnumber given the name of the op. First we look for the
        specific name, then the more general short name. */
     VTABLE INTVAL get_integer_keyed_str(STRING *name) {
-        char * cstr = Parrot_str_to_cstring(INTERP, name);
+        char * const cstr = Parrot_str_to_cstring(INTERP, name);
         INTVAL num = INTERP->op_lib->op_code(INTERP, cstr, 1);
         if (num == -1)
             num = INTERP->op_lib->op_code(INTERP, cstr, 0);
@@ -105,7 +105,7 @@
 
     METHOD op_family(STRING *shortname)
     {
-        char *sname = Parrot_str_to_cstring(INTERP, shortname);
+        char * const sname = Parrot_str_to_cstring(INTERP, shortname);
         const op_lib_t * const op_lib = INTERP->op_lib;
         const op_info_t * const table = op_lib->op_info_table;
         PMC *result = PMCNULL;

Modified: trunk/src/pmc/resizablebooleanarray.pmc
==============================================================================
--- trunk/src/pmc/resizablebooleanarray.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/pmc/resizablebooleanarray.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -454,12 +454,12 @@
 
 */
     VTABLE void thaw(PMC *info) {
-        unsigned char   *bit_array;
+
         const UINTVAL    head_pos = VTABLE_shift_integer(INTERP, info);
         const UINTVAL    tail_pos = VTABLE_shift_integer(INTERP, info);
         STRING * const   s        = VTABLE_shift_string(INTERP, info);
 
-        bit_array      = (unsigned char*)Parrot_str_to_cstring(INTERP, s);
+        unsigned char * const bit_array = (unsigned char*)Parrot_str_to_cstring(INTERP, s);
         SET_ATTR_size(INTERP, SELF, tail_pos);
         SET_ATTR_resize_threshold(INTERP, SELF, head_pos);
         SET_ATTR_bit_array(INTERP, SELF, bit_array);

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc	Tue May  4 07:05:39 2010	(r46274)
+++ trunk/src/pmc/string.pmc	Tue May  4 07:50:22 2010	(r46275)
@@ -541,7 +541,7 @@
 
         /* TODO verify encoding */
         const STRING *me  = VTABLE_get_string(INTERP, SELF);
-        char         *str = Parrot_str_to_cstring(INTERP, me);
+        char  * const str = Parrot_str_to_cstring(INTERP, me);
         UINTVAL       i   = 0;
         size_t        j   = 0;
         size_t        len = strlen(str);


More information about the parrot-commits mailing list