file-position and string-output-stream
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
FILE-POSITION sometimes crashes on string streams.
It also crashes or has non-obvious behavior in other lisp implementations, so apparently we're not the first to wonder what it's supposed to do.
* (defparameter *s* (make-string-
*S*
* (dotimes (i 64) (write-char #\a *s*))
NIL
* (dotimes (i 64) (write-char #\b *s*))
NIL
* (file-position *s* 3)
3
* (file-position *s* 4)
debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {10005084C3}>:
The value
-60
is not of type
SB-INT:INDEX
when setting slot SB-IMPL::POINTER of structure SB-IMPL:
I think our intent is probably the best among the implementations I tested: you can rewrite portions of the buffer, and GET-OUTPUT-
Here are observations in other lisps for the sake of comparison:
CLISP seems to think FILE-POSITION means truncate. You can't set the position to a higher number than you've set it, and GET- returns data up to the the lesser value.
> (file-position *s* 3)
3
> (file-position *s* 4)
*** - FILE-POSITION: index 4 for "aaa" is out of range
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [5]> :r1
> (Get-output-
"aaa"
ECL seems to think it means truncate and/or extend, space-filling as necessary:
> (file-position *s* 3)
T
> (file-position *s* 4)
T
> (Get-output-
"aaa "
> (file-position *s* 10)
T
> (Get-output-
" "
CCL truncates and/or extends, but uses lingering data from previous output operations:
? (defparameter *s* (make-string-
? (dotimes (i 10) (write-char (code-char (+ 64 i)) *s*))
? (get-output-
"@ABCDEFGHI"
? (file-position *s* 5)
? (Get-output-
"@ABCD"
Also (unrelatedly) I think CLEAR-OUTPUT ought to mean erase the buffer, but it doesn't.
description: | updated |
Changed in sbcl: | |
assignee: | nobody → Christophe Rhodes (csr21-cantab) |
Changed in sbcl: | |
status: | New → Fix Committed |
assignee: | Christophe Rhodes (csr21-cantab) → nobody |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |