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
b377b7d5
Commit
b377b7d5
authored
Aug 07, 2019
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `mrb_to_str` and related functions.
Contrary to the name, `mrb_to_str` just checks type, no conversion.
parent
98fc887c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
20 deletions
+9
-20
include/mruby.h
include/mruby.h
+1
-0
src/class.c
src/class.c
+5
-18
src/string.c
src/string.c
+3
-2
No files found.
include/mruby.h
View file @
b377b7d5
...
...
@@ -1186,6 +1186,7 @@ MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
MRB_API
mrb_value
mrb_to_int
(
mrb_state
*
mrb
,
mrb_value
val
);
#define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val))
/* string type checking (contrary to the name, it doesn't convert) */
MRB_API
mrb_value
mrb_to_str
(
mrb_state
*
mrb
,
mrb_value
val
);
MRB_API
void
mrb_check_type
(
mrb_state
*
mrb
,
mrb_value
x
,
enum
mrb_vtype
t
);
...
...
src/class.c
View file @
b377b7d5
...
...
@@ -499,30 +499,17 @@ mrb_notimplement_m(mrb_state *mrb, mrb_value self)
return
mrb_nil_value
();
}
#define CHECK_TYPE(mrb, val, t, c) do { \
if (mrb_type(val) != (t)) {\
mrb_raisef(mrb, E_TYPE_ERROR, "expected %l", c, sizeof(c "")-1);\
}\
} while (0)
static
mrb_value
to_str
(
mrb_state
*
mrb
,
mrb_value
val
)
{
CHECK_TYPE
(
mrb
,
val
,
MRB_TT_STRING
,
"String"
);
return
val
;
}
static
mrb_value
to_ary
(
mrb_state
*
mrb
,
mrb_value
val
)
{
CHECK_TYPE
(
mrb
,
val
,
MRB_TT_ARRAY
,
"Array"
);
mrb_check_type
(
mrb
,
val
,
MRB_TT_ARRAY
);
return
val
;
}
static
mrb_value
to_hash
(
mrb_state
*
mrb
,
mrb_value
val
)
{
CHECK_TYPE
(
mrb
,
val
,
MRB_TT_HASH
,
"Hash"
);
mrb_check_type
(
mrb
,
val
,
MRB_TT_HASH
);
return
val
;
}
...
...
@@ -686,7 +673,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
}
}
if
(
i
<
argc
)
{
*
p
=
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
*
p
=
mrb_
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
i
++
;
}
}
...
...
@@ -747,7 +734,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
}
}
if
(
i
<
argc
)
{
ss
=
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
ss
=
mrb_
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
*
ps
=
RSTRING_PTR
(
ss
);
*
pl
=
RSTRING_LEN
(
ss
);
i
++
;
...
...
@@ -769,7 +756,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
}
}
if
(
i
<
argc
)
{
ss
=
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
ss
=
mrb_
to_str
(
mrb
,
ARGV
[
arg_i
++
]);
*
ps
=
RSTRING_CSTR
(
mrb
,
ss
);
i
++
;
}
...
...
src/string.c
View file @
b377b7d5
...
...
@@ -1280,7 +1280,7 @@ mrb_str_aset(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_
{
mrb_int
beg
,
len
,
charlen
;
replace
=
mrb_to_str
(
mrb
,
replace
);
mrb_to_str
(
mrb
,
replace
);
switch
(
str_convert_range
(
mrb
,
str
,
indx
,
alen
,
&
beg
,
&
len
))
{
case
STR_OUT_OF_RANGE
:
...
...
@@ -2394,7 +2394,8 @@ mrb_str_to_inum(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck)
const
char
*
s
;
mrb_int
len
;
s
=
mrb_string_value_ptr
(
mrb
,
str
);
mrb_to_str
(
mrb
,
str
);
s
=
RSTRING_PTR
(
str
);
len
=
RSTRING_LEN
(
str
);
return
mrb_str_len_to_inum
(
mrb
,
s
,
len
,
base
,
badcheck
);
}
...
...
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