Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luajit and ffi went wrong in while block #8

Closed
qleein opened this issue Jun 2, 2016 · 3 comments
Closed

luajit and ffi went wrong in while block #8

qleein opened this issue Jun 2, 2016 · 3 comments

Comments

@qleein
Copy link

qleein commented Jun 2, 2016

I develop a red-black tree base on luajit, but sometime could not found the minium node in the tree, The code behind would assert failed.
If add a line to the while block or use jit.off() to disable jit, it would work well.

        while node.left ~= sentinel do
            --If add a line here, it would work well even jit.on
            --print('node:', node)
            node = node.left
        end
        assert(node.left == sentinel)

OS: Ubuntu 16.04 or ArchLinux .
Code is Here, extra code is removed.

local ffi = require "ffi"


ffi.cdef[[
    typedef struct rbtree_node_s rbtree_node;
    struct rbtree_node_s {
        int                     key;
        struct rbtree_node_s    *left;
    };
]]


--for debug
local function traverse(array, size)
    for i = 0, size + 1 do
        print('i:', i, ' node:', array[i], ' nodekey:', array[i].key, ' node.left:', array[i].left)
    end
end


local function test()
    local size = 24

    local q = ffi.new("rbtree_node[?]", size + 2)
    ffi.fill(q, ffi.sizeof("rbtree_node", size + 2), 0)

    local sentinel = q[0]
    local root = q[1]
    root.key = 1
    root.left = sentinel

    for i = 2, size do
        q[i].key = i
        q[i-1].left = q[i]
        q[i].left = sentinel

        local node = root
        while node.left ~= sentinel do
            --If add a line here, it would work well even jit.on
            --print('node:', node)
            node = node.left
        end

        --print('index:', i)
        --print('node:', node)
        --print('node.key:', node.key)
        --print('node.left:', node.left)
        --traverse(q, size)
        assert(node == q[i])
        assert(node.left == sentinel)
    end
end


print('jit.off')
jit.off(test)
test()

print('jit.on')
jit.on(test)
test()
@agentzh
Copy link
Member

agentzh commented Jun 2, 2016

@qlee001 Could you report to the official LuaJIT repository instead? See

https://github.com/LuaJIT/LuaJIT

I can confirm that the official v2.1 branch also has this issue. Thanks!

@qleein
Copy link
Author

qleein commented Jun 3, 2016

@agentzh Ok, thanks!

@qleein
Copy link
Author

qleein commented Jun 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants