forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tarantool#8350 was introduced by the commit b42302f ("lua-yaml: enable aliasing for objects returned by __serialize") so the patch is effectively reversed. The idea is to call all object __serialize methods recursively before finding references. The new serialization pass stores the mapping from the original object to the serialized representation. After this, the reference analysis pass and the encoding pass use this mapping to replace original objects with the serialized representation. As result, the reference analysis has a complete information about objects and no references are missed. Closes tarantool#8350 Closes tarantool#8310 Closes tarantool#8321 NO_DOC=bugfix Co-authored-by: Nikolay Shirokovskiy <nshirokovskiy@tarantool.org> (cherry picked from commit 610f5fb)
- Loading branch information
1 parent
3a95774
commit 29458ba
Showing
8 changed files
with
311 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## bugfix/lua | ||
|
||
* Fixed alias detection in the YAML encoder (gh-8350, gh-8310, gh-8321). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local yaml = require('yaml') | ||
local fiber = require('fiber') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
|
||
local strip = function(str) | ||
return str:gsub('^%s*', ''):gsub('\n%s*', '\n') | ||
end | ||
|
||
local function serialize(o, s) | ||
s = s or yaml | ||
return s.decode(s.encode(o)) | ||
end | ||
|
||
g.test_recursion = function() | ||
local x = {} | ||
x.x = x | ||
local res = serialize(x) | ||
t.assert(rawequal(res, res.x)) | ||
end | ||
|
||
g.test_stress = function() | ||
local s = yaml.new() | ||
s.cfg({encode_use_tostring = true}) | ||
|
||
-- Shouldn't raise or cycle. | ||
serialize(_G, s) | ||
end | ||
|
||
g.test_gh_8350_no_unnecessary_anchors = function() | ||
local x = {{}} | ||
setmetatable(x, {__serialize = function(_) return {x[1]} end}) | ||
local expected = [[ | ||
--- | ||
- [] | ||
... | ||
]] | ||
t.assert_equals(yaml.encode(x), strip(expected)) | ||
end | ||
|
||
g.test_gh_8310_alias_across_serialize_method = function() | ||
local x = {} | ||
local y = setmetatable({}, {__serialize = function() return x end}) | ||
local z = {x, y} | ||
local expected = [[ | ||
--- | ||
- &0 [] | ||
- *0 | ||
... | ||
]] | ||
t.assert_equals(yaml.encode(z), strip(expected)) | ||
end | ||
|
||
g.test_gh_8321_alias_between_same_udata_objects = function() | ||
local x = serialize({fiber.self(), fiber.self()}) | ||
t.assert(rawequal(x[1], x[2])) | ||
end | ||
|
||
g.test_gh_8321_alias_between_same_cdata_objects = function() | ||
local tuple = box.tuple.new({}) | ||
local x = serialize({tuple, tuple}) | ||
t.assert(rawequal(x[1], x[2])) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.