[Python-checkins] bpo-34042: Fix dict.copy() to maintain correct total refcount (GH-8119)
Miss Islington (bot)
webhook-mailer at python.org
Fri Jul 6 12:40:20 EDT 2018
https://github.com/python/cpython/commit/127bd9bfd591c8ec1a97eb7f4037c8b884eef973
commit: 127bd9bfd591c8ec1a97eb7f4037c8b884eef973
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-07-06T09:40:17-07:00
summary:
bpo-34042: Fix dict.copy() to maintain correct total refcount (GH-8119)
(cherry picked from commit 0b75228700e0077d8bf2636e74733389514b4b2f)
Co-authored-by: Yury Selivanov <yury at magic.io>
files:
A Misc/NEWS.d/next/Core and Builtins/2018-07-05-15-51-29.bpo-34042.Gr9XUH.rst
M Objects/dictobject.c
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-07-05-15-51-29.bpo-34042.Gr9XUH.rst b/Misc/NEWS.d/next/Core and Builtins/2018-07-05-15-51-29.bpo-34042.Gr9XUH.rst
new file mode 100644
index 000000000000..fd1730d4308b
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-07-05-15-51-29.bpo-34042.Gr9XUH.rst
@@ -0,0 +1,2 @@
+Fix dict.copy() to maintain correct total refcount (as reported by
+sys.gettotalrefcount()).
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 7a1bcebec6fd..828eb99e2d03 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -656,6 +656,13 @@ clone_combined_dict(PyDictObject *orig)
/* Maintain tracking. */
_PyObject_GC_TRACK(new);
}
+
+ /* Since we copied the keys table we now have an extra reference
+ in the system. Manually call _Py_INC_REFTOTAL to signal that
+ we have it now; calling DK_INCREF would be an error as
+ keys->dk_refcnt is already set to 1 (after memcpy). */
+ _Py_INC_REFTOTAL;
+
return (PyObject *)new;
}
More information about the Python-checkins
mailing list