Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
af56e0e7
Kaydet (Commit)
af56e0e7
authored
Ara 16, 2016
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28991: Fix obscure reentrancy bug in functools.lru_cache().
üst
ac13beee
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
functools.py
Lib/functools.py
+4
-2
test_functools.py
Lib/test/test_functools.py
+13
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/functools.py
Dosyayı görüntüle @
af56e0e7
...
...
@@ -516,14 +516,16 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
last
=
root
[
PREV
]
link
=
[
last
,
root
,
key
,
result
]
last
[
NEXT
]
=
root
[
PREV
]
=
cache
[
key
]
=
link
full
=
(
len
(
cache
)
>=
maxsize
)
# Use the __len__() method instead of the len() function
# which could potentially be wrapped in an lru_cache itself.
full
=
(
cache
.
__len__
()
>=
maxsize
)
misses
+=
1
return
result
def
cache_info
():
"""Report cache statistics"""
with
lock
:
return
_CacheInfo
(
hits
,
misses
,
maxsize
,
len
(
cache
))
return
_CacheInfo
(
hits
,
misses
,
maxsize
,
cache
.
__len__
(
))
def
cache_clear
():
"""Clear the cache and cache statistics"""
...
...
Lib/test/test_functools.py
Dosyayı görüntüle @
af56e0e7
import
abc
import
builtins
import
collections
import
copy
from
itertools
import
permutations
...
...
@@ -1162,6 +1163,18 @@ class TestLRU:
self
.
assertEqual
(
misses
,
4
)
self
.
assertEqual
(
currsize
,
2
)
def
test_lru_reentrancy_with_len
(
self
):
# Test to make sure the LRU cache code isn't thrown-off by
# caching the built-in len() function. Since len() can be
# cached, we shouldn't use it inside the lru code itself.
old_len
=
builtins
.
len
try
:
builtins
.
len
=
self
.
module
.
lru_cache
(
4
)(
len
)
for
i
in
[
0
,
0
,
1
,
2
,
3
,
3
,
4
,
5
,
6
,
1
,
7
,
2
,
1
]:
self
.
assertEqual
(
len
(
'abcdefghijklmn'
[:
i
]),
i
)
finally
:
builtins
.
len
=
old_len
def
test_lru_type_error
(
self
):
# Regression test for issue #28653.
# lru_cache was leaking when one of the arguments
...
...
Misc/NEWS
Dosyayı görüntüle @
af56e0e7
...
...
@@ -13,6 +13,9 @@ Core and Builtins
- Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
- Issue #28991: functools.lru_cache() was susceptible to an obscure reentrancy
bug caused by a monkey-patched len() function.
- Issue #28648: Fixed crash in Py_DecodeLocale() in debug build on Mac OS X
when decode astral characters. Patch by Xiang Zhang.
...
...
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