Hello,
I have program which works fine when compiled, but when pasted into a
REPL gives the following error message:
While compiling expression:
In procedure bytevector-copy!: Wrong type argument in position 3
(expecting mutable bytevector): #vu8()
I'm having a hard time narrowing down the source of the error,
though I do know that it occurs when the second call to
`parse-netstring' is evaluated, and I am assuming this is a bug because
my expectation would be that the REPL would behave exactly the same as
the Guile compiler.
Test case:
----------------------------- snip -----------------------------
(use-modules (rnrs bytevectors)
(rnrs bytevectors gnu))
(define (bytevector-index haystack needle)
(define len (bytevector-length haystack))
(let loop ((i 0))
(cond [(>= i len) #f]
[(= needle (bytevector-u8-ref haystack i)) i]
[else (loop (+ 1 i))])))
(define (parse-netstring bv)
(define split-index (bytevector-index bv (char->integer #\:)))
(unless split-index
(throw 'scgi-parse-error "netstring contains no delimiter character"))
(let* [(length-encoded (bytevector-slice bv 0 split-index))
(length-parsed (string->number (utf8->string length-encoded)))]
(unless length-parsed
(throw 'scgi-parse-error (format #f "illegal netstring length '~a'"
length-encoded)))
(let* ([payload-start (+ 1 split-index)]
[payload-end (+ 1 payload-start length-parsed)]
[remaining (- (bytevector-length bv) payload-end)])
(values (bytevector-slice bv payload-start length-parsed)
(bytevector-slice bv payload-end remaining)))))
(parse-netstring (string->utf8 "13:Hello, world!,"))
(parse-netstring (string->utf8 "5:hello,"))