Commit 9c259c50 authored by Jun Hiroe's avatar Jun Hiroe

Add NOFREE macros

parent fe95f440
...@@ -55,6 +55,10 @@ struct RString { ...@@ -55,6 +55,10 @@ struct RString {
#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED) #define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
#define RSTR_UNSET_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 mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
#define RSTRING(s) mrb_str_ptr(s) #define RSTRING(s) mrb_str_ptr(s)
#define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
......
...@@ -254,8 +254,8 @@ mrb_str_clear(mrb_state *mrb, mrb_value str) ...@@ -254,8 +254,8 @@ mrb_str_clear(mrb_state *mrb, mrb_value str)
struct RString *s = mrb_str_ptr(str); struct RString *s = mrb_str_ptr(str);
if (!RSTR_SHARED_P(s) && !RSTR_EMBED_P(s)) { if (!RSTR_SHARED_P(s) && !RSTR_EMBED_P(s)) {
if (s->flags & MRB_STR_NOFREE) { if (RSTR_NOFREE_P(s)) {
s->flags &= ~MRB_STR_NOFREE; RSTR_UNSET_NOFREE_FLAG(s);
} }
else { else {
mrb_free(mrb, s->as.heap.ptr); mrb_free(mrb, s->as.heap.ptr);
......
...@@ -106,7 +106,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s) ...@@ -106,7 +106,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
RSTR_UNSET_SHARED_FLAG(s); RSTR_UNSET_SHARED_FLAG(s);
return; return;
} }
if (s->flags & MRB_STR_NOFREE) { if (RSTR_NOFREE_P(s)) {
char *p = s->as.heap.ptr; char *p = s->as.heap.ptr;
s->as.heap.ptr = (char *)mrb_malloc(mrb, (size_t)s->as.heap.len+1); 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) ...@@ -115,7 +115,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
} }
RSTR_PTR(s)[s->as.heap.len] = '\0'; RSTR_PTR(s)[s->as.heap.len] = '\0';
s->as.heap.aux.capa = s->as.heap.len; s->as.heap.aux.capa = s->as.heap.len;
s->flags &= ~MRB_STR_NOFREE; RSTR_UNSET_NOFREE_FLAG(s);
return; return;
} }
} }
...@@ -302,7 +302,7 @@ mrb_gc_free_str(mrb_state *mrb, struct RString *str) ...@@ -302,7 +302,7 @@ mrb_gc_free_str(mrb_state *mrb, struct RString *str)
/* no code */; /* no code */;
else if (RSTR_SHARED_P(str)) else if (RSTR_SHARED_P(str))
str_decref(mrb, str->as.heap.aux.shared); 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); mrb_free(mrb, str->as.heap.ptr);
} }
...@@ -340,10 +340,10 @@ str_make_shared(mrb_state *mrb, struct RString *s) ...@@ -340,10 +340,10 @@ str_make_shared(mrb_state *mrb, struct RString *s)
shared->nofree = FALSE; shared->nofree = FALSE;
shared->ptr = s->as.heap.ptr; shared->ptr = s->as.heap.ptr;
} }
else if (s->flags & MRB_STR_NOFREE) { else if (RSTR_NOFREE_P(s)) {
shared->nofree = TRUE; shared->nofree = TRUE;
shared->ptr = s->as.heap.ptr; shared->ptr = s->as.heap.ptr;
s->flags &= ~MRB_STR_NOFREE; RSTR_UNSET_NOFREE_FLAG(s);
} }
else { else {
shared->nofree = FALSE; shared->nofree = FALSE;
...@@ -1373,7 +1373,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2) ...@@ -1373,7 +1373,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
if (RSTR_SHARED_P(s1)) { if (RSTR_SHARED_P(s1)) {
str_decref(mrb, s1->as.heap.aux.shared); 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); mrb_free(mrb, s1->as.heap.ptr);
} }
RSTR_UNSET_EMBED_FLAG(s1); RSTR_UNSET_EMBED_FLAG(s1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment