unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Bug in vector-move-right!
@ 2010-03-26  7:06 Michael Lucy
  2010-08-04 19:48 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Lucy @ 2010-03-26  7:06 UTC (permalink / raw)
  To: bug-guile

Hi,
I think there's a bug in vector-move-right!.  I'm using guile 1.9.9 as
built from the git repository earlier today.

This is the behavior I see:
"
scheme@(guile-user)> (define *v1* #(1 2 3 4 5 6 7 8 9))
scheme@(guile-user)> (define *v2* #(10 20 30 40 50 60 70 80 90))
scheme@(guile-user)> (vector-move-right! *v1* 0 2 *v2* 5)
scheme@(guile-user)> *v2*
#(10 20 30 1 2 60 70 80 90)
"

It seems to interpret the argument start2 as an ending index.  I
thought for a second that this might be intended behavior, but it says
in the documentation that start2 is supposed to be an inclusive index,
which it isn't.

This is the behavior I expect:
"
scheme@(guile-user)> (define *v1* #(1 2 3 4 5 6 7 8 9))
scheme@(guile-user)> (define *v2* #(10 20 30 40 50 60 70 80 90))
scheme@(guile-user)> (vector-move-right! *v1* 0 2 *v2* 5)
scheme@(guile-user)> *v2*
#(10 20 30 40 50 1 2 80 90)
"

This is also the behavior already shown by vector-move-left! in the
same context.

If this is actually a bug rather than a documentation issue, it can be
fixed by adding one line to libguile/vectors.c.  Here's a diff:

diff -c /home/zededarian/bak/vectors.c.old
/home/zededarian/gg/libguile/vectors.c
*** /home/zededarian/bak/vectors.c.old  2010-03-25 16:41:48.000000000 -0500
--- /home/zededarian/gg/libguile/vectors.c      2010-03-26
01:37:52.000000000 -0500
***************
*** 573,578 ****
--- 573,580 ----
    i = scm_to_unsigned_integer (start1, 0, len1);
    e = scm_to_unsigned_integer (end1, i, len1);
    j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
+
+   j += (e - i);

    i *= inc1;
    e *= inc1;

Diff finished.  Fri Mar 26 02:03:05 2010




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug in vector-move-right!
  2010-03-26  7:06 Bug in vector-move-right! Michael Lucy
@ 2010-08-04 19:48 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2010-08-04 19:48 UTC (permalink / raw)
  To: Michael Lucy; +Cc: bug-guile

Hi Michael,

Late reply, but better than never...

On Fri 26 Mar 2010 08:06, Michael Lucy <MichaelGLucy@Gmail.com> writes:

> I think there's a bug in vector-move-right!.  I'm using guile 1.9.9 as
> built from the git repository earlier today.
>
> This is the behavior I see:
> "
> scheme@(guile-user)> (define *v1* #(1 2 3 4 5 6 7 8 9))
> scheme@(guile-user)> (define *v2* #(10 20 30 40 50 60 70 80 90))
> scheme@(guile-user)> (vector-move-right! *v1* 0 2 *v2* 5)
> scheme@(guile-user)> *v2*
> #(10 20 30 1 2 60 70 80 90)
> "
>
> It seems to interpret the argument start2 as an ending index.  I
> thought for a second that this might be intended behavior, but it says
> in the documentation that start2 is supposed to be an inclusive index,
> which it isn't.
>
> This is the behavior I expect:
> "
> scheme@(guile-user)> (define *v1* #(1 2 3 4 5 6 7 8 9))
> scheme@(guile-user)> (define *v2* #(10 20 30 40 50 60 70 80 90))
> scheme@(guile-user)> (vector-move-right! *v1* 0 2 *v2* 5)
> scheme@(guile-user)> *v2*
> #(10 20 30 40 50 1 2 80 90)
> "

Well, there are more bugs:

scheme@(guile-user)> (define *v1* #(1 2 3 4 5 6 7 8 9))
scheme@(guile-user)> (define *v2* #(10 20 30 40 50 60 70 80 90))
scheme@(guile-user)> (vector-move-left! *v1* 0 2 *v2* 9)
scheme@(guile-user)> *v2*
$1 = #(10 20 30 40 50 60 70 80 90)

Hmm, what memory did we just overwrite? :)

I have fixed all of the bugs that I can see here, but there might be
more, so please do give this a poke.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-04 19:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26  7:06 Bug in vector-move-right! Michael Lucy
2010-08-04 19:48 ` Andy Wingo

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).