[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] LuaJIT-2.0.0-beta8
- From: Benoit Germain <bnt.germain@...>
- Date: Fri, 24 Jun 2011 14:46:34 +0200
2011/6/24 Mike Pall <mikelu-1106@mike.de>:
> Benoit Germain wrote:
>> 2011/6/24 Mike Pall <mikelu-1106@mike.de>:
>
> Err, no. You use the internal function as a key into a table.
>
> Proof-of-concept code:
>
Ah ok I got it.
Now, For the user to be sure that the code will do what he expects in
a lane, this relies on the fact that, for the keys so processed, the
closure found at some key in the source state will behave the same as
the closure found at the same key in the destination state, since I no
longer copy the implementation, but only a reference that has to be
"linked" in the target state.
I'll be optimistic and assume that this is always the case for C or
LuaJIT-fast functions. But if the user decides for some reason to
override one of the standard functions, even for a valid purpose, this
won't be the case.
For example, it happens that Lanes overrides require(), for a
perfectly valid purpose, which is to wrap the original require()
function inside a mutex to protect modules against multiple parallel
initializations. One can write:
require "lanes"
local my_require = require
lanes.gen( "base", function() my_require "some module" blah blah end)()
Here, my_require is an upvalue that references a C closure wrapping
the vanilla require. What you propose will enable me to find out that
my_require is in fact a closure which is in my lookup table under the
name "require". But it happens that it isn't implemented the same way
in the source and the target state :-(.
Therefore, if some base function is overridden with another C
function, things get a bit complex, because for me to detect this, I
need to compare the result to lua_tocfunction applied to the contents
of the lookup table in the source and destination state. As it happens
,this would even work when running under LuaJIT, because
lua_tocfunction() would return NULL for all optimized vanilla base
functions, unless they are overridden, in which case I would get a
non-NULL lua_CFunction pointer.
However, one could write some overrides in Lua. For example, one could
imagine that a user overrides pairs() to implement a version that
honors a __pairs metamethod.
I need to be able to detect it, because in that case, the function has
to be moved with lua_dump()/luaL_loadbuffer(). Unfortunately, I can't
tell the difference between a Lua and a fast function using
lua_tocfunction(), because it will return NULL for both.
So back to square one: When running Lanes under LuaJIT, how can I
differentiate between a bytecode function and the other functions
using the C API besides guessing from what the debug infos tell me? I
think the simplest for me would be to have lua_tocfunction to return
some dummy pointer for fast functions whose value would be for example
0x0000NN01 where NN is the fast index.
--
Benoit.