[svn:parrot] r45507 - branches/immutable_strings_part1/src/string

bacek at svn.parrot.org bacek at svn.parrot.org
Sat Apr 10 13:35:03 UTC 2010


Author: bacek
Date: Sat Apr 10 13:35:02 2010
New Revision: 45507
URL: https://trac.parrot.org/parrot/changeset/45507

Log:
Add helper clone_string function

Modified:
   branches/immutable_strings_part1/src/string/api.c

Modified: branches/immutable_strings_part1/src/string/api.c
==============================================================================
--- branches/immutable_strings_part1/src/string/api.c	Sat Apr 10 09:55:03 2010	(r45506)
+++ branches/immutable_strings_part1/src/string/api.c	Sat Apr 10 13:35:02 2010	(r45507)
@@ -43,6 +43,12 @@
 
 PARROT_INLINE
 PARROT_WARN_UNUSED_RESULT
+static STRING* clone_string(PARROT_INTERP, ARGIN(STRING const * const s))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 static const CHARSET * string_rep_compatible(SHIM_INTERP,
     ARGIN(const STRING *a),
@@ -53,6 +59,9 @@
         __attribute__nonnull__(4)
         FUNC_MODIFIES(*e);
 
+#define ASSERT_ARGS_clone_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_string_rep_compatible __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(a) \
     , PARROT_ASSERT_ARG(b) \
@@ -327,6 +336,33 @@
     return NULL;
 }
 
+/*
+
+=item C<static STRING* clone_string(PARROT_INTERP, STRING const * const s)>
+
+Helper function to clone string.
+
+*/
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+static STRING*
+clone_string(PARROT_INTERP, ARGIN(STRING const * const s))
+{
+    ASSERT_ARGS(clone_string)
+
+    STRING *result = Parrot_gc_new_string_header(interp, 0);
+    size_t  alloc_size = s->bufused;
+
+    Parrot_gc_allocate_string_storage(interp, result, alloc_size);
+
+    /* now copy memory over */
+    mem_sys_memcopy(result->strstart, s->strstart, alloc_size);
+    result->strlen = s->strlen;
+
+    return result;
+}
+
 
 /*
 


More information about the parrot-commits mailing list