pkg/lua: Make the module searchers conform to the API.#9726
pkg/lua: Make the module searchers conform to the API.#9726leandrolanzieri merged 3 commits intoRIOT-OS:masterfrom
Conversation
|
I labeled it as a bug because I was not respecting the API and that qualifies as a bug. @danpetry Do you mind giving me a hand with this one? |
|
@danpetry Ping. |
danpetry
left a comment
There was a problem hiding this comment.
reasoning makes sense - could you please include a test (code or instructions)?
|
@jcarrano ping. |
|
Well, sorry for the delay. Testing this required creating some lua C-extension modules, which I was lazy to write and also did not have time to. I finally got around to doing it, and uncovered another bug in the process. I added a test application. |
5b19166 to
6587c75
Compare
There was a problem hiding this comment.
Changes make sense. I noticed a change of behaviour compared to master, when trying to require a module that is not defined. I guess this is due to the fix of Bug 1?:
On current master
main(): This is RIOT! (Version: 2019.07-devel-527-gd1f06)
Using memory range for Lua heap: 0x56614090 - 0x5661dcd0, 4 bytes
This is Lua: starting interactive session
Welcome to the interactive interpreter
L> require "something"
Runtime error Module 'something' not found in Lua-builtins
L>
L>
With this PR
main(): This is RIOT! (Version: 2019.07-devel-519-g18a38-lua-loader-fix)
Using memory range for Lua heap: 0x5668e090 - 0x56697cd0, 4 bytes
This is Lua: starting interactive session
Welcome to the interactive interpreter
L> require "something"
/home/leandro/Work/RIOT/examples/lua_REPL/../../Makefile.include:557: recipe for target 'term' failed
make: *** [term] Segmentation fault (core dumped)
Also, some minor comments.
D'oh! good catch. I made a copypasta-error (it already felt like copypasta when I was writing the code, I should't have ignored that hunch). I removed the ready-for build. I'll add it back once I have squashed. |
|
@jcarrano that seems to fix it. Maybe you could add '\n' to the error strings, currently the output looks like: |
|
I added some newline and tabs, it should be prettier now. |
leandrolanzieri
left a comment
There was a problem hiding this comment.
Looks good, ACK. Please squash!
The module searchers in the `require` package should return a string if the module is not found, and not raise an error. See: https://www.lua.org/manual/5.3/manual.html#pdf-package.searchers Also make error strings contain newlines and tabs just like the original ones.
After removing the default definitions of lua module tables and table lengths (see lua_builtin.h) the symbols have been left undefined, which results in them getting an address of NULL and a crash if there are no user symbols and the user attempts a "require". This patch checks the address of the table length variable and fails the module search function of the table is not set (i.e. it behaves as if the table was empty.)
For the RIOT port of Lua, the module loader has been more or less rewritten to allow for easily integrating source modules defined in static arrays and C modules embedded in the application. So far the loader had not been tested (and a bug was found). This test should give a bit more certainty that the RIOT integration works as it should.
|
@danpetry any other comments? Please ACK, review or dismiss. |
Contribution description
Bug 1
I messed up the specification for the Lua loader module.
The module searchers in the
requirepackage should return a stringif the module is not found, and not raise an error.
See: https://www.lua.org/manual/5.3/manual.html#pdf-package.searchers
If the searchers raised an error, then the search would stop after the first loader fails to find (which is the current- buggy- behaviour.) The result is that only the pure-lua module table get searched, and it is impossible to load a C extension module.
Bug 2
I violated my own specification, resulting in a crash where a module was requested but no modules were supplied by the user.
This used to work, but then some time ago I remove the definition of the weak symbols used for the tables, leaving them pointing to NULL by default.
Testing procedure
I included a test script in the third commit.