[svn:parrot] r45892 - in branches/string_consting: include/parrot src/string

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Apr 22 10:39:01 UTC 2010


Author: bacek
Date: Thu Apr 22 10:39:00 2010
New Revision: 45892
URL: https://trac.parrot.org/parrot/changeset/45892

Log:
Made Parrot_str_copy to accept const string

Modified:
   branches/string_consting/include/parrot/string_funcs.h
   branches/string_consting/src/string/api.c

Modified: branches/string_consting/include/parrot/string_funcs.h
==============================================================================
--- branches/string_consting/include/parrot/string_funcs.h	Thu Apr 22 10:15:49 2010	(r45891)
+++ branches/string_consting/include/parrot/string_funcs.h	Thu Apr 22 10:39:00 2010	(r45892)
@@ -109,10 +109,9 @@
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
-STRING * Parrot_str_copy(PARROT_INTERP, ARGMOD(STRING *s))
+STRING * Parrot_str_copy(PARROT_INTERP, ARGIN(const STRING *s))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*s);
+        __attribute__nonnull__(2);
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL

Modified: branches/string_consting/src/string/api.c
==============================================================================
--- branches/string_consting/src/string/api.c	Thu Apr 22 10:15:49 2010	(r45891)
+++ branches/string_consting/src/string/api.c	Thu Apr 22 10:39:00 2010	(r45892)
@@ -355,7 +355,7 @@
 
 /*
 
-=item C<STRING * Parrot_str_copy(PARROT_INTERP, STRING *s)>
+=item C<STRING * Parrot_str_copy(PARROT_INTERP, const STRING *s)>
 
 Creates and returns a shallow copy of the specified Parrot string.
 
@@ -367,18 +367,19 @@
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 STRING *
-Parrot_str_copy(PARROT_INTERP, ARGMOD(STRING *s))
+Parrot_str_copy(PARROT_INTERP, ARGIN(const STRING *s))
 {
     ASSERT_ARGS(Parrot_str_copy)
-    STRING *d;
+    STRING *d = Parrot_gc_new_string_header(interp,
+                    PObj_get_FLAGS(s) & ~PObj_constant_FLAG);
+
+    DECL_CONST_CAST;
 
     /* We set COW flag to avoid cloning buffer in compact_pool */
+    PObj_COW_SET(PARROT_const_cast(STRING*, s));
+    STRUCT_COPY(d, s);
 
     if (PObj_constant_TEST(s)) {
-        d = Parrot_gc_new_string_header(interp,
-            PObj_get_FLAGS(s) & ~PObj_constant_FLAG);
-        PObj_COW_SET(s);
-        STRUCT_COPY(d, s);
         /* we can't move the memory, because constants aren't
          * scanned in compact_pool, therefore the other end
          * would point to garbage.
@@ -387,9 +388,6 @@
         PObj_external_SET(d);
     }
     else {
-        d = Parrot_gc_new_string_header(interp, PObj_get_FLAGS(s));
-        PObj_COW_SET(s);
-        STRUCT_COPY(d, s);
         PObj_sysmem_CLEAR(d);
     }
 


More information about the parrot-commits mailing list