summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-08-18 19:44:00 +0900
committerKOBAYASHI Shuji <[email protected]>2019-08-18 19:44:00 +0900
commitaaa509dd076e7de654a6c555bec264083c145388 (patch)
tree665ff3b8e431ff59eb46923e367b61ac0d20a6c4
parent83dab1ee0d0d3aa76e44f7fbf14360ee501be151 (diff)
downloadmruby-aaa509dd076e7de654a6c555bec264083c145388.tar.gz
mruby-aaa509dd076e7de654a6c555bec264083c145388.zip
Also use `str_init_shared` for `orig` in `str_make_shared()`
-rw-r--r--src/string.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c
index ab53c2e69..10e20c3b1 100644
--- a/src/string.c
+++ b/src/string.c
@@ -77,7 +77,7 @@ str_init_shared(mrb_state *mrb, const struct RString *orig, struct RString *s, m
}
else {
shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string));
- shared->refcnt = 2;
+ shared->refcnt = 1;
shared->ptr = orig->as.heap.ptr;
shared->len = orig->as.heap.len;
}
@@ -516,7 +516,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
static void
str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s)
{
- mrb_int len = RSTR_LEN(orig);
+ size_t len = (size_t)orig->as.heap.len;
mrb_assert(!RSTR_EMBED_P(orig));
if (RSTR_NOFREE_P(orig)) {
@@ -536,8 +536,7 @@ str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s)
orig->as.heap.ptr = (char *)mrb_realloc(mrb, orig->as.heap.ptr, len+1);
}
str_init_shared(mrb, orig, s, NULL);
- orig->as.heap.aux.shared = s->as.heap.aux.shared;
- RSTR_SET_TYPE_FLAG(orig, SHARED);
+ str_init_shared(mrb, orig, orig, s->as.heap.aux.shared);
}
}