lua-yaml: call __serialize once for all aliases
The YAML format supports aliasing - if the same object is referenced more than once, it will be encoded in one places with other places being turned to references: tarantool> x = {} --- ... tarantool> {a = x, b = x} --- - a: &0 [] b: *0 ... This feature is useful for dumping a space list (e.g. box.space) to the console, because each space is referenced by name and id. However, it doesn't work if the referenced object implements the __serialize method: tarantool> x = setmetatable({}, { > __serialize = function() return {} end, > }) --- ... tarantool> {a = x, b = x} --- - a: [] b: [] ... This happens because we check for aliases in dump_array and dump_table (with get_yaml_anchor), after calling the __serialize method via luaL_checkfield. Since the __serialize method may (and usually does) return a different object on each invocation, aliases aren't detected. Let's fix it by calling alias detection (get_yaml_anchor) before luaL_checkfield and passing the anchor to dump_table/dump_array. Needed for https://github.com/tarantool/tarantool-ee/issues/221 Part of #8240 NO_DOC=bug fix NO_CHANGELOG=next commit (cherry picked from commit 310de56f)
Showing
Loading
Please register or sign in to comment