Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf2ad55

Browse files
Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names could cause undefined behavior.
2 parents 5285545 + 3c317e7 commit cf2ad55

7 files changed

Lines changed: 119 additions & 105 deletions

File tree

Lib/importlib/_bootstrap_external.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def _write_atomic(path, data, mode=0o666):
223223
# Python 3.5b1 3330 (PEP 448: Additional Unpacking Generalizations)
224224
# Python 3.5b2 3340 (fix dictionary display evaluation order #11205)
225225
# Python 3.5b2 3350 (add GET_YIELD_FROM_ITER opcode #24400)
226+
# Python 3.5.2 3351 (fix BUILD_MAP_UNPACK_WITH_CALL opcode #27286)
226227
# Python 3.6a0 3360 (add FORMAT_VALUE opcode #25483
227228
# Python 3.6a0 3361 (lineno delta of code.co_lnotab becomes signed)
228229
# Python 3.6a0 3370 (16 bit wordcode)

Lib/test/test_extcall.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
Traceback (most recent call last):
5858
...
5959
TypeError: f() got multiple values for keyword argument 'a'
60+
>>> f(1, 2, a=3, **{'a': 4}, **{'a': 5})
61+
Traceback (most recent call last):
62+
...
63+
TypeError: f() got multiple values for keyword argument 'a'
6064
>>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7})
6165
(1, 2, 3, 4, 5) {'a': 6, 'b': 7}
6266
>>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9})

Lib/test/test_unpack_ex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@
248248
...
249249
TypeError: f() got multiple values for keyword argument 'x'
250250
251+
>>> f(x=5, **{'x': 3}, **{'x': 2})
252+
Traceback (most recent call last):
253+
...
254+
TypeError: f() got multiple values for keyword argument 'x'
255+
251256
>>> f(**{1: 3}, **{1: 5})
252257
Traceback (most recent call last):
253258
...

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.6.0 alpha 2
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
14+
function with generalized unpacking (PEP 448) and conflicting keyword names
15+
could cause undefined behavior.
16+
1317
- Issue #27140: Added BUILD_CONST_KEY_MAP opcode.
1418

1519
- Issue #27186: Add support for os.PathLike objects to open() (part of PEP 519).

PC/launcher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ static PYC_MAGIC magic_values[] = {
10881088
{ 3160, 3180, L"3.2" },
10891089
{ 3190, 3230, L"3.3" },
10901090
{ 3250, 3310, L"3.4" },
1091-
{ 3320, 3350, L"3.5" },
1091+
{ 3320, 3351, L"3.5" },
10921092
{ 3360, 3371, L"3.6" },
10931093
{ 0 }
10941094
};

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3487,7 +3487,7 @@ compiler_call_helper(struct compiler *c,
34873487
code |= 2;
34883488
if (nsubkwargs > 1) {
34893489
/* Pack it all up */
3490-
int function_pos = n + (code & 1) + nkw + 1;
3490+
int function_pos = n + (code & 1) + 2 * nkw + 1;
34913491
ADDOP_I(c, BUILD_MAP_UNPACK_WITH_CALL, nsubkwargs | (function_pos << 8));
34923492
}
34933493
}

Python/importlib_external.h

Lines changed: 103 additions & 103 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)