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
63be55c7
Commit
63be55c7
authored
Jun 11, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2386 from suzukaze/add-nofree-macro
Add NOFREE macros
parents
fe95f440
9c259c50
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
8 deletions
+12
-8
include/mruby/string.h
include/mruby/string.h
+4
-0
mrbgems/mruby-string-ext/src/string.c
mrbgems/mruby-string-ext/src/string.c
+2
-2
src/string.c
src/string.c
+6
-6
No files found.
include/mruby/string.h
View file @
63be55c7
...
...
@@ -55,6 +55,10 @@ struct RString {
#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
#define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED)
#define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE)
#define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE)
#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
#define RSTRING(s) mrb_str_ptr(s)
#define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
...
...
mrbgems/mruby-string-ext/src/string.c
View file @
63be55c7
...
...
@@ -254,8 +254,8 @@ mrb_str_clear(mrb_state *mrb, mrb_value str)
struct
RString
*
s
=
mrb_str_ptr
(
str
);
if
(
!
RSTR_SHARED_P
(
s
)
&&
!
RSTR_EMBED_P
(
s
))
{
if
(
s
->
flags
&
MRB_STR_NOFREE
)
{
s
->
flags
&=
~
MRB_STR_NOFREE
;
if
(
RSTR_NOFREE_P
(
s
)
)
{
RSTR_UNSET_NOFREE_FLAG
(
s
)
;
}
else
{
mrb_free
(
mrb
,
s
->
as
.
heap
.
ptr
);
...
...
src/string.c
View file @
63be55c7
...
...
@@ -106,7 +106,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
RSTR_UNSET_SHARED_FLAG
(
s
);
return
;
}
if
(
s
->
flags
&
MRB_STR_NOFREE
)
{
if
(
RSTR_NOFREE_P
(
s
)
)
{
char
*
p
=
s
->
as
.
heap
.
ptr
;
s
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_malloc
(
mrb
,
(
size_t
)
s
->
as
.
heap
.
len
+
1
);
...
...
@@ -115,7 +115,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
}
RSTR_PTR
(
s
)[
s
->
as
.
heap
.
len
]
=
'\0'
;
s
->
as
.
heap
.
aux
.
capa
=
s
->
as
.
heap
.
len
;
s
->
flags
&=
~
MRB_STR_NOFREE
;
RSTR_UNSET_NOFREE_FLAG
(
s
)
;
return
;
}
}
...
...
@@ -302,7 +302,7 @@ mrb_gc_free_str(mrb_state *mrb, struct RString *str)
/* no code */
;
else
if
(
RSTR_SHARED_P
(
str
))
str_decref
(
mrb
,
str
->
as
.
heap
.
aux
.
shared
);
else
if
(
(
str
->
flags
&
MRB_STR_NOFREE
)
==
0
)
else
if
(
RSTR_NOFREE_P
(
str
)
==
0
)
mrb_free
(
mrb
,
str
->
as
.
heap
.
ptr
);
}
...
...
@@ -340,10 +340,10 @@ str_make_shared(mrb_state *mrb, struct RString *s)
shared
->
nofree
=
FALSE
;
shared
->
ptr
=
s
->
as
.
heap
.
ptr
;
}
else
if
(
s
->
flags
&
MRB_STR_NOFREE
)
{
else
if
(
RSTR_NOFREE_P
(
s
)
)
{
shared
->
nofree
=
TRUE
;
shared
->
ptr
=
s
->
as
.
heap
.
ptr
;
s
->
flags
&=
~
MRB_STR_NOFREE
;
RSTR_UNSET_NOFREE_FLAG
(
s
)
;
}
else
{
shared
->
nofree
=
FALSE
;
...
...
@@ -1373,7 +1373,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
if
(
RSTR_SHARED_P
(
s1
))
{
str_decref
(
mrb
,
s1
->
as
.
heap
.
aux
.
shared
);
}
else
if
(
!
RSTR_EMBED_P
(
s1
)
&&
!
(
s1
->
flags
&
MRB_STR_NOFREE
))
{
else
if
(
!
RSTR_EMBED_P
(
s1
)
&&
!
RSTR_NOFREE_P
(
s1
))
{
mrb_free
(
mrb
,
s1
->
as
.
heap
.
ptr
);
}
RSTR_UNSET_EMBED_FLAG
(
s1
);
...
...
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