Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
alexandria
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lovrolu
alexandria
Commits
49555427
Commit
49555427
authored
13 years ago
by
Nikodemus Siivola
Browse files
Options
Downloads
Patches
Plain Diff
copy-stream: fix non-standard loops
Added test-case.
parent
209c6e29
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
io.lisp
+21
-24
21 additions, 24 deletions
io.lisp
tests.lisp
+23
-0
23 additions, 0 deletions
tests.lisp
with
44 additions
and
24 deletions
io.lisp
+
21
−
24
View file @
49555427
...
...
@@ -122,31 +122,28 @@ compatible element-types."
(
input-position
0
))
(
unless
(
zerop
start
)
;; FIXME add platform specific optimization to skip seekable streams
(
loop
:while
(
<
input-position
start
)
:for
bytes-read
=
(
read-sequence
buffer
input
:end
(
min
(
length
buffer
)
(
-
start
input-position
)))
:do
(
progn
(
when
(
zerop
bytes-read
)
(
error
"Could not read enough bytes from the input to fulfill the START requirement in ~S"
'copy-stream
))
(
incf
input-position
bytes-read
))))
(
loop
while
(
<
input-position
start
)
do
(
let
((
n
(
read-sequence
buffer
input
:end
(
min
(
length
buffer
)
(
-
start
input-position
)))))
(
when
(
zerop
n
)
(
error
"~@<Could not read enough bytes from the input to fulfill ~
the :START ~S requirement in ~S.~:@>"
'copy-stream
start
))
(
incf
input-position
n
))))
(
assert
(
=
input-position
start
))
(
loop
:while
(
or
(
null
end
)
(
<
input-position
end
))
:for
bytes-read
=
(
read-sequence
buffer
input
:end
(
when
end
(
min
(
length
buffer
)
(
-
end
input-position
))))
:do
(
progn
(
when
(
zerop
bytes-read
)
(
if
end
(
error
"Could not read enough bytes from the input to fulfill the END requirement in ~S"
'copy-stream
)
(
return
)))
(
incf
input-position
bytes-read
)
(
write-sequence
buffer
output
:end
bytes-read
)
(
incf
output-position
bytes-read
)))
(
loop
while
(
or
(
null
end
)
(
<
input-position
end
))
do
(
let
((
n
(
read-sequence
buffer
input
:end
(
when
end
(
min
(
length
buffer
)
(
-
end
input-position
))))))
(
when
(
zerop
n
)
(
if
end
(
error
"~@<Could not read enough bytes from the input to fulfill ~
the :END ~S requirement in ~S.~:@>"
'copy-stream
end
)
(
return
)))
(
incf
input-position
n
)
(
write-sequence
buffer
output
:end
n
)
(
incf
output-position
n
)))
(
when
finish-output
(
finish-output
output
))
output-position
))
This diff is collapsed.
Click to expand it.
tests.lisp
+
23
−
0
View file @
49555427
...
...
@@ -1807,3 +1807,26 @@
(
deftest
binomial-coefficient.1
(
alexandria:binomial-coefficient
1239
139
)
28794902202288970200771694600561826718847179309929858835480006683522184441358211423695124921058123706380656375919763349913245306834194782172712255592710204598527867804110129489943080460154
)
(
deftest
copy-stream.1
(
let
((
data
"sdkfjhsakfh weior763495ewofhsdfk sdfadlkfjhsadf woif sdlkjfhslkdfh sdklfjh"
))
(
values
(
equal
data
(
with-input-from-string
(
in
data
)
(
with-output-to-string
(
out
)
(
alexandria:copy-stream
in
out
))))
(
equal
(
subseq
data
10
20
)
(
with-input-from-string
(
in
data
)
(
with-output-to-string
(
out
)
(
alexandria:copy-stream
in
out
:start
10
:end
20
))))
(
equal
(
subseq
data
10
)
(
with-input-from-string
(
in
data
)
(
with-output-to-string
(
out
)
(
alexandria:copy-stream
in
out
:start
10
))))
(
equal
(
subseq
data
0
20
)
(
with-input-from-string
(
in
data
)
(
with-output-to-string
(
out
)
(
alexandria:copy-stream
in
out
:end
20
))))))
t
t
t
t
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment