Skip to content
Snippets Groups Projects
Commit f89b5ab0 authored by Chris Sosnin's avatar Chris Sosnin Committed by Kirill Yukhin
Browse files

box: frommap() bug fix

- If an optional argument is provided for
  space_object:frommap() (which is {table = true|false}),
  type match for first arguments is omitted, which is
  incorrect. We should return the result only after making
  sure it is possible to build a tuple.

- If there is a type mismatch, however, frommap() does not
  return nil, err as it is mentioned in the description, so we
  change it to be this way.

Closes #4262
parent 21ae2899
No related branches found
No related tags found
No related merge requests found
......@@ -580,14 +580,18 @@ lbox_space_frommap(struct lua_State *L)
}
lua_rawseti(L, -3, fieldno+1);
}
if (table)
return 1;
lua_replace(L, 1);
lua_settop(L, 1);
tuple = luaT_tuple_new(L, -1, space->format);
if (tuple == NULL)
return luaT_error(L);
if (tuple == NULL) {
struct error *e = diag_last_error(&fiber()->diag);
lua_pushnil(L);
lua_pushstring(L, e->errmsg);
return 2;
}
if (table)
return 1;
luaT_pushtuple(L, tuple);
return 1;
usage_error:
......
......@@ -1121,7 +1121,13 @@ s:frommap()
...
s:frommap({})
---
- error: Tuple field 1 required by space format is missing
- null
- Tuple field 1 required by space format is missing
...
s:frommap({ddd = 'fail', aaa = 2, ccc = 3, bbb = 4}, {table=true})
---
- null
- 'Tuple field 4 type does not match one required by operation: expected unsigned'
...
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true})
---
......
......@@ -373,6 +373,7 @@ s:frommap({ddd = 1, aaa = 2, bbb = 3})
s:frommap({ddd = 1, aaa = 2, ccc = 3, eee = 4})
s:frommap()
s:frommap({})
s:frommap({ddd = 'fail', aaa = 2, ccc = 3, bbb = 4}, {table=true})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = false})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = box.NULL})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment