[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] greedy (read-string 0)
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] greedy (read-string 0) |
Date: |
Thu, 19 Apr 2007 08:07:04 +0200 |
On 4/18/07, Andre Kuehne <address@hidden> wrote:
Hi everyone
I just installed chicken from darcs and got the following:
> csi -n
.--. .-. _ .-.
: .--': : :_; : :.-.
: : : `-. .-. .--. : `'.' .--. ,-.,-.
: :__ : .. :: :' ..': . `.' '_.': ,. :
`.__.':_;:_;:_;`.__.':_;:_;`.__.':_;:_;
Version 2.611 - linux-unix-gnu-x86 - [ dload ptables applyhook ]
(c)2000-2007 Felix L. Winkelmann
#;1> (with-input-from-file "test" (lambda () (string-length (read-string 0))))
1
This only happens inside with-input-from-file.
Argh. Here the patch:
--- old-chicken/extras.scm 2007-04-19 08:02:21.505209216 +0200
+++ new-chicken/extras.scm 2007-04-19 08:02:21.583197360 +0200
@@ -420,23 +420,25 @@
(doread port) ) ) ) ) ) )
(define (##sys#read-string! n dest port start)
- (when (##sys#slot port 6) ; peeked?
- (##core#inline "C_setsubchar" dest start (##sys#read-char-0 port))
- (set! start (fx+ start 1)) )
- (let ((rdstring (##sys#slot (##sys#slot port 2) 7)))
- (let loop ((start start) (n n) (m 0))
- (let ((n2 (if rdstring
- (rdstring port n dest start) ; *** doesn't update
port-position!
- (let ((c (##sys#read-char-0 port)))
- (if (eof-object? c)
- 0
- (begin
- (##core#inline "C_setsubchar" dest start c)
- 1) ) ) ) ) )
- (cond ((eq? n2 0) m)
- ((or (not n) (fx< n2 n))
- (loop (fx+ start n2) (and n (fx- n n2)) (fx+ m n2)) )
- (else (fx+ n2 m))) ) ) ))
+ (cond ((eq? n 0) 0)
+ (else
+ (when (##sys#slot port 6) ; peeked?
+ (##core#inline "C_setsubchar" dest start (##sys#read-char-0 port))
+ (set! start (fx+ start 1)) )
+ (let ((rdstring (##sys#slot (##sys#slot port 2) 7)))
+ (let loop ((start start) (n n) (m 0))
+ (let ((n2 (if rdstring
+ (rdstring port n dest start) ; *** doesn't update
port-position!
+ (let ((c (##sys#read-char-0 port)))
+ (if (eof-object? c)
+ 0
+ (begin
+ (##core#inline "C_setsubchar" dest start c)
+ 1) ) ) ) ) )
+ (cond ((eq? n2 0) m)
+ ((or (not n) (fx< n2 n))
+ (loop (fx+ start n2) (and n (fx- n n2)) (fx+ m n2)) )
+ (else (fx+ n2 m))) ) ) ))))
(define (read-string! n dest #!optional (port ##sys#standard-input) (start 0))
(##sys#check-port port 'read-string!)
(also checked into darcs head in a few minutes)
BTW, is it still considered good practice to post such issues here,
or do you prefer trac-tickets?
For things like this, trac tickets would be preferable. For issues that
might interest others or where feedback from others might be
useful, a post here is good.
You can always do both.
cheers,
felix