Hi Maxime,

Maxime Devos <maximede...@telenet.be> skribis:

> It currently is difficult to write a correct implementation of 
> get-bytevector-all in pure Scheme, because ‘get-bytevector-all’ needs to 
> return a _fresh_ bytevector and could return twice (e.g. in case of 
> system-async-mark + call-with-prompt shenanigans). I think the proposed 
> implementation is incorrect in this way.

Hmm I don’t see how it could return twice.  If an async runs while
‘get-bytevector-all’ is executed, it cannot cause ‘get-bytevector-all’
to abort to a prompt.  I think we’re fine, no?

> +(define (get-bytevector-all port)
> +  (define %initial-length 4096)
> +
> +  (let read-loop ((total 0)
> +                  (result-length %initial-length)
> +                  (result (make-bytevector %initial-length)))
>
> I sense a lack of tests for the test suite ...
> Also, to avoid avoidable allocations and copying, it would be nice if 
> %initial-length could be overridden (optional #:initial-length keyword 
> argument), in case the user has a better guess available.

Yeah, but since this interface is specified in R6RS, and since we’re
just porting the existing C implementation to Scheme, I’d rather not add
such a keyword argument.  We could provide an extension separately
though, as is done for (rnrs bytevectors gnu) for instance.

Regarding tests, you’re right: this is already covered.

I pushed this as 461ff313fa478d207a7668595e9d976a2ace9770 together with
a NEWS entry.

Thanks for your feedback!

Ludo’.

Reply via email to