lua: split fio to minifio and fio
The minifio module is supposed to be used in tarantool's code that potentially works at early initialization stage. The loaders.lua module needs several file manipulation functions and it'll be moved to the early initialization stage (see the previous commit for the idea). Next commits will use minifio instead of fio in loaders.lua and will move minifio and loaders at the early loading stage. The list of changes in the functions: * fio.pathjoin() uses `error(<...>, 0)` to don't prefix the error message with `internal.minifio.lua` -- a user is unlikely interested how fio is split to files internally. * An obsoleted comment from fio.abspath() is dropped (it is obsoleted by commit 583e8ba2 ("fio: new approach for error handling")). cwd(), pathjoin() and abspath() are moved to `minifio` and exposed from `fio`. dirname() is duplicated: `minifio`'s implementation uses ffi.new(), `fio`'s implementation uses cord_ibuf_take()/cord_ibuf_put(). ## Alternatives considered In brief: no really good option, but the implemented one looks as the best one. ### Copy to loaders.lua First option is to copy those four functions right into loaders.lua. It requires a slight adaptation: - cwd(): reimplement using ffi. - pathjoin(): just copy. - abspath(): copy and use own cwd() and pathjoin(). - dirname(): copy and use ffi.new() instead of cord_ibuf_take()/cord_ibuf_put(). All the functions would be maintained in two places that is error-prone. It would be good to reduce amount of copies of the same/similar code. ### Add minifio.lua Okay, let's assume we created own file for the four functions. Can we avoid adding minifio.c for cwd()? There are two ways (spoiler: both are bad). * We can initialize the C part of `fio` before minifio.lua and use it here. But it would be highly counter-intuitive to use `fio` in `minifio`. * We can reimplement cwd() on ffi, but we'll need to duplicate abspath() to use `minifio`'s cwd() function. We definitely need `minifio.c`. ### Add minifio.c and minifio.lua This option is implemented in this commit. The only function that is duplicated is dirname(). ### Mitigate dirname() duplication There are two ways. It is possible to add a dependency on the `buffer` module and use cord_ibuf_take()/cord_ibuf_put() in `minifio`. However it would mean that `buffer` shouldn't depend on other built-in modules. It is logical for `minifio`, which is created specifically to load at early stage, but counter-intuitive for `buffer`. If `buffer` will depend on another built-in module in a future, a developer will need to play around 'right' order of loading. We can also move dirname()'s implementation to the C part of `minifio`, use C's cord_ibuf_take()/cord_ibuf_put() and expose the function as to `minifio` as well as to `fio`. The latter is a good option, but I don't bother much about the copy-paste, because the function body has 7 SLoC. ### Move into Lua C API We can implement all the four function using the Lua C API in fio.c and initialize the C part of `fio` before loading of loaders.lua. It would look more clean in some sense: all the file manipulation functions are in the `fio` module. However it is also error-prone, because nothing would stop a future developer to use some fio.foobar() function, which is actually loaded after loaders.lua, before loading Lua's part of `fio`. An explicit splitting to early/usual stage looks safer. Part of #7774 NO_TEST=no user visible changes NO_CHANGELOG=see NO_TEST NO_DOC=see NO_TEST
Showing
- src/CMakeLists.txt 2 additions, 0 deletionssrc/CMakeLists.txt
- src/lua/fio.c 0 additions, 16 deletionssrc/lua/fio.c
- src/lua/fio.lua 14 additions, 68 deletionssrc/lua/fio.lua
- src/lua/init.c 5 additions, 1 deletionsrc/lua/init.c
- src/lua/minifio.c 58 additions, 0 deletionssrc/lua/minifio.c
- src/lua/minifio.h 19 additions, 0 deletionssrc/lua/minifio.h
- src/lua/minifio.lua 113 additions, 0 deletionssrc/lua/minifio.lua
- test/app/fio.result 4 additions, 4 deletionstest/app/fio.result
Loading
Please register or sign in to comment