[svn:parrot] r39775 - in trunk: compilers/imcc include/parrot src src/gc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu Jun 25 19:55:07 UTC 2009


Author: NotFound
Date: Thu Jun 25 19:55:05 2009
New Revision: 39775
URL: https://trac.parrot.org/parrot/changeset/39775

Log:
[core] add new function mem_sys_strdup to memory.h and replace several usages of str_dup with it

Modified:
   trunk/compilers/imcc/instructions.c
   trunk/compilers/imcc/main.c
   trunk/compilers/imcc/optimizer.c
   trunk/compilers/imcc/parser_util.c
   trunk/compilers/imcc/pbc.c
   trunk/compilers/imcc/symreg.c
   trunk/include/parrot/memory.h
   trunk/src/gc/alloc_memory.c
   trunk/src/library.c
   trunk/src/packfile.c
   trunk/src/parrot_debugger.c
   trunk/src/pbc_merge.c

Modified: trunk/compilers/imcc/instructions.c
==============================================================================
--- trunk/compilers/imcc/instructions.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/instructions.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -103,8 +103,8 @@
         (Instruction*)mem_sys_allocate_zeroed(sizeof (Instruction) + reg_space);
     int i;
 
-    ins->opname       = str_dup(op);
-    ins->format       = str_dup(fmt);
+    ins->opname       = mem_sys_strdup(op);
+    ins->format       = mem_sys_strdup(fmt);
     ins->symreg_count = n;
 
     for (i = 0; i < n; i++)

Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/main.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -955,7 +955,7 @@
     Parrot_pbc_load(interp, pf);
 
     IMCC_push_parser_state(interp);
-    IMCC_INFO(interp)->state->file = str_dup(sourcefile);
+    IMCC_INFO(interp)->state->file = mem_sys_strdup(sourcefile);
 
     emit_open(interp, per_pbc, per_pbc ? NULL : (void*)output_file);
 

Modified: trunk/compilers/imcc/optimizer.c
==============================================================================
--- trunk/compilers/imcc/optimizer.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/optimizer.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -368,7 +368,7 @@
                     last->opnum = tmp->opnum;
                     last->opsize = tmp->opsize;
                     free(last->opname);
-                    last->opname = str_dup(tmp->opname);
+                    last->opname = mem_sys_strdup(tmp->opname);
                     free_ins(tmp);
 
                     /* delete branch */

Modified: trunk/compilers/imcc/parser_util.c
==============================================================================
--- trunk/compilers/imcc/parser_util.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/parser_util.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -677,7 +677,7 @@
         IMCC_INFO(interp)->state->next = NULL;
 
     IMCC_INFO(interp)->state->pasm_file = pasm_file;
-    IMCC_INFO(interp)->state->file      = str_dup(name);
+    IMCC_INFO(interp)->state->file      = mem_sys_strdup(name);
     IMCC_INFO(interp)->expect_pasm      = 0;
 
     compile_string(interp, s, yyscanner);
@@ -941,7 +941,7 @@
     IMCC_push_parser_state(interp);
     {
         /* Store a copy, in order to know how to free it later */
-        char *copyname = str_dup(fullname);
+        char *copyname = mem_sys_strdup(fullname);
         IMCC_INFO(interp)->state->file = copyname;
         ext                            = strrchr(copyname, '.');
     }

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/pbc.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -1348,7 +1348,7 @@
         ns_const  = ns->color;
 
         if (real_name) {
-            char * const p = str_dup(real_name + 1);
+            char * const p = mem_sys_strdup(real_name + 1);
             free(r->name);
             r->name = p;
         }
@@ -1394,7 +1394,7 @@
         unit->subid = r;
     else {
         /* trim the quotes  */
-        unit->subid->name = str_dup(unit->subid->name + 1);
+        unit->subid->name = mem_sys_strdup(unit->subid->name + 1);
         unit->subid->name[strlen(unit->subid->name) - 1] = 0;
 
         /* create string constant for it. */

Modified: trunk/compilers/imcc/symreg.c
==============================================================================
--- trunk/compilers/imcc/symreg.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/compilers/imcc/symreg.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -145,7 +145,7 @@
     Namespace * const ns = mem_allocate_zeroed_typed(Namespace);
 
     ns->parent = pesky_global__namespace;
-    ns->name   = str_dup(name);
+    ns->name   = mem_sys_strdup(name);
     pesky_global__namespace = ns;
 }
 
@@ -267,7 +267,7 @@
         r             = mem_allocate_zeroed_typed(SymReg);
         r->set        = t;
         r->type       = VTREG;
-        r->name       = str_dup(name);
+        r->name       = mem_sys_strdup(name);
         r->color      = -1;
         r->want_regno = -1;
 
@@ -619,7 +619,7 @@
         return result;
     }
 
-    return str_dup(name);
+    return mem_sys_strdup(name);
 }
 
 
@@ -722,7 +722,7 @@
     r[0] = left;
 
     /* strip delimiters */
-    name          = str_dup(rhs->name + 1);
+    name          = mem_sys_strdup(rhs->name + 1);
     len           = strlen(name);
     name[len - 1] = '\0';
 
@@ -920,7 +920,7 @@
 
     if (!IMCC_INFO(interp)->cur_namespace
     || (l = strlen(IMCC_INFO(interp)->cur_namespace->name)) <= 2)
-        return str_dup(name);
+        return mem_sys_strdup(name);
 
     /* TODO keyed syntax */
     len     = strlen(name) + l  + 4;
@@ -967,7 +967,7 @@
     if (uniq == U_add_all) {
         r       = mem_allocate_zeroed_typed(SymReg);
         r->type = VTADDRESS;
-        r->name = str_dup(name);
+        r->name = mem_sys_strdup(name);
         _store_symreg(hsh, r);
     }
     else {
@@ -1150,7 +1150,7 @@
     ASSERT_ARGS(dup_sym)
     SymReg * const new_sym = mem_allocate_zeroed_typed(SymReg);
     STRUCT_COPY(new_sym, r);
-    new_sym->name = str_dup(r->name);
+    new_sym->name = mem_sys_strdup(r->name);
 
     if (r->nextkey)
         new_sym->nextkey = dup_sym(r->nextkey);

Modified: trunk/include/parrot/memory.h
==============================================================================
--- trunk/include/parrot/memory.h	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/include/parrot/memory.h	Thu Jun 25 19:55:05 2009	(r39775)
@@ -70,6 +70,12 @@
     size_t size,
     size_t old_size);
 
+PARROT_EXPORT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+char * mem_sys_strdup(ARGIN(const char *src))
+        __attribute__nonnull__(1);
+
 PARROT_MALLOC
 PARROT_CANNOT_RETURN_NULL
 void * mem__internal_allocate(
@@ -116,6 +122,8 @@
 #define ASSERT_ARGS_mem_sys_free __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_mem_sys_realloc __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_mem_sys_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
+#define ASSERT_ARGS_mem_sys_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(src)
 #define ASSERT_ARGS_mem__internal_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(file)
 #define ASSERT_ARGS_mem__internal_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = \

Modified: trunk/src/gc/alloc_memory.c
==============================================================================
--- trunk/src/gc/alloc_memory.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/src/gc/alloc_memory.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -343,6 +343,32 @@
 
 /*
 
+=item C<char * mem_sys_strdup(const char *src)>
+
+Copy a C string to a new block of memory allocated with mem_sys_allocate,
+that can be later deallocated with mem_sys_free.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+char *
+mem_sys_strdup(ARGIN(const char *src))
+{
+    ASSERT_ARGS(mem_sys_strdup)
+
+    size_t l = strlen(src);
+    char *result = (char *)mem_sys_allocate(l + 1);
+    memcpy(result, src, l);
+    result[l] = '\0';
+    return result;
+}
+
+/*
+
 =back
 
 =cut

Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/src/library.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -788,7 +788,7 @@
     char * const env = Parrot_getenv("PARROT_RUNTIME", &free_it);
 
     if (env)
-        return free_it ? env : str_dup(env);
+        return free_it ? env : mem_sys_strdup(env);
     else {
         PMC    * const config_hash =
             VTABLE_get_pmc_keyed_int(interp, interp->iglobals, (INTVAL) IGLOBALS_CONFIG_HASH);
@@ -799,7 +799,7 @@
             return Parrot_str_to_cstring(interp, s);
         }
         else
-            return str_dup(".");
+            return mem_sys_strdup(".");
     }
 }
 

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/src/packfile.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -2388,7 +2388,7 @@
     self->size        = 0;
     self->data        = NULL;
     self->id          = 0;
-    self->name        = str_dup(name);
+    self->name        = mem_sys_strdup(name);
 }
 
 
@@ -2733,7 +2733,7 @@
     }
 
     /* find seg e.g. CODE_DB => CODE and attach it */
-    code_name              = str_dup(debug->base.name);
+    code_name              = mem_sys_strdup(debug->base.name);
     str_len                = strlen(code_name);
     code_name[str_len - 3] = '\0';
     code                   = (PackFile_ByteCode *)PackFile_find_segment(interp,
@@ -3509,7 +3509,7 @@
 
     self->fixups[i]         = mem_allocate_typed(PackFile_FixupEntry);
     self->fixups[i]->type   = type;
-    self->fixups[i]->name   = str_dup(label);
+    self->fixups[i]->name   = mem_sys_strdup(label);
     self->fixups[i]->offset = offs;
     self->fixups[i]->seg    = self->code;
 }
@@ -4310,7 +4310,7 @@
     }
 
     /* Need to associate this segment with the applicable code segment. */
-    code_name              = str_dup(self->base.name);
+    code_name              = mem_sys_strdup(self->base.name);
     str_len                = strlen(code_name);
     code_name[str_len - 4] = '\0';
     code                   = (PackFile_ByteCode *)PackFile_find_segment(interp,

Modified: trunk/src/parrot_debugger.c
==============================================================================
--- trunk/src/parrot_debugger.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/src/parrot_debugger.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -184,7 +184,7 @@
             Parrot_pbc_load(interp, pf);
 
             IMCC_push_parser_state(interp);
-            IMCC_INFO(interp)->state->file = str_dup(filename);
+            IMCC_INFO(interp)->state->file = mem_sys_strdup(filename);
 
             if (!(imc_yyin_set(fopen(filename, "r"), yyscanner)))    {
                 IMCC_fatal_standalone(interp, EXCEPTION_PIO_ERROR,

Modified: trunk/src/pbc_merge.c
==============================================================================
--- trunk/src/pbc_merge.c	Thu Jun 25 17:56:50 2009	(r39774)
+++ trunk/src/pbc_merge.c	Thu Jun 25 19:55:05 2009	(r39775)
@@ -378,7 +378,7 @@
     /* Stash produced bytecode. */
     bc_seg->base.data = bc;
     bc_seg->base.size = cursor;
-    bc_seg->base.name = str_dup("MERGED");
+    bc_seg->base.name = mem_sys_strdup("MERGED");
     return bc_seg;
 }
 


More information about the parrot-commits mailing list