Jump to content




[1.48] os.queueEvent/os.pullEvent fail for 8-bit strings


  • This topic is locked This topic is locked
3 replies to this topic

#1 Eric

  • Members
  • 92 posts
  • LocationUK

Posted 25 February 2013 - 02:52 AM

This is the root cause of this "suggestion": http://www.computerc...net-being-crap/

Test #1: check that :byte and .char work as expected:
for i = 0, 255 do
    local c = string.char(i)
    local j = c:byte()
    if j ~= i then
        print(("FAIL: Converting %d from int->char->int gave %d"):format(i, j))
    end
end
Passes

Test #2: Check that strings are preserved through events:
for i = 0, 255 do
    local c = string.char(i)
    os.queueEvent('test', c)
    local _, c2 = os.pullEvent('test')
    assert(#c == 1 and #c2 == 1) -- to prove these are single-byte strings

    local j = c2:byte()
    if c ~= c2 then
         print(("FAIL: Passing %d through an event gives %d"):format(i, j))
    end
end
Fails:
FAIL: Passing 128 through an event gives 239
FAIL: Passing 129 through an event gives 239
FAIL: Passing 130 through an event gives 239
...
FAIL: Passing 255 through an event gives 239

To summarize, either queueEvent or pullEvent fail to pass strings containing characters above character 127.

This bug is almost certainly present in 1.5 as well, although I haven't tested it.

#2 Pinkishu

  • Members
  • 484 posts

Posted 25 February 2013 - 03:17 AM

So thats what caused rednet to screw up, as messages go over events ^^

#3 Eric

  • Members
  • 92 posts
  • LocationUK

Posted 25 February 2013 - 03:31 AM

Found another related bug in the file system:
fs.makeDir('d')  -- empty directory
local h = fs.open('d/'..string.char(128), 'w')  -- odd filename
assert(h == nil) -- which doesn't get created - fair enough

-- So there should be no files in the directory, right?
local files = fs.list('d')
assert(#files == 1)  -- except there are

-- Can you guess what the name of the file is?
local file = files[1]
print(files[1]:byte(1, math.huge))
That outputs:
239
190
128


#4 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 25 February 2013 - 04:47 AM

Way to add two and two together and get five. Again, this is the same as the last thread. All we do is pass the string to and from Java/Lua. NOTHING MORE. Unless you want to delve through LuaJ to find a fix, I consider this unimportant.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users