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
7c80edb5
Unverified
Commit
7c80edb5
authored
Nov 17, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert half of
9fbf0ef8
.
I misunderstand the meaning of #4483. Sorry.
parent
5abb283d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
25 deletions
+33
-25
include/mruby/array.h
include/mruby/array.h
+3
-3
include/mruby/string.h
include/mruby/string.h
+3
-3
include/mruby/value.h
include/mruby/value.h
+8
-0
src/string.c
src/string.c
+19
-19
No files found.
include/mruby/array.h
View file @
7c80edb5
...
@@ -17,7 +17,7 @@ MRB_BEGIN_DECL
...
@@ -17,7 +17,7 @@ MRB_BEGIN_DECL
typedef
struct
mrb_shared_array
{
typedef
struct
mrb_shared_array
{
int
refcnt
;
int
refcnt
;
mrb_
int
len
;
mrb_
ssize
len
;
mrb_value
*
ptr
;
mrb_value
*
ptr
;
}
mrb_shared_array
;
}
mrb_shared_array
;
...
@@ -33,9 +33,9 @@ struct RArray {
...
@@ -33,9 +33,9 @@ struct RArray {
MRB_OBJECT_HEADER
;
MRB_OBJECT_HEADER
;
union
{
union
{
struct
{
struct
{
mrb_
int
len
;
mrb_
ssize
len
;
union
{
union
{
mrb_
int
capa
;
mrb_
ssize
capa
;
mrb_shared_array
*
shared
;
mrb_shared_array
*
shared
;
}
aux
;
}
aux
;
mrb_value
*
ptr
;
mrb_value
*
ptr
;
...
...
include/mruby/string.h
View file @
7c80edb5
...
@@ -23,9 +23,9 @@ struct RString {
...
@@ -23,9 +23,9 @@ struct RString {
MRB_OBJECT_HEADER
;
MRB_OBJECT_HEADER
;
union
{
union
{
struct
{
struct
{
mrb_
int
len
;
mrb_
ssize
len
;
union
{
union
{
mrb_
int
capa
;
mrb_
ssize
capa
;
struct
mrb_shared_string
*
shared
;
struct
mrb_shared_string
*
shared
;
struct
RString
*
fshared
;
struct
RString
*
fshared
;
}
aux
;
}
aux
;
...
@@ -54,7 +54,7 @@ struct RStringEmbed {
...
@@ -54,7 +54,7 @@ struct RStringEmbed {
RSTR_SET_EMBED_LEN((s),(n));\
RSTR_SET_EMBED_LEN((s),(n));\
}\
}\
else {\
else {\
(s)->as.heap.len = (mrb_
int
)(n);\
(s)->as.heap.len = (mrb_
ssize
)(n);\
}\
}\
} while (0)
} while (0)
#define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary)
#define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary)
...
...
include/mruby/value.h
View file @
7c80edb5
...
@@ -168,6 +168,14 @@ struct RCptr {
...
@@ -168,6 +168,14 @@ struct RCptr {
#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT)
#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT)
#if INTPTR_MAX < MRB_INT_MAX
typedef
intptr_t
mrb_ssize
;
# define MRB_SSIZE_MAX (INTPTR_MAX>>MRB_FIXNUM_SHIFT)
#else
typedef
mrb_int
mrb_ssize
;
# define MRB_SSIZE_MAX MRB_INT_MAX
#endif
#ifndef mrb_immediate_p
#ifndef mrb_immediate_p
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#endif
#endif
...
...
src/string.c
View file @
7c80edb5
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
typedef
struct
mrb_shared_string
{
typedef
struct
mrb_shared_string
{
int
refcnt
;
int
refcnt
;
mrb_
int
capa
;
mrb_
ssize
capa
;
char
*
ptr
;
char
*
ptr
;
}
mrb_shared_string
;
}
mrb_shared_string
;
...
@@ -41,8 +41,8 @@ str_init_normal_capa(mrb_state *mrb, struct RString *s,
...
@@ -41,8 +41,8 @@ str_init_normal_capa(mrb_state *mrb, struct RString *s,
if
(
p
)
memcpy
(
dst
,
p
,
len
);
if
(
p
)
memcpy
(
dst
,
p
,
len
);
dst
[
len
]
=
'\0'
;
dst
[
len
]
=
'\0'
;
s
->
as
.
heap
.
ptr
=
dst
;
s
->
as
.
heap
.
ptr
=
dst
;
s
->
as
.
heap
.
len
=
(
mrb_
int
)
len
;
s
->
as
.
heap
.
len
=
(
mrb_
ssize
)
len
;
s
->
as
.
heap
.
aux
.
capa
=
(
mrb_
int
)
capa
;
s
->
as
.
heap
.
aux
.
capa
=
(
mrb_
ssize
)
capa
;
RSTR_UNSET_TYPE_FLAG
(
s
);
RSTR_UNSET_TYPE_FLAG
(
s
);
return
s
;
return
s
;
}
}
...
@@ -67,7 +67,7 @@ static struct RString*
...
@@ -67,7 +67,7 @@ static struct RString*
str_init_nofree
(
struct
RString
*
s
,
const
char
*
p
,
size_t
len
)
str_init_nofree
(
struct
RString
*
s
,
const
char
*
p
,
size_t
len
)
{
{
s
->
as
.
heap
.
ptr
=
(
char
*
)
p
;
s
->
as
.
heap
.
ptr
=
(
char
*
)
p
;
s
->
as
.
heap
.
len
=
(
mrb_
int
)
len
;
s
->
as
.
heap
.
len
=
(
mrb_
ssize
)
len
;
s
->
as
.
heap
.
aux
.
capa
=
0
;
/* nofree */
s
->
as
.
heap
.
aux
.
capa
=
0
;
/* nofree */
RSTR_SET_TYPE_FLAG
(
s
,
NOFREE
);
RSTR_SET_TYPE_FLAG
(
s
,
NOFREE
);
return
s
;
return
s
;
...
@@ -119,7 +119,7 @@ str_new_static(mrb_state *mrb, const char *p, size_t len)
...
@@ -119,7 +119,7 @@ str_new_static(mrb_state *mrb, const char *p, size_t len)
if
(
RSTR_EMBEDDABLE_P
(
len
))
{
if
(
RSTR_EMBEDDABLE_P
(
len
))
{
return
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
return
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
}
}
if
(
len
>=
(
size_t
)
MRB_INT
_MAX
)
{
if
(
len
>=
MRB_SSIZE
_MAX
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
}
}
return
str_init_nofree
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
return
str_init_nofree
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
...
@@ -131,7 +131,7 @@ str_new(mrb_state *mrb, const char *p, size_t len)
...
@@ -131,7 +131,7 @@ str_new(mrb_state *mrb, const char *p, size_t len)
if
(
RSTR_EMBEDDABLE_P
(
len
))
{
if
(
RSTR_EMBEDDABLE_P
(
len
))
{
return
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
return
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
p
,
len
);
}
}
if
(
len
>=
(
size_t
)
MRB_INT
_MAX
)
{
if
(
len
>=
MRB_SSIZE
_MAX
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
}
}
if
(
p
&&
mrb_ro_data_p
(
p
))
{
if
(
p
&&
mrb_ro_data_p
(
p
))
{
...
@@ -163,7 +163,7 @@ mrb_str_new_capa(mrb_state *mrb, size_t capa)
...
@@ -163,7 +163,7 @@ mrb_str_new_capa(mrb_state *mrb, size_t capa)
if
(
RSTR_EMBEDDABLE_P
(
capa
))
{
if
(
RSTR_EMBEDDABLE_P
(
capa
))
{
s
=
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
NULL
,
0
);
s
=
str_init_embed
(
mrb_obj_alloc_string
(
mrb
),
NULL
,
0
);
}
}
else
if
(
capa
>=
(
size_t
)
MRB_INT
_MAX
)
{
else
if
(
capa
>=
MRB_SSIZE
_MAX
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string capacity size too big"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string capacity size too big"
);
/* not reached */
/* not reached */
s
=
NULL
;
s
=
NULL
;
...
@@ -191,8 +191,8 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa)
...
@@ -191,8 +191,8 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa)
static
void
static
void
resize_capa
(
mrb_state
*
mrb
,
struct
RString
*
s
,
size_t
capacity
)
resize_capa
(
mrb_state
*
mrb
,
struct
RString
*
s
,
size_t
capacity
)
{
{
#if SIZE_MAX > MRB_
INT
_MAX
#if SIZE_MAX > MRB_
SSIZE
_MAX
mrb_assert
(
capacity
<
=
MRB_INT
_MAX
);
mrb_assert
(
capacity
<
MRB_SSIZE
_MAX
);
#endif
#endif
if
(
RSTR_EMBED_P
(
s
))
{
if
(
RSTR_EMBED_P
(
s
))
{
if
(
!
RSTR_EMBEDDABLE_P
(
capacity
))
{
if
(
!
RSTR_EMBEDDABLE_P
(
capacity
))
{
...
@@ -201,7 +201,7 @@ resize_capa(mrb_state *mrb, struct RString *s, size_t capacity)
...
@@ -201,7 +201,7 @@ resize_capa(mrb_state *mrb, struct RString *s, size_t capacity)
}
}
else
{
else
{
s
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_realloc
(
mrb
,
RSTR_PTR
(
s
),
capacity
+
1
);
s
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_realloc
(
mrb
,
RSTR_PTR
(
s
),
capacity
+
1
);
s
->
as
.
heap
.
aux
.
capa
=
(
mrb_
int
)
capacity
;
s
->
as
.
heap
.
aux
.
capa
=
(
mrb_
ssize
)
capacity
;
}
}
}
}
...
@@ -586,7 +586,7 @@ str_share(mrb_state *mrb, struct RString *orig, struct RString *s)
...
@@ -586,7 +586,7 @@ str_share(mrb_state *mrb, struct RString *orig, struct RString *s)
else
{
else
{
if
(
orig
->
as
.
heap
.
aux
.
capa
>
orig
->
as
.
heap
.
len
)
{
if
(
orig
->
as
.
heap
.
aux
.
capa
>
orig
->
as
.
heap
.
len
)
{
orig
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_realloc
(
mrb
,
orig
->
as
.
heap
.
ptr
,
len
+
1
);
orig
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_realloc
(
mrb
,
orig
->
as
.
heap
.
ptr
,
len
+
1
);
orig
->
as
.
heap
.
aux
.
capa
=
(
mrb_
int
)
len
;
orig
->
as
.
heap
.
aux
.
capa
=
(
mrb_
ssize
)
len
;
}
}
str_init_shared
(
mrb
,
orig
,
s
,
NULL
);
str_init_shared
(
mrb
,
orig
,
s
,
NULL
);
str_init_shared
(
mrb
,
orig
,
orig
,
s
->
as
.
heap
.
aux
.
shared
);
str_init_shared
(
mrb
,
orig
,
orig
,
s
->
as
.
heap
.
aux
.
shared
);
...
@@ -605,8 +605,8 @@ mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
...
@@ -605,8 +605,8 @@ mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
}
}
else
{
else
{
str_share
(
mrb
,
orig
,
s
);
str_share
(
mrb
,
orig
,
s
);
s
->
as
.
heap
.
ptr
+=
beg
;
s
->
as
.
heap
.
ptr
+=
(
mrb_ssize
)
beg
;
s
->
as
.
heap
.
len
=
len
;
s
->
as
.
heap
.
len
=
(
mrb_ssize
)
len
;
}
}
RSTR_COPY_ASCII_FLAG
(
s
,
orig
);
RSTR_COPY_ASCII_FLAG
(
s
,
orig
);
return
mrb_obj_value
(
s
);
return
mrb_obj_value
(
s
);
...
@@ -953,7 +953,7 @@ mrb_str_times(mrb_state *mrb, mrb_value self)
...
@@ -953,7 +953,7 @@ mrb_str_times(mrb_state *mrb, mrb_value self)
if
(
times
<
0
)
{
if
(
times
<
0
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"negative argument"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"negative argument"
);
}
}
if
(
times
&&
MRB_
INT
_MAX
/
times
<
RSTRING_LEN
(
self
))
{
if
(
times
&&
MRB_
SSIZE
_MAX
/
times
<
RSTRING_LEN
(
self
))
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"argument too big"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"argument too big"
);
}
}
...
@@ -1272,7 +1272,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
...
@@ -1272,7 +1272,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
replen
=
(
mrb_nil_p
(
rep
)
?
0
:
RSTRING_LEN
(
rep
));
replen
=
(
mrb_nil_p
(
rep
)
?
0
:
RSTRING_LEN
(
rep
));
newlen
=
replen
+
(
len
-
(
end
-
pos
));
newlen
=
replen
+
(
len
-
(
end
-
pos
));
if
(
newlen
<
replen
)
{
/* overflowed */
if
(
newlen
>=
MRB_SSIZE_MAX
||
newlen
<
replen
/* overflowed */
)
{
mrb_raise
(
mrb
,
E_RUNTIME_ERROR
,
"string size too big"
);
mrb_raise
(
mrb
,
E_RUNTIME_ERROR
,
"string size too big"
);
}
}
...
@@ -2689,21 +2689,21 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
...
@@ -2689,21 +2689,21 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
capa
=
RSTR_CAPA
(
s
);
capa
=
RSTR_CAPA
(
s
);
total
=
RSTR_LEN
(
s
)
+
len
;
total
=
RSTR_LEN
(
s
)
+
len
;
if
(
total
>
(
size_t
)
MRB_INT
_MAX
)
{
if
(
total
>
=
MRB_SSIZE
_MAX
)
{
size_error:
size_error:
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"string size too big"
);
}
}
if
(
capa
<=
total
)
{
if
(
capa
<=
total
)
{
if
(
capa
==
0
)
capa
=
1
;
if
(
capa
==
0
)
capa
=
1
;
while
(
capa
<=
total
)
{
while
(
capa
<=
total
)
{
if
(
capa
<=
(
size_t
)
MRB_INT
_MAX
/
2
)
{
if
(
capa
<=
MRB_SSIZE
_MAX
/
2
)
{
capa
*=
2
;
capa
*=
2
;
}
}
else
{
else
{
capa
=
total
+
1
;
capa
=
total
+
1
;
}
}
}
}
if
(
capa
<=
total
||
capa
>
(
size_t
)
MRB_INT
_MAX
)
{
if
(
capa
<=
total
||
capa
>
MRB_SSIZE
_MAX
)
{
goto
size_error
;
goto
size_error
;
}
}
resize_capa
(
mrb
,
s
,
capa
);
resize_capa
(
mrb
,
s
,
capa
);
...
@@ -2712,7 +2712,7 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
...
@@ -2712,7 +2712,7 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
ptr
=
RSTR_PTR
(
s
)
+
off
;
ptr
=
RSTR_PTR
(
s
)
+
off
;
}
}
memcpy
(
RSTR_PTR
(
s
)
+
RSTR_LEN
(
s
),
ptr
,
len
);
memcpy
(
RSTR_PTR
(
s
)
+
RSTR_LEN
(
s
),
ptr
,
len
);
mrb_assert_int_fit
(
size_t
,
total
,
mrb_
int
,
MRB_INT
_MAX
);
mrb_assert_int_fit
(
size_t
,
total
,
mrb_
ssize
,
MRB_SSIZE
_MAX
);
RSTR_SET_LEN
(
s
,
total
);
RSTR_SET_LEN
(
s
,
total
);
RSTR_PTR
(
s
)[
total
]
=
'\0'
;
/* sentinel */
RSTR_PTR
(
s
)[
total
]
=
'\0'
;
/* sentinel */
return
str
;
return
str
;
...
...
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