lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Sep 4, 2009 at 1:49 PM, Jack Pham<jackp@qualcomm.com> wrote:
> Hi,
>
> This doesn't cause any errors but it looks like the creation of the
> "package.loaders" table in luaopen_package() is calling lua_createtable()
> incorrectly, with the "narr" and "nrec" parameters swapped, perhaps leading
> to some unnecessary reallocation at load time?
>
> --- loadlib.c   2008-08-06 06:29:28.000000000 -0700
> +++ loadlib.c.new       2009-09-04 10:36:47.616920300 -0700
> @@ -638,9 +638,9 @@
> #endif
>  lua_pushvalue(L, -1);
>  lua_replace(L, LUA_ENVIRONINDEX);
>  /* create `loaders' table */
> -  lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
> +  lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
>  /* fill it with pre-defined loaders */
>  for (i=0; loaders[i] != NULL; i++) {
>    lua_pushcfunction(L, loaders[i]);
>    lua_rawseti(L, -2, i+1);
>
> In other words the table is initially constructed as a hash of predetermined
> size but is best suited as an array as evidenced by the calls to
> lua_rawseti().
>
> Thanks,
> Jack
>

I think you are right.

--Leo--