mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
[3.12] gh-115618: Remove improper Py_XDECREFs in property methods (GH-115619) (GH-115620)
(cherry picked from commit 090dd21ab9
)
This commit is contained in:
parent
2763f382f9
commit
b9d1efa696
3 changed files with 21 additions and 3 deletions
|
@ -183,6 +183,24 @@ class PropertyTests(unittest.TestCase):
|
||||||
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
|
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
|
||||||
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
|
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
|
||||||
|
|
||||||
|
@support.refcount_test
|
||||||
|
def test_gh_115618(self):
|
||||||
|
# Py_XDECREF() was improperly called for None argument
|
||||||
|
# in property methods.
|
||||||
|
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
|
||||||
|
prop = property()
|
||||||
|
refs_before = gettotalrefcount()
|
||||||
|
for i in range(100):
|
||||||
|
prop = prop.getter(None)
|
||||||
|
self.assertIsNone(prop.fget)
|
||||||
|
for i in range(100):
|
||||||
|
prop = prop.setter(None)
|
||||||
|
self.assertIsNone(prop.fset)
|
||||||
|
for i in range(100):
|
||||||
|
prop = prop.deleter(None)
|
||||||
|
self.assertIsNone(prop.fdel)
|
||||||
|
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
|
||||||
|
|
||||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||||
"Docstrings are omitted with -O2 and above")
|
"Docstrings are omitted with -O2 and above")
|
||||||
def test_class_property(self):
|
def test_class_property(self):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix improper decreasing the reference count for ``None`` argument in
|
||||||
|
:class:`property` methods :meth:`~property.getter`, :meth:`~property.setter`
|
||||||
|
and :meth:`~property.deleter`.
|
|
@ -1697,15 +1697,12 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (get == NULL || get == Py_None) {
|
if (get == NULL || get == Py_None) {
|
||||||
Py_XDECREF(get);
|
|
||||||
get = pold->prop_get ? pold->prop_get : Py_None;
|
get = pold->prop_get ? pold->prop_get : Py_None;
|
||||||
}
|
}
|
||||||
if (set == NULL || set == Py_None) {
|
if (set == NULL || set == Py_None) {
|
||||||
Py_XDECREF(set);
|
|
||||||
set = pold->prop_set ? pold->prop_set : Py_None;
|
set = pold->prop_set ? pold->prop_set : Py_None;
|
||||||
}
|
}
|
||||||
if (del == NULL || del == Py_None) {
|
if (del == NULL || del == Py_None) {
|
||||||
Py_XDECREF(del);
|
|
||||||
del = pold->prop_del ? pold->prop_del : Py_None;
|
del = pold->prop_del ? pold->prop_del : Py_None;
|
||||||
}
|
}
|
||||||
if (pold->getter_doc && get != Py_None) {
|
if (pold->getter_doc && get != Py_None) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue