Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
822aedfe
Commit
822aedfe
authored
9 months ago
by
Alexander Turenko
Committed by
Alexander Turenko
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
odict: fix ffi.new('void *') as a key
The problem is found by @ochaton. NO_DOC=bugfix NO_CHANGELOG=not a public API
parent
97a801e1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/box/lua/config/utils/odict.lua
+4
-4
4 additions, 4 deletions
src/box/lua/config/utils/odict.lua
test/config-luatest/odict_test.lua
+36
-0
36 additions, 0 deletions
test/config-luatest/odict_test.lua
with
40 additions
and
4 deletions
src/box/lua/config/utils/odict.lua
+
4
−
4
View file @
822aedfe
...
...
@@ -65,7 +65,7 @@ local function gen(od, prev_key)
-- The previous key is nil only on the first call of the
-- generator function.
local
id
=
prev_key
==
nil
and
0
or
ctx
.
key2id
[
prev_key
]
local
id
=
type
(
prev_key
)
==
'
nil
'
and
0
or
ctx
.
key2id
[
prev_key
]
-- NB: This assert doesn't catch all the kinds of changes
-- during an iteration. It rather verifies a precondition
-- for the following cycle.
...
...
@@ -80,7 +80,7 @@ local function gen(od, prev_key)
-- id2key may contain a stalled entry, because __newindex
-- is not called on assignment of an existing field,
-- including assignment to nil.
if
key
~=
nil
and
od
[
key
]
~=
nil
then
if
type
(
key
)
~=
'
nil
'
and
od
[
key
]
~=
nil
then
return
key
,
od
[
key
]
end
end
...
...
@@ -148,11 +148,11 @@ local function reindex(od, ctx)
for
id
=
1
,
old_max_id
do
local
key
=
ctx
.
id2key
[
id
]
-- Drop the given key-id pair from the key<->id mappings.
if
key
~=
nil
then
if
type
(
key
)
~=
'
nil
'
then
release
(
ctx
,
key
)
end
-- Add the new key-id pair into the key<->id mappings.
if
key
~=
nil
and
od
[
key
]
~=
nil
then
if
type
(
key
)
~=
'
nil
'
and
od
[
key
]
~=
nil
then
track
(
ctx
,
key
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/config-luatest/odict_test.lua
+
36
−
0
View file @
822aedfe
local
fun
=
require
(
'fun'
)
local
ffi
=
require
(
'ffi'
)
local
odict
=
require
(
'internal.config.utils.odict'
)
local
t
=
require
(
'luatest'
)
...
...
@@ -117,6 +118,41 @@ g.test_pairs_delete_and_set = function()
})
end
-- Using cdata as a key is unusual, but it is legal in LuaJIT.
--
-- There is a potential pitfall: ffi.new('void *') == nil. Let's
-- verify that we handle such a key correctly.
g
.
test_null_as_key
=
function
()
local
od
=
odict
.
new
()
local
nulls
=
{
ffi
.
new
(
'void *'
),
ffi
.
new
(
'void *'
),
ffi
.
new
(
'void *'
),
}
od
[
nulls
[
1
]]
=
1
od
[
nulls
[
2
]]
=
2
od
[
nulls
[
3
]]
=
3
local
res
=
{}
for
k
,
v
in
odict
.
pairs
(
od
)
do
table.insert
(
res
,
{
k
,
v
})
end
-- It doesn't differentiate nulls.
t
.
assert_equals
(
res
,
{
{
nulls
[
1
],
1
},
{
nulls
[
2
],
2
},
{
nulls
[
3
],
3
},
})
-- It does.
t
.
assert
(
rawequal
(
res
[
1
][
1
],
nulls
[
1
]))
t
.
assert
(
rawequal
(
res
[
2
][
1
],
nulls
[
2
]))
t
.
assert
(
rawequal
(
res
[
3
][
1
],
nulls
[
3
]))
end
-- {{{ Helpers for reindexing test cases
-- Parse a range expressed like Python's slice operator.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment