[svn:parrot] r40939 - in trunk/src: . dynpmc pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Sep 3 01:48:27 UTC 2009


Author: cotto
Date: Thu Sep  3 01:48:25 2009
New Revision: 40939
URL: https://trac.parrot.org/parrot/changeset/40939

Log:
[strings] first of many patches from darbelo++ getting rid of ->strstart abuse

Modified:
   trunk/src/dynpmc/gdbmhash.pmc
   trunk/src/misc.c
   trunk/src/pmc/fixedbooleanarray.pmc
   trunk/src/pmc/nci.pmc
   trunk/src/pmc/resizablebooleanarray.pmc

Modified: trunk/src/dynpmc/gdbmhash.pmc
==============================================================================
--- trunk/src/dynpmc/gdbmhash.pmc	Thu Sep  3 01:02:26 2009	(r40938)
+++ trunk/src/dynpmc/gdbmhash.pmc	Thu Sep  3 01:48:25 2009	(r40939)
@@ -214,13 +214,16 @@
         if (!dbf) return;
         keystr = make_hash_key(interp, key);
 
-        key_gdbm.dsize = keystr->strlen;
-        key_gdbm.dptr  = keystr->strstart;
-        val_gdbm.dsize = value->strlen;
-        val_gdbm.dptr  = value->strstart;
+        key_gdbm.dptr  = Parrot_str_to_cstring(interp, keystr);
+        key_gdbm.dsize = strlen(key_gdbm.dptr);
+        val_gdbm.dptr  = Parrot_str_to_cstring(interp, value);
+        val_gdbm.dsize = strlen(val_gdbm.dptr);
 
         gdbm_store(dbf, key_gdbm, val_gdbm, GDBM_REPLACE);
 
+        Parrot_str_free_cstring(key_gdbm.dptr);
+        Parrot_str_free_cstring(val_gdbm.dptr);
+
         return;
     }
 

Modified: trunk/src/misc.c
==============================================================================
--- trunk/src/misc.c	Thu Sep  3 01:02:26 2009	(r40938)
+++ trunk/src/misc.c	Thu Sep  3 01:48:25 2009	(r40939)
@@ -112,6 +112,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--;
@@ -119,12 +121,15 @@
         const STRING * const ret = Parrot_vsprintf_c(interp, pat, args);
         /* string_transcode(interp, ret, NULL, NULL, &ret); */
 
-        if (len > ret->bufused) {
-            len = ret->bufused;
+        str_ret = Parrot_str_to_cstring(interp, ret);
+        str_len = strlen(str_ret);
+        if (len > str_len) {
+            len = str_len;
         }
 
         if (len)
-            memcpy(targ, ret->strstart, len);
+            memcpy(targ, str_ret, len);
+        Parrot_str_free_cstring(str_ret);
     }
     targ[len] = 0;
 }

Modified: trunk/src/pmc/fixedbooleanarray.pmc
==============================================================================
--- trunk/src/pmc/fixedbooleanarray.pmc	Thu Sep  3 01:02:26 2009	(r40938)
+++ trunk/src/pmc/fixedbooleanarray.pmc	Thu Sep  3 01:48:25 2009	(r40939)
@@ -550,15 +550,15 @@
 
         if (info->extra_flags == EXTRA_IS_NULL) {
             unsigned char * bit_array;
+            UINTVAL         threshold;
             const INTVAL    size      = VTABLE_shift_integer(INTERP, io);
             STRING * const  s         = VTABLE_shift_string(INTERP, io);
 
-            bit_array = (unsigned char*)mem_sys_allocate_zeroed(s->bufused);
-            mem_sys_memcopy(bit_array, s->strstart, s->bufused);
-
+            bit_array = Parrot_str_to_cstring(INTERP, s);
+            threshold = Parrot_str_byte_length(interp, s) * BITS_PER_CHAR;
+                    
             SET_ATTR_size(INTERP, SELF, size);
-            SET_ATTR_resize_threshold(INTERP, SELF,
-                    s->bufused * BITS_PER_CHAR);
+            SET_ATTR_resize_threshold(INTERP, SELF, threshold);
             SET_ATTR_bit_array(INTERP, SELF, bit_array);
         }
     }

Modified: trunk/src/pmc/nci.pmc
==============================================================================
--- trunk/src/pmc/nci.pmc	Thu Sep  3 01:02:26 2009	(r40938)
+++ trunk/src/pmc/nci.pmc	Thu Sep  3 01:48:25 2009	(r40939)
@@ -302,6 +302,7 @@
     VTABLE opcode_t *invoke(void *next) {
         Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
         nci_sub_t                     func;
+        char                         *sig_str;
         void                         *orig_func;
         PMC                          *cont;
 
@@ -324,7 +325,9 @@
             nci_jit_sub_t jit_func = (nci_jit_sub_t) D2FPTR(nci_info->func);
 
             /* Parrot_eprintf(interp, "JITTED %S\n", nci_info->signature); */
-            jit_func(INTERP, SELF, (char *) nci_info->pcc_params_signature->strstart);
+            sig_str = Parrot_str_to_cstring(interp, nci_info->pcc_params_signature);
+            jit_func(INTERP, SELF, sig_str);
+            Parrot_str_free_cstring(sig_str);
         }
         else {
             if (PObj_flag_TEST(private2, SELF)) {

Modified: trunk/src/pmc/resizablebooleanarray.pmc
==============================================================================
--- trunk/src/pmc/resizablebooleanarray.pmc	Thu Sep  3 01:02:26 2009	(r40938)
+++ trunk/src/pmc/resizablebooleanarray.pmc	Thu Sep  3 01:48:25 2009	(r40939)
@@ -453,8 +453,7 @@
         const UINTVAL    tail_pos = VTABLE_shift_integer(INTERP, io);
         STRING * const   s        = VTABLE_shift_string(INTERP, io);
 
-        bit_array      = (unsigned char *)mem_sys_allocate_zeroed(s->bufused);
-        mem_sys_memcopy(bit_array, (unsigned char *)s->strstart, s->bufused);
+        bit_array      = Parrot_str_to_cstring(INTERP, s);
         PMC_data(SELF) =
             mem_allocate_zeroed_typed(Parrot_ResizableBooleanArray_attributes);
 


More information about the parrot-commits mailing list