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
b87268f1
Commit
b87268f1
authored
Apr 28, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `IO#readchar` to support UTF-8 char reading; fix #4712
This fix only effective when `MRB_UTF8_STRING` is set.
parent
a395f8e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
8 deletions
+43
-8
mrbgems/mruby-io/mrblib/io.rb
mrbgems/mruby-io/mrblib/io.rb
+4
-3
mrbgems/mruby-io/src/io.c
mrbgems/mruby-io/src/io.c
+39
-5
No files found.
mrbgems/mruby-io/mrblib/io.rb
View file @
b87268f1
...
@@ -283,9 +283,10 @@ class IO
...
@@ -283,9 +283,10 @@ class IO
def
readchar
def
readchar
_read_buf
_read_buf
c
=
@buf
[
0
]
_readchar
(
@buf
)
@buf
[
0
]
=
""
# c = @buf[0]
c
# @buf[0] = ""
# c
end
end
def
getc
def
getc
...
...
mrbgems/mruby-io/src/io.c
View file @
b87268f1
...
@@ -1454,14 +1454,13 @@ mrb_io_pwrite(mrb_state *mrb, mrb_value io)
...
@@ -1454,14 +1454,13 @@ mrb_io_pwrite(mrb_state *mrb, mrb_value io)
#endif
/* MRB_WITH_IO_PREAD_PWRITE */
#endif
/* MRB_WITH_IO_PREAD_PWRITE */
static
mrb_value
static
mrb_value
io_bufread
(
mrb_state
*
mrb
,
mrb_value
s
elf
)
io_bufread
(
mrb_state
*
mrb
,
mrb_value
s
tr
,
mrb_int
len
)
{
{
mrb_value
str
,
str
2
;
mrb_value
str2
;
mrb_int
len
,
newlen
;
mrb_int
newlen
;
struct
RString
*
s
;
struct
RString
*
s
;
char
*
p
;
char
*
p
;
mrb_get_args
(
mrb
,
"Si"
,
&
str
,
&
len
);
s
=
RSTRING
(
str
);
s
=
RSTRING
(
str
);
mrb_str_modify
(
mrb
,
s
);
mrb_str_modify
(
mrb
,
s
);
p
=
RSTR_PTR
(
s
);
p
=
RSTR_PTR
(
s
);
...
@@ -1474,6 +1473,40 @@ io_bufread(mrb_state *mrb, mrb_value self)
...
@@ -1474,6 +1473,40 @@ io_bufread(mrb_state *mrb, mrb_value self)
return
str2
;
return
str2
;
}
}
static
mrb_value
mrb_io_bufread
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
str
;
mrb_int
len
;
mrb_get_args
(
mrb
,
"Si"
,
&
str
,
&
len
);
return
io_bufread
(
mrb
,
str
,
len
);
}
static
mrb_value
mrb_io_readchar
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
buf
;
unsigned
char
c
;
mrb_int
len
=
1
;
mrb_get_args
(
mrb
,
"S"
,
&
buf
);
mrb_assert
(
RSTRING_PTR
(
buf
)
>
0
);
#ifdef MRB_UTF8_STRING
c
=
RSTRING_PTR
(
buf
)[
0
];
if
(
c
&
0x80
)
{
len
=
mrb_utf8len
(
RSTRING_PTR
(
buf
),
RSTRING_END
(
buf
));
if
(
len
==
1
&&
RSTRING_LEN
(
buf
)
<
5
)
{
/* partial UTF-8 */
/* refill the buffer */
mrb_value
b
=
mrb_io_sysread_common
(
mrb
,
mrb_sysread_dummy
,
self
,
mrb_nil_value
(),
4096
,
0
);
mrb_str_concat
(
mrb
,
buf
,
b
);
}
len
=
mrb_utf8len
(
RSTRING_PTR
(
buf
),
RSTRING_END
(
buf
));
}
#endif
return
io_bufread
(
mrb
,
buf
,
len
);
}
void
void
mrb_init_io
(
mrb_state
*
mrb
)
mrb_init_io
(
mrb_state
*
mrb
)
{
{
...
@@ -1511,5 +1544,6 @@ mrb_init_io(mrb_state *mrb)
...
@@ -1511,5 +1544,6 @@ mrb_init_io(mrb_state *mrb)
mrb_define_method
(
mrb
,
io
,
"pread"
,
mrb_io_pread
,
MRB_ARGS_ANY
());
/* ruby 2.5 feature */
mrb_define_method
(
mrb
,
io
,
"pread"
,
mrb_io_pread
,
MRB_ARGS_ANY
());
/* ruby 2.5 feature */
mrb_define_method
(
mrb
,
io
,
"pwrite"
,
mrb_io_pwrite
,
MRB_ARGS_ANY
());
/* ruby 2.5 feature */
mrb_define_method
(
mrb
,
io
,
"pwrite"
,
mrb_io_pwrite
,
MRB_ARGS_ANY
());
/* ruby 2.5 feature */
mrb_define_class_method
(
mrb
,
io
,
"_bufread"
,
io_bufread
,
MRB_ARGS_REQ
(
2
));
mrb_define_method
(
mrb
,
io
,
"_readchar"
,
mrb_io_readchar
,
MRB_ARGS_REQ
(
1
));
mrb_define_class_method
(
mrb
,
io
,
"_bufread"
,
mrb_io_bufread
,
MRB_ARGS_REQ
(
2
));
}
}
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