luajit require("file") and table.concat issue

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

luajit require("file") and table.concat issue

aSEioT
Sorry for my poorly english, I just try to report my problem when using the latest luajit. This is first time I post here, hope your guys can understand it.

Demo code as loading lua51.dll by dllcall.

    handle := DllCall("LoadLibrary", "Str","lua51.dll")

    L := DllCall("lua51\luaL_newstate","Cdecl")

    DllCall("lua51\luaL_openlibs", "Ptr", L,"Cdecl")

    DllCall("lua51\luaL_loadfile", "Ptr", L,"AStr", "main.lua", "Cdecl Int")

    DllCall("lua51\lua_pcall", "Ptr", L,"Int", 0, "Int", 0, "Ptr", 0, "Cdecl")

    /* we want to close it now*/

    DllCall("lua51\lua_close", "Ptr", L,"Cdecl")

    DllCall("FreeLibrary", "Ptr", handle )

    /* The lua51.dll is still in use in latest luajit(in win7 sp1 and xp sp3)*/

The content of Main.lua is:

    require "sth"    -- require sth.lua, thiscause the problem. No matter what thecontent of sth.lua, even is empty.

    require "ffi"  -- no problem when we load internal lib.

About table.concat, It just broken recently, I still use the 10.14 version with no problem.

    local concat = table.concat

    function tableToJson (s, ic)

        if not ic and type(s) ~= "table" then return s end

        local l = {}

        for k, v in pairs(s) do

            if type(v) == "table" then

                l[#l+1] = k .. ":".. tableToJson (v, true)

            else

                l[#l+1] = k .. ':"' .. tostring(v) ..'"'

            end

        end

        if #l>0 then

            return "{" .. concat(l, ",") .. "}"

        else

            return "{}"

        end

    end

This function may generate truncated result in some situation, and stop me from using the latest git-head version.

Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

Mike Pall-33
junjie shen wrote:
> The content of Main.lua is:
>
>     require "sth"    -- require sth.lua, thiscause the problem. No matter what thecontent of sth.lua, even is empty.

Have a look at the error message from require. I.e. the string
that pcall puts on the Lua stack if it returns with an error.
This ought to tell you what happened.

> About table.concat, It just broken recently, I still use the 10.14 version with no problem.

10.14? There's no such version. You need to give a commit ID.

Also, there has been no change to table.concat recently. Try
cleaning your git tree and rebuild everything from scratch.

>     function tableToJson (s, ic)
> [...]
> This function may generate truncated result in some situation, and stop me from using the latest git-head version.

It doesn't give wrong results for any kind of input table I can
come up with. You'll have to provide a complete test case.

--Mike

Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

aSEioT
In reply to this post by aSEioT
> Have a look at the error message from require. I.e. the string
> that pcall puts on the Lua stack if it returns with an error.
>This ought to tell you what happened.

Sure, I had checked the return of lua_pcall with no error!

   > > About table.concat, It just broken recently, I still use the 10.14
version with no problem.

   > 10.14? There's no such version. You need to give a commit ID.

   > Also, there has been no change to table.concat recently. Try
    >cleaning your git tree and rebuild everything from scratch.

    >>     function tableToJson (s, ic)
   > > [...]
    >> This function may generate truncated result in some situation, and
stop me from using the latest git-head version.

   > It doesn't give wrong results for any kind of input table I can
    >come up with. You'll have to provide a complete test case.
   > ... [show rest of quote]

After redownloaded and rebuilded dozens of commit version. I finally found
it happend since commit "2dc574d06bc6e828109a3bffa975592f9417434c".
btw: I was call the "ffi" lib to snap the processes and relative information
in a table, after that I convert the table to the Json style and return to
the caller.( does this helpful?)


Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

aSEioT
In reply to this post by aSEioT
>> Have a look at the error message from require. I.e. the string
>> that pcall puts on the Lua stack if it returns with an error.
>>This ought to tell you what happened.

>Sure, I had checked the return of lua_pcall with no error!

Additional test, I found it broken since commit
"aad7ea3c02b0baed5b700565eea36c9b33d7c6b1", and no such problem in previous
versions and lua 5.14.
After we load and unload the lua51.dll, It just locked and cannot be deleted
before we exit the caller.


Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

Mike Pall-33
In reply to this post by aSEioT
aSEioT wrote:
> After redownloaded and rebuilded dozens of commit version. I finally found
> it happend since commit "2dc574d06bc6e828109a3bffa975592f9417434c".
> btw: I was call the "ffi" lib to snap the processes and relative information
> in a table, after that I convert the table to the Json style and return to
> the caller.( does this helpful?)

This change allowed FFI calls to __stdcall functions to be
compiled. Previously this caused a fallback to the interpreter.
Maybe something is still wrong in the code generation for this
feature. So the problem is most likely not in table.concat itself.

You probably use calls to some __stdcall Windows API function to
generate the table. Which Windows API functions do you call in a
loop? To debug this further, I'll probably need to see the FFI
part of your code.

--Mike

Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

Mike Pall-33
In reply to this post by aSEioT
aSEioT wrote:

> >> Have a look at the error message from require. I.e. the string
> >> that pcall puts on the Lua stack if it returns with an error.
> >>This ought to tell you what happened.
>
> >Sure, I had checked the return of lua_pcall with no error!
>
> Additional test, I found it broken since commit
> "aad7ea3c02b0baed5b700565eea36c9b33d7c6b1", and no such problem in previous
> versions and lua 5.14.
> After we load and unload the lua51.dll, It just locked and cannot be deleted
> before we exit the caller.

Ah, ok! Sorry, but I have misunderstood your problem.

So require() itself works fine. Your actual problem is that calls
to require() for a new module messed up the module reference count
for lua51.dll. Thank you for the report! Fixed in git HEAD.

--Mike

Reply | Threaded
Open this post in threaded view
|

Re: luajit require("file") and table.concat issue

aSEioT
In reply to this post by aSEioT
Many thanks! It work flawless now!