[svn:parrot] r48635 - trunk/src/string
nwellnhof at svn.parrot.org
nwellnhof at svn.parrot.org
Tue Aug 24 17:19:45 UTC 2010
Author: nwellnhof
Date: Tue Aug 24 17:19:45 2010
New Revision: 48635
URL: https://trac.parrot.org/parrot/changeset/48635
Log:
Clarify handling of flags in str_copy
Modified:
trunk/src/string/api.c
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Tue Aug 24 17:14:54 2010 (r48634)
+++ trunk/src/string/api.c Tue Aug 24 17:19:45 2010 (r48635)
@@ -382,18 +382,21 @@
Parrot_str_copy(PARROT_INTERP, ARGIN(const STRING *s))
{
ASSERT_ARGS(Parrot_str_copy)
- STRING *d;
+ STRING * const d = Parrot_gc_new_string_header(interp, 0);
const int is_movable = PObj_is_movable_TESTALL(s);
- /* We set COW flag to avoid cloning buffer in compact_pool */
-
- d = Parrot_gc_new_string_header(interp,
- PObj_get_FLAGS(s) & ~PObj_constant_FLAG);
- /* This overwrites the constant flag again. Not sure if this is OK */
+ /* Copy encoding/charset/etc */
STRUCT_COPY(d, s);
- /* Clear live flag. It might be set on constant strings */
- PObj_live_CLEAR(d);
+ /* Only copy is_COWable, constant, and external flags.
+ * Note that it's important (and safe) to copy the constant flag
+ * although the copied string header is not allocated from the constant
+ * string header pool. */
+ PObj_get_FLAGS(d) = PObj_is_string_FLAG
+ | (PObj_get_FLAGS(s)
+ & (PObj_is_COWable_FLAG
+ | PObj_constant_FLAG
+ | PObj_external_FLAG));
/* Now check that buffer allocated from pool and affected by compacting */
if (is_movable && Buffer_bufstart(s)) {
More information about the parrot-commits
mailing list