Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit92337f6

Browse files
authored
gh-133703: dict: fix calculate_log2_keysize() (GH-133809)
1 parent878e0fb commit92337f6

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

‎Lib/test/test_dict.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,10 +1039,8 @@ class C:
10391039
a=C()
10401040
a.x=1
10411041
d=a.__dict__
1042-
before_resize=sys.getsizeof(d)
10431042
d[2]=2# split table is resized to a generic combined table
10441043

1045-
self.assertGreater(sys.getsizeof(d),before_resize)
10461044
self.assertEqual(list(d), ['x',2])
10471045

10481046
deftest_iterator_pickling(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix hashtable in dict can be bigger than intended in some situations.

‎Objects/dictobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,13 @@ static inline uint8_t
547547
calculate_log2_keysize(Py_ssize_tminsize)
548548
{
549549
#ifSIZEOF_LONG==SIZEOF_SIZE_T
550-
minsize= (minsize |PyDict_MINSIZE)-1;
551-
return_Py_bit_length(minsize| (PyDict_MINSIZE-1));
550+
minsize=Py_MAX(minsize,PyDict_MINSIZE);
551+
return_Py_bit_length(minsize-1);
552552
#elif defined(_MSC_VER)
553-
// On 64bit Windows, sizeof(long) == 4.
554-
minsize= (minsize |PyDict_MINSIZE)-1;
553+
// On 64bit Windows, sizeof(long) == 4. We cannot use _Py_bit_length.
554+
minsize=Py_MAX(minsize,PyDict_MINSIZE);
555555
unsigned longmsb;
556-
_BitScanReverse64(&msb, (uint64_t)minsize);
556+
_BitScanReverse64(&msb, (uint64_t)minsize-1);
557557
return (uint8_t)(msb+1);
558558
#else
559559
uint8_tlog2_size;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp