Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
bd538189
Commit
bd538189
authored
Jun 11, 2014
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
str_replace: self should not be shared and nofree
parent
63be55c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
src/string.c
src/string.c
+11
-7
test/t/string.rb
test/t/string.rb
+7
-0
No files found.
src/string.c
View file @
bd538189
...
@@ -1368,14 +1368,17 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
...
@@ -1368,14 +1368,17 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
long
len
;
long
len
;
len
=
RSTR_LEN
(
s2
);
len
=
RSTR_LEN
(
s2
);
if
(
RSTR_SHARED_P
(
s1
))
{
str_decref
(
mrb
,
s1
->
as
.
heap
.
aux
.
shared
);
}
else
if
(
!
RSTR_EMBED_P
(
s1
)
&&
!
RSTR_NOFREE_P
(
s1
))
{
mrb_free
(
mrb
,
s1
->
as
.
heap
.
ptr
);
}
RSTR_UNSET_NOFREE_FLAG
(
s1
);
if
(
RSTR_SHARED_P
(
s2
))
{
if
(
RSTR_SHARED_P
(
s2
))
{
L_SHARE:
L_SHARE:
if
(
RSTR_SHARED_P
(
s1
))
{
str_decref
(
mrb
,
s1
->
as
.
heap
.
aux
.
shared
);
}
else
if
(
!
RSTR_EMBED_P
(
s1
)
&&
!
RSTR_NOFREE_P
(
s1
))
{
mrb_free
(
mrb
,
s1
->
as
.
heap
.
ptr
);
}
RSTR_UNSET_EMBED_FLAG
(
s1
);
RSTR_UNSET_EMBED_FLAG
(
s1
);
s1
->
as
.
heap
.
ptr
=
s2
->
as
.
heap
.
ptr
;
s1
->
as
.
heap
.
ptr
=
s2
->
as
.
heap
.
ptr
;
s1
->
as
.
heap
.
len
=
len
;
s1
->
as
.
heap
.
len
=
len
;
...
@@ -1385,6 +1388,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
...
@@ -1385,6 +1388,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
}
}
else
{
else
{
if
(
len
<=
RSTRING_EMBED_LEN_MAX
)
{
if
(
len
<=
RSTRING_EMBED_LEN_MAX
)
{
RSTR_UNSET_SHARED_FLAG
(
s1
);
RSTR_SET_EMBED_FLAG
(
s1
);
RSTR_SET_EMBED_FLAG
(
s1
);
memcpy
(
s1
->
as
.
ary
,
RSTR_PTR
(
s2
),
len
);
memcpy
(
s1
->
as
.
ary
,
RSTR_PTR
(
s2
),
len
);
RSTR_SET_EMBED_LEN
(
s1
,
len
);
RSTR_SET_EMBED_LEN
(
s1
,
len
);
...
...
test/t/string.rb
View file @
bd538189
...
@@ -320,6 +320,13 @@ assert('String#replace', '15.2.10.5.28') do
...
@@ -320,6 +320,13 @@ assert('String#replace', '15.2.10.5.28') do
b
.
replace
(
c
);
b
.
replace
(
c
);
c
.
replace
(
b
);
c
.
replace
(
b
);
assert_equal
c
,
b
assert_equal
c
,
b
# shared string
s
=
"foo"
*
100
a
=
s
[
10
,
90
]
# create shared string
assert_equal
(
""
,
s
.
replace
(
""
))
# clear
assert_equal
(
""
,
s
)
# s is cleared
assert_not_equal
(
""
,
a
)
# a should not be affected
end
end
assert
(
'String#reverse'
,
'15.2.10.5.29'
)
do
assert
(
'String#reverse'
,
'15.2.10.5.29'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment