unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: d4ryus via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" <bug-guile@gnu.org>
To: 45816@debbugs.gnu.org
Subject: bug#45816: (ice-9 suspendable-ports):get-bytevector-some! is broken
Date: Tue, 12 Jan 2021 15:19:05 +0100	[thread overview]
Message-ID: <X/2v2XvE8XuIHwAv@gandalf.d4ryus.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]

hi,

(ice-9 suspendable-ports):get-bytevector-some! calls bytevector-copy!
with transfer-size (which is a number) as third argument:

  ...
  (define (get-bytevector-some! port bv start count)
    (if (zero? count)
        0
        (call-with-values (lambda () (fill-input port 1 'binary))
          (lambda (buf cur buffered)
            (if (zero? buffered)
                (begin
                  (set-port-buffer-has-eof?! buf #f)
                  the-eof-object)
                (let ((transfer-size (min count buffered)))
                  (bytevector-copy! (port-buffer-bytevector buf) cur
                                    transfer-size start buffered)
                  (set-port-buffer-cur! buf (+ cur transfer-size))
                  transfer-size))))))
  ...

The third argument to bytevector-copy! must be the target bytevector,
from the doc:

  Scheme Procedure: bytevector-copy! source source-start target target-start len

    Copy len bytes from source into target, starting reading from
    source-start (a positive index within source) and start writing at
    target-start. It is permitted for the source and target regions to
    overlap.

I think the correct call is:

  (bytevector-copy! (port-buffer-bytevector buf) cur
                    bv start transfer-size)


A potentional fix is attached.

If you need any additional information, please let me know.


-  d4ryus

[-- Attachment #2: suspendable-get-bytevector-some-fix.patch --]
[-- Type: text/plain, Size: 609 bytes --]

diff --git a/module/ice-9/suspendable-ports.scm b/module/ice-9/suspendable-ports.scm
index f5f005cca..a823f1d37 100644
--- a/module/ice-9/suspendable-ports.scm
+++ b/module/ice-9/suspendable-ports.scm
@@ -338,7 +338,7 @@
                 the-eof-object)
               (let ((transfer-size (min count buffered)))
                 (bytevector-copy! (port-buffer-bytevector buf) cur
-                                  transfer-size start buffered)
+                                  bv start transfer-size)
                 (set-port-buffer-cur! buf (+ cur transfer-size))
                 transfer-size))))))


             reply	other threads:[~2021-01-12 14:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 14:19 d4ryus via Bug reports for GUILE, GNU's Ubiquitous Extension Language [this message]
2021-05-06 10:46 ` bug#45816: (ice-9 suspendable-ports):get-bytevector-some! is broken d4ryus via Bug reports for GUILE, GNU's Ubiquitous Extension Language

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X/2v2XvE8XuIHwAv@gandalf.d4ryus.net \
    --to=bug-guile@gnu.org \
    --cc=45816@debbugs.gnu.org \
    --cc=d4ryus@mailbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).