Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
77aa396b
Commit
77aa396b
authored
May 22, 2019
by
Jeroen Demeyer
Committed by
Petr Viktorin
May 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36907: fix refcount bug in _PyStack_UnpackDict() (GH-13381)
parent
b892d3ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
5 deletions
+31
-5
Lib/test/test_call.py
Lib/test/test_call.py
+17
-0
Misc/NEWS.d/next/Core and Builtins/2019-05-17-12-28-24.bpo-36907.rk7kgp.rst
...ore and Builtins/2019-05-17-12-28-24.bpo-36907.rk7kgp.rst
+2
-0
Objects/call.c
Objects/call.c
+12
-5
No files found.
Lib/test/test_call.py
View file @
77aa396b
...
...
@@ -8,6 +8,7 @@ except ImportError:
import
struct
import
collections
import
itertools
import
gc
class
FunctionCalls
(
unittest
.
TestCase
):
...
...
@@ -457,6 +458,22 @@ class FastCallTests(unittest.TestCase):
result = _testcapi.pyobject_fastcallkeywords(func, args, kwnames)
self.check_result(result, expected)
def test_fastcall_clearing_dict(self):
# Test bpo-36907: the point of the test is just checking that this
# does not crash.
class IntWithDict:
__slots__ = ["
kwargs
"]
def __init__(self, **kwargs):
self.kwargs = kwargs
def __index__(self):
self.kwargs.clear()
gc.collect()
return 0
x = IntWithDict(dont_inherit=IntWithDict())
# We test the argument handling of "
compile
" here, the compilation
# itself is not relevant. When we pass flags=x below, x.__index__() is
# called, which changes the keywords dict.
compile("
pass
", "", "
exec
", x, **x.kwargs)
if __name__ == "
__main__
":
unittest.main()
Misc/NEWS.d/next/Core and Builtins/2019-05-17-12-28-24.bpo-36907.rk7kgp.rst
0 → 100644
View file @
77aa396b
Fix a crash when calling a C function with a keyword dict (``f(**kwargs)``)
and changing the dict ``kwargs`` while that function is running.
Objects/call.c
View file @
77aa396b
...
...
@@ -544,10 +544,14 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self,
}
result
=
(
*
fastmeth
)
(
self
,
stack
,
nargs
,
kwnames
);
if
(
stack
!=
args
)
{
if
(
kwnames
!=
NULL
)
{
Py_ssize_t
i
,
n
=
nargs
+
PyTuple_GET_SIZE
(
kwnames
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
Py_DECREF
(
stack
[
i
]);
}
PyMem_Free
((
PyObject
**
)
stack
);
Py_DECREF
(
kwnames
);
}
Py_XDECREF
(
kwnames
);
break
;
}
...
...
@@ -1334,8 +1338,11 @@ _PyStack_UnpackDict(PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs,
return
-
1
;
}
/* Copy position arguments (borrowed references) */
memcpy
(
stack
,
args
,
nargs
*
sizeof
(
stack
[
0
]));
/* Copy positional arguments */
for
(
i
=
0
;
i
<
nargs
;
i
++
)
{
Py_INCREF
(
args
[
i
]);
stack
[
i
]
=
args
[
i
];
}
kwstack
=
stack
+
nargs
;
pos
=
i
=
0
;
...
...
@@ -1344,8 +1351,8 @@ _PyStack_UnpackDict(PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs,
called in the performance critical hot code. */
while
(
PyDict_Next
(
kwargs
,
&
pos
,
&
key
,
&
value
))
{
Py_INCREF
(
key
);
Py_INCREF
(
value
);
PyTuple_SET_ITEM
(
kwnames
,
i
,
key
);
/* The stack contains borrowed references */
kwstack
[
i
]
=
value
;
i
++
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment