Skip to content

Commit 5dfa4f4

Browse files
authored
Merge branch 'main' into feature/property-name
2 parents e514472 + 090dd21 commit 5dfa4f4

File tree

11 files changed

+39
-2752
lines changed

11 files changed

+39
-2752
lines changed

Lib/test/test_os.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,23 +3506,22 @@ class ProgramPriorityTests(unittest.TestCase):
35063506
"""Tests for os.getpriority() and os.setpriority()."""
35073507

35083508
def test_set_get_priority(self):
3509-
35103509
base = os.getpriority(os.PRIO_PROCESS, os.getpid())
3511-
os.setpriority(os.PRIO_PROCESS, os.getpid(), base + 1)
3512-
try:
3513-
new_prio = os.getpriority(os.PRIO_PROCESS, os.getpid())
3514-
# nice value cap is 19 for linux and 20 for FreeBSD
3515-
if base >= 19 and new_prio <= base:
3516-
raise unittest.SkipTest("unable to reliably test setpriority "
3517-
"at current nice level of %s" % base)
3518-
else:
3519-
self.assertEqual(new_prio, base + 1)
3520-
finally:
3521-
try:
3522-
os.setpriority(os.PRIO_PROCESS, os.getpid(), base)
3523-
except OSError as err:
3524-
if err.errno != errno.EACCES:
3525-
raise
3510+
code = f"""if 1:
3511+
import os
3512+
os.setpriority(os.PRIO_PROCESS, os.getpid(), {base} + 1)
3513+
print(os.getpriority(os.PRIO_PROCESS, os.getpid()))
3514+
"""
3515+
3516+
# Subprocess inherits the current process' priority.
3517+
_, out, _ = assert_python_ok("-c", code)
3518+
new_prio = int(out)
3519+
# nice value cap is 19 for linux and 20 for FreeBSD
3520+
if base >= 19 and new_prio <= base:
3521+
raise unittest.SkipTest("unable to reliably test setpriority "
3522+
"at current nice level of %s" % base)
3523+
else:
3524+
self.assertEqual(new_prio, base + 1)
35263525

35273526

35283527
@unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")

Lib/test/test_property.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ def test_refleaks_in___init__(self):
183183
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
184184
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
185185

186+
@support.refcount_test
187+
def test_gh_115618(self):
188+
# Py_XDECREF() was improperly called for None argument
189+
# in property methods.
190+
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
191+
prop = property()
192+
refs_before = gettotalrefcount()
193+
for i in range(100):
194+
prop = prop.getter(None)
195+
self.assertIsNone(prop.fget)
196+
for i in range(100):
197+
prop = prop.setter(None)
198+
self.assertIsNone(prop.fset)
199+
for i in range(100):
200+
prop = prop.deleter(None)
201+
self.assertIsNone(prop.fdel)
202+
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
203+
186204
def test_property_name(self):
187205
def getter(self):
188206
return 42
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix improper decreasing the reference count for ``None`` argument in
2+
:class:`property` methods :meth:`~property.getter`, :meth:`~property.setter`
3+
and :meth:`~property.deleter`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``ProgramPriorityTests`` in ``test_os`` permanently changing the process
2+
priority.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove outdated Tools/{io,cc,string}bench

Objects/descrobject.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,15 +1735,12 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
17351735
return NULL;
17361736

17371737
if (get == NULL || get == Py_None) {
1738-
Py_XDECREF(get);
17391738
get = pold->prop_get ? pold->prop_get : Py_None;
17401739
}
17411740
if (set == NULL || set == Py_None) {
1742-
Py_XDECREF(set);
17431741
set = pold->prop_set ? pold->prop_set : Py_None;
17441742
}
17451743
if (del == NULL || del == Py_None) {
1746-
Py_XDECREF(del);
17471744
del = pold->prop_del ? pold->prop_del : Py_None;
17481745
}
17491746
if (pold->getter_doc && get != Py_None) {

Tools/README

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ c-analyzer Tools to check no new global variables have been added.
1010

1111
cases_generator Tooling to generate interpreters.
1212

13-
ccbench A Python threads-based concurrency benchmark. (*)
14-
1513
clinic A preprocessor for CPython C files in order to automate
1614
the boilerplate involved with writing argument parsing
1715
code for "builtins".
@@ -28,8 +26,6 @@ i18n Tools for internationalization. pygettext.py
2826

2927
importbench A set of micro-benchmarks for various import scenarios.
3028

31-
iobench Benchmark for the new Python I/O system. (*)
32-
3329
msi Support for packaging Python as an MSI package on Windows.
3430

3531
nuget Files for the NuGet package manager for .NET.
@@ -45,9 +41,6 @@ scripts A number of useful single-file programs, e.g. run_tests.py
4541
ssl Scripts to generate ssl_data.h from OpenSSL sources, and run
4642
tests against multiple installations of OpenSSL and LibreSSL.
4743

48-
stringbench A suite of micro-benchmarks for various operations on
49-
strings (both 8-bit and unicode). (*)
50-
5144
tz A script to dump timezone from /usr/share/zoneinfo.
5245

5346
unicode Tools for generating unicodedata and codecs from unicode.org
@@ -60,6 +53,4 @@ unittestgui A Tkinter based GUI test runner for unittest, with test
6053
wasm Config and helpers to facilitate cross compilation of CPython
6154
to WebAssembly (WASM).
6255

63-
(*) A generic benchmark suite is maintained separately at https://github.com/python/performance
64-
6556
Note: The pynche color editor has moved to https://gitlab.com/warsaw/pynche

0 commit comments

Comments
 (0)