You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Peter Cawley <co...@corsix.org> on 2009/03/26 21:20:00 UTC

mod_lua: package.loaded == apache2 (bug)

The function apl_load_apache2_lmodule, which is meant to load the
apache2 library is flawed in that it loads the library into the
package.loaded table and sets this as the global "apache2". It should
load it into a new table, and set this as the global "apache2" and
package.loaded.apache2. What follows is a small test script which
shows this (all tests _should_ pass, but most of the apache2 ones do
not). Also attached is a patch which fixes this.

---- begin code sample ----
function handle(req)
  local function assert(test)
    local status = loadstring('return '.. test)()
    req:write(test ..': '.. (status and "pass" or "FAIL") ..'\n')
  end

  -- control tests
  assert [[string == require "string"]]
  assert "package.loaded.math == math"

  -- apache2 tests
  assert [[apache2 == require "apache2"]]
  assert "package.loaded.apache2 == apache2"
  assert "package.loaded ~= apache2"
  assert "apache2.apache2 == nil"
  assert "apache2.OK ~= nil"
  assert "package.loaded.apache2.OK ~= nil"
end
---- end code sample ----

Re: mod_lua: package.loaded == apache2 (bug)

Posted by Bertrand Mansion <bm...@mamasam.net>.
On Thu, Mar 26, 2009 at 9:20 PM, Peter Cawley <co...@corsix.org> wrote:
> The function apl_load_apache2_lmodule, which is meant to load the
> apache2 library is flawed in that it loads the library into the
> package.loaded table and sets this as the global "apache2". It should
> load it into a new table, and set this as the global "apache2" and
> package.loaded.apache2. What follows is a small test script which
> shows this (all tests _should_ pass, but most of the apache2 ones do
> not). Also attached is a patch which fixes this.

I have tested the patch and I confirm it fixes the bug (thank you
Peter). Now OK, DECLINED etc are accessible. I have patched my work
repository:
http://mamasam.indefero.net/p/modlua/source/tree/mansion/


-- 
Bertrand Mansion
Mamasam