From feedc86f86bf91e6ed96158943529e511ad49d12 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 24 Apr 2017 21:44:25 +0300 Subject: [PATCH 1/2] bpo-30156: Fix a crash in debug build when PYTHONDUMPREFS is set. Apply an alternate patch from bpo-26811. --- Misc/NEWS | 2 ++ Objects/descrobject.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index bf0c015eeb54c9d..d36b63e14bb7117 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1? Core and Builtins ----------------- +- bpo-30156: Fixed a crash in debug build when PYTHONDUMPREFS is set. + - bpo-12414: sys.getsizeof() on a code object now returns the sizes which includes the code struct and sizes of objects which it references. Patch by Dong-hee Na. diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 1d11605a9b8d3bf..10bae67bf02ef2c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1374,12 +1374,15 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type) return NULL; } args = cached_args; - cached_args = NULL; if (!args) { args = PyTuple_New(1); if (!args) return NULL; - _PyObject_GC_UNTRACK(args); + } + else { + cached_args = NULL; + assert(Py_REFCNT(args) == 1); + Py_SIZE(args) = 1; } Py_INCREF(obj); PyTuple_SET_ITEM(args, 0, obj); @@ -1387,12 +1390,12 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type) if (cached_args == NULL && Py_REFCNT(args) == 1) { assert(PyTuple_GET_SIZE(args) == 1); assert(PyTuple_GET_ITEM(args, 0) == obj); + Py_SIZE(args) = 0; cached_args = args; Py_DECREF(obj); } else { assert(Py_REFCNT(args) >= 1); - _PyObject_GC_TRACK(args); Py_DECREF(args); } return ret; From 719d46ae79f96a74d4166097323a66c4492dc069 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 12 Oct 2017 23:46:05 +0300 Subject: [PATCH 2/2] Move the NEWS entry to NEWS.d/. --- Misc/NEWS | 2 -- .../Core and Builtins/2017-10-12-23-45-54.bpo-30156.dZ3kZk.rst | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2017-10-12-23-45-54.bpo-30156.dZ3kZk.rst diff --git a/Misc/NEWS b/Misc/NEWS index fafb96d2face03a..6f90175bf7713f1 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,8 +10,6 @@ What's New in Python 3.7.0 alpha 1? Core and Builtins ----------------- -- bpo-30156: Fixed a crash in debug build when PYTHONDUMPREFS is set. - - bpo-29104: Fixed parsing backslashes in f-strings. - bpo-27945: Fixed various segfaults with dict when input collections are diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-10-12-23-45-54.bpo-30156.dZ3kZk.rst b/Misc/NEWS.d/next/Core and Builtins/2017-10-12-23-45-54.bpo-30156.dZ3kZk.rst new file mode 100644 index 000000000000000..c1c50e33d053353 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-10-12-23-45-54.bpo-30156.dZ3kZk.rst @@ -0,0 +1 @@ +Fixed a crash in debug build when PYTHONDUMPREFS is set.