diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 71fa20a50b32e798feb494a81ee98d1b5837c10a..91a66393e41a55ba278750abc917f3cba8ee7e7a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,6 @@ lua_source(lua_sources lua/digest.lua) lua_source(lua_sources lua/session.lua) lua_source(lua_sources lua/msgpackffi.lua) lua_source(lua_sources lua/console.lua) -lua_source(lua_sources lua/load_cfg.lua) lua_source(lua_sources lua/bsdsocket.lua) lua_source(lua_sources lua/errno.lua) lua_source(lua_sources lua/log.lua) diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index e64e632f7d5fc07db383a57a81ca5b24b364cd25..4916bcde7568318ab43f870733f33d41706d6fef 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -3,6 +3,7 @@ file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/box/lua) include_directories(${SOPHIA_INCLUDE_DIR}) set(lua_sources) +lua_source(lua_sources lua/load_cfg.lua) lua_source(lua_sources lua/schema.lua) lua_source(lua_sources lua/box_net.lua) lua_source(lua_sources lua/tuple.lua) diff --git a/src/box/lua/call.cc b/src/box/lua/call.cc index 0ed7344ca48cfbd31dfc91edd7d3d1650c79fc7e..afea7defe309fd683a242ea7e6b0cbd54f400e41 100644 --- a/src/box/lua/call.cc +++ b/src/box/lua/call.cc @@ -49,8 +49,8 @@ #include "box/schema.h" /* contents of box.lua, misc.lua, box.net.lua respectively */ -extern char schema_lua[], box_net_lua[]; -static const char *lua_sources[] = { schema_lua, box_net_lua, NULL }; +extern char load_cfg_lua[], schema_lua[], box_net_lua[]; +static const char *lua_sources[] = { schema_lua, box_net_lua, load_cfg_lua, NULL }; /* * Functions, exported in box_lua.h should have prefix diff --git a/src/lua/load_cfg.lua b/src/box/lua/load_cfg.lua similarity index 87% rename from src/lua/load_cfg.lua rename to src/box/lua/load_cfg.lua index d14fbe586c7b6a8f378bcc49fd36d1158c58482d..02deb93aa92f36f7624927e3686047265490f7e0 100644 --- a/src/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -11,7 +11,6 @@ void box_set_too_long_threshold(double threshold); void box_set_snap_io_rate_limit(double limit); ]]) - local function normalize_port_uri(port) if port == nil then return nil @@ -88,6 +87,20 @@ local function reload_cfg(oldcfg, newcfg) end end +local box = require('box') +-- Move all box members to box_saved +local box_configured = {} +for k, v in pairs(box) do + box_configured[k] = v + box[k] = nil +end + +setmetatable(box, { + __index = function(table, index) + error("Please call box.cfg{} first") + end +}) + function box.cfg(cfg) if cfg == nil then cfg = {} @@ -102,6 +115,12 @@ function box.cfg(cfg) -- options that can be number or string cfg[k] = wrapper_cfg[k](cfg[k]) end + -- Restore box members from box_saved after initial configuration + for k, v in pairs(box_configured) do + box[k] = v + end + setmetatable(box, nil) + box_configured = nil box.cfg = setmetatable(cfg, { __newindex = function(table, index) diff --git a/src/lua/init.cc b/src/lua/init.cc index 657415a4c1ed35537cbab5aacb4bd7b38d24d122..44919557389c5d33e9bf744c354fb3c9925c2cf8 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -70,9 +70,9 @@ struct lua_State *tarantool_L; /* contents of src/lua/ files */ extern char uuid_lua[], session_lua[], msgpackffi_lua[], fun_lua[], - load_cfg_lua[], console_lua[], digest_lua[], init_lua[], + console_lua[], digest_lua[], init_lua[], log_lua[]; -static const char *lua_sources[] = { init_lua, session_lua, load_cfg_lua, NULL }; +static const char *lua_sources[] = { init_lua, session_lua, NULL }; static const char *lua_modules[] = { "msgpackffi", msgpackffi_lua, "fun", fun_lua, "digest", digest_lua, "console", console_lua, diff --git a/test/app/cfg.result b/test/app/cfg.result new file mode 100644 index 0000000000000000000000000000000000000000..804aeb7327bdb676764a53f975588204543d8dc5 --- /dev/null +++ b/test/app/cfg.result @@ -0,0 +1,3 @@ +false [string "-- load_cfg.lua - internal file..."]:100: Please call box.cfg{} first +true table +false [string "-- load_cfg.lua - internal file..."]:100: Please call box.cfg{} first diff --git a/test/app/cfg.test.lua b/test/app/cfg.test.lua new file mode 100755 index 0000000000000000000000000000000000000000..6f99c7ec078df93e731de5de52d4eb48885764db --- /dev/null +++ b/test/app/cfg.test.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env tarantool + +-------------------------------------------------------------------------------- +-- All box members must raise an exception on access if box.cfg{} wasn't called +-------------------------------------------------------------------------------- + +local box = require('box') +local function test() + return type(box.space) +end + +print(pcall(test)) +box.cfg{logger="tarantool.log"} +print(pcall(test)) + +os.exit(0) diff --git a/test/app/pcall.result b/test/app/pcall.result index 5067f21845cfe71ac9257a80ce4884b34dbe51f7..e70f316bc71f624ac6e84a1e1646fd9aecb6442d 100644 --- a/test/app/pcall.result +++ b/test/app/pcall.result @@ -7,3 +7,7 @@ pcall with Lua error(): false some message pcall with box.raise(): false some message pcall with no return: 1 pcall with multireturn: true 1 2 3 +-------------------------------------------------------------------------------- +-- #267: Bad exception catching +-------------------------------------------------------------------------------- + diff --git a/test/app/pcall.test.lua b/test/app/pcall.test.lua index 46cff211f129c3e532d0daa2849ff2602181443b..248ccbd7b6344cb687f062fa61ebbd10eb63bcfa 100755 --- a/test/app/pcall.test.lua +++ b/test/app/pcall.test.lua @@ -6,6 +6,7 @@ print[[ -------------------------------------------------------------------------------- ]] +box.cfg{logger="tarantool.log"} function pcalltest() local ERRMSG = "module 'some_invalid_module' not found" local status, msg = pcall(require, 'some_invalid_module') @@ -31,3 +32,4 @@ print('pcall with box.raise():', status, msg) print('pcall with no return:', select('#', pcall(function() end))) print('pcall with multireturn:', pcall(function() return 1, 2, 3 end)) +os.exit(0) diff --git a/test/box/cfg.result b/test/box/cfg.result index 363f04b7cdd65eac42406c1a6eda610151dd1183..2d9d9ba67c1c98a153b0c64a9e3ef50fe70a0fbe 100644 --- a/test/box/cfg.result +++ b/test/box/cfg.result @@ -2,7 +2,7 @@ --# push filter 'admin_port: .*' to 'admin_port: <number>' box.cfg.nosuchoption = 1 --- -- error: '[string "-- load_cfg.lua - internal file..."]:108: Attempt to modify a read-only +- error: '[string "-- load_cfg.lua - internal file..."]:127: Attempt to modify a read-only table' ... t = {} for k,v in pairs(box.cfg) do if type(v) ~= 'table' and type(v) ~= 'function' then table.insert(t, k..': '..tostring(v)) end end