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
27f42288
Unverified
Commit
27f42288
authored
Jun 11, 2017
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
To accurate `pos`
pos shouldn't cache because it's not controllable
parent
3a73a584
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
24 deletions
+8
-24
mrblib/io.rb
mrblib/io.rb
+8
-20
src/io.c
src/io.c
+0
-4
No files found.
mrblib/io.rb
View file @
27f42288
...
@@ -124,7 +124,6 @@ class IO
...
@@ -124,7 +124,6 @@ class IO
str
=
string
.
is_a?
(
String
)
?
string
:
string
.
to_s
str
=
string
.
is_a?
(
String
)
?
string
:
string
.
to_s
return
str
.
size
unless
str
.
size
>
0
return
str
.
size
unless
str
.
size
>
0
len
=
syswrite
(
str
)
len
=
syswrite
(
str
)
@pos
+=
len
len
len
end
end
...
@@ -146,7 +145,7 @@ class IO
...
@@ -146,7 +145,7 @@ class IO
def
pos
def
pos
raise
IOError
if
closed?
raise
IOError
if
closed?
@pos
sysseek
(
0
,
SEEK_CUR
)
-
@buf
.
length
end
end
alias_method
:tell
,
:pos
alias_method
:tell
,
:pos
...
@@ -160,7 +159,7 @@ class IO
...
@@ -160,7 +159,7 @@ class IO
def
seek
(
i
,
whence
=
SEEK_SET
)
def
seek
(
i
,
whence
=
SEEK_SET
)
raise
IOError
if
closed?
raise
IOError
if
closed?
@pos
=
sysseek
(
i
,
whence
)
sysseek
(
i
,
whence
)
@buf
=
''
@buf
=
''
0
0
end
end
...
@@ -172,7 +171,6 @@ class IO
...
@@ -172,7 +171,6 @@ class IO
def
ungetc
(
substr
)
def
ungetc
(
substr
)
raise
TypeError
.
new
"expect String, got
#{
substr
.
class
}
"
unless
substr
.
is_a?
(
String
)
raise
TypeError
.
new
"expect String, got
#{
substr
.
class
}
"
unless
substr
.
is_a?
(
String
)
@pos
-=
substr
.
size
if
@buf
.
empty?
if
@buf
.
empty?
@buf
=
substr
.
dup
@buf
=
substr
.
dup
else
else
...
@@ -195,7 +193,6 @@ class IO
...
@@ -195,7 +193,6 @@ class IO
end
end
array
=
[]
array
=
[]
start_pos
=
@pos
while
1
while
1
begin
begin
_read_buf
_read_buf
...
@@ -204,15 +201,12 @@ class IO
...
@@ -204,15 +201,12 @@ class IO
break
break
end
end
if
length
&&
(
@pos
-
start_pos
+
@buf
.
size
)
>=
length
if
length
&&
length
<=
@buf
.
size
len
=
length
-
(
@pos
-
start_pos
)
array
.
push
@buf
[
0
,
length
]
array
.
push
@buf
[
0
,
len
]
@buf
=
@buf
[
length
,
@buf
.
size
-
length
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
break
break
else
else
array
.
push
@buf
array
.
push
@buf
@pos
+=
@buf
.
size
@buf
=
''
@buf
=
''
end
end
end
end
...
@@ -240,7 +234,6 @@ class IO
...
@@ -240,7 +234,6 @@ class IO
end
end
array
=
[]
array
=
[]
start_pos
=
@pos
while
1
while
1
begin
begin
_read_buf
_read_buf
...
@@ -249,21 +242,17 @@ class IO
...
@@ -249,21 +242,17 @@ class IO
break
break
end
end
if
limit
&&
(
@pos
-
start_pos
+
@buf
.
size
)
>=
limit
if
limit
&&
limit
<=
@buf
.
size
len
=
limit
-
(
@pos
-
start_pos
)
array
.
push
@buf
[
0
,
limit
]
array
.
push
@buf
[
0
,
len
]
@buf
=
@buf
[
limit
,
@buf
.
size
-
limit
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
break
break
elsif
idx
=
@buf
.
index
(
rs
)
elsif
idx
=
@buf
.
index
(
rs
)
len
=
idx
+
rs
.
size
len
=
idx
+
rs
.
size
array
.
push
@buf
[
0
,
len
]
array
.
push
@buf
[
0
,
len
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
break
break
else
else
array
.
push
@buf
array
.
push
@buf
@pos
+=
@buf
.
size
@buf
=
''
@buf
=
''
end
end
end
end
...
@@ -285,7 +274,6 @@ class IO
...
@@ -285,7 +274,6 @@ class IO
_read_buf
_read_buf
c
=
@buf
[
0
]
c
=
@buf
[
0
]
@buf
=
@buf
[
1
,
@buf
.
size
]
@buf
=
@buf
[
1
,
@buf
.
size
]
@pos
+=
1
c
c
end
end
...
...
src/io.c
View file @
27f42288
...
@@ -389,7 +389,6 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
...
@@ -389,7 +389,6 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
}
}
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr
=
mrb_io_alloc
(
mrb
);
fptr
=
mrb_io_alloc
(
mrb
);
fptr
->
fd
=
fd
;
fptr
->
fd
=
fd
;
...
@@ -443,7 +442,6 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
...
@@ -443,7 +442,6 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
flags
=
mrb_io_modestr_to_flags
(
mrb
,
mrb_string_value_cstr
(
mrb
,
&
mode
));
flags
=
mrb_io_modestr_to_flags
(
mrb
,
mrb_string_value_cstr
(
mrb
,
&
mode
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr
=
(
struct
mrb_io
*
)
DATA_PTR
(
io
);
fptr
=
(
struct
mrb_io
*
)
DATA_PTR
(
io
);
if
(
fptr
!=
NULL
)
{
if
(
fptr
!=
NULL
)
{
...
@@ -801,7 +799,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
...
@@ -801,7 +799,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
r
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
r
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
mrb_iv_set
(
mrb
,
r
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
r
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
r
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr_r
=
mrb_io_alloc
(
mrb
);
fptr_r
=
mrb_io_alloc
(
mrb
);
fptr_r
->
fd
=
pipes
[
0
];
fptr_r
->
fd
=
pipes
[
0
];
fptr_r
->
readable
=
1
;
fptr_r
->
readable
=
1
;
...
@@ -812,7 +809,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
...
@@ -812,7 +809,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
w
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
w
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
mrb_iv_set
(
mrb
,
w
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
w
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
w
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr_w
=
mrb_io_alloc
(
mrb
);
fptr_w
=
mrb_io_alloc
(
mrb
);
fptr_w
->
fd
=
pipes
[
1
];
fptr_w
->
fd
=
pipes
[
1
];
fptr_w
->
readable
=
0
;
fptr_w
->
readable
=
0
;
...
...
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