May be a bug?

1 view
Skip to first unread message

Guille

unread,
Dec 28, 2008, 6:00:44 AM12/28/08
to slate-language
Hello group, while programming the library I run into a problem with
ByteArray. I think that the intXXAt:put: set of methods are wrong.

I need to do something like:

aWordArray igEndianInt32At: anIndex put: a32bitNumber

But, it is implemented:

a@(ByteArray traits) littleEndianInt32At: offset put: word
[
offset: offset * 4.
a byteAt: offset put: (word byteAt: 0).
a byteAt: offset + 1 put: (word byteAt: 1).
a byteAt: offset + 2 put: (word byteAt: 2).
a byteAt: offset + 3 put: (word byteAt: 3).
word
].

It fails saying that byteAt cannot be used with numbers.

I think the correct way of doing that, may be with:

a@(ByteArray traits) bigEndianInt32At: offset put: word
[ | b0 b1 b2 b3 |
b0: (word bitShift: -24).
b1: ((word bitShift: -16) bitAnd: 255).
b2: ((word bitShift: -8) bitAnd: 255).
b3: (word bitAnd: 255).

offset: offset * 4.
a byteAt: offset put: b0.
a byteAt: offset + 1 put: b1.
a byteAt: offset + 2 put: b2.
a byteAt: offset + 3 put: b3.
word
].

In this way it does not fail.

If you think this way is correct, I changed all the other intXXAt:put:
methods in arrayed.slate. I can post it if you want.

Cheers.

Timmy Douglas

unread,
Dec 28, 2008, 12:20:36 PM12/28/08
to slate-language
It appears the original author of that file assumed that 'word' would
be a byte array like the first argument. I ran into this same problem
a few weeks ago when I was writing a postgres backend but I decided a
better fix for that would be to create what is now 'src/lib/
struct.slate'. src/lib/stream.slate has a
#next:putInteger:&littleEndian: function.

I think the best way to fix this would be to add types to the 'word'
argument. E.g.

a@(ByteArray traits) littleEndianInt32At: offset put: word@(ByteArray
traits) [originalImplementation].
a@(ByteArray traits) littleEndianInt32At: offset put: word@(Integer
traits) [newImplementation].

I will fix this and commit a change in the next hour or so.
Reply all
Reply to author
Forward
0 new messages