micropython/py
Damien George 7c1584aef1 py/compile: Fix scope of assignment expression target in comprehensions.
When := is used in a comprehension the target variable is bound to the
parent scope, so it's either a global or a nonlocal.  Prior to this commit
that was handled by simply using the parent scope's id_info for the
target variable.  That's completely wrong because it uses the slot number
for the parent's Python stack to store the variable, rather than the slot
number for the comprehension.  This will in most cases lead to incorrect
behaviour or memory faults.

This commit fixes the scoping of the target variable by explicitly
declaring it a global or nonlocal, depending on whether the parent is the
global scope or not.  Then the id_info of the comprehension can be used to
access the target variable.  This fixes a lot of cases of using := in a
comprehension.

Code size change for this commit:

       bare-arm:    +0 +0.000%
    minimal x86:    +0 +0.000%
       unix x64:  +152 +0.019% standard
          stm32:   +96 +0.024% PYBV10
         cc3200:   +96 +0.052%
        esp8266:  +196 +0.028% GENERIC
          esp32:  +156 +0.010% GENERIC[incl +8(data)]
         mimxrt:   +96 +0.027% TEENSY40
     renesas-ra:   +88 +0.014% RA6M2_EK
            nrf:   +88 +0.048% pca10040
            rp2:  +104 +0.020% PICO
           samd:   +88 +0.033% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Fixes issue #10895.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:13:12 +11:00
..
argcheck.c py: Remove the word "yet" from exception messages. 2022-12-06 13:34:52 +11:00
asmarm.c
asmarm.h
asmbase.c
asmbase.h
asmthumb.c
asmthumb.h
asmx64.c
asmx64.h
asmx86.c
asmx86.h
asmxtensa.c
asmxtensa.h
bc.c py/bc: Fix checking for duplicate **kwargs. 2022-11-28 11:23:22 +11:00
bc.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
bc0.h
binary.c
binary.h
builtin.h
builtinevex.c
builtinhelp.c
builtinimport.c py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
compile.c py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
compile.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
dynruntime.h
dynruntime.mk
emit.h py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitbc.c
emitcommon.c py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitglue.c
emitglue.h
emitinlinethumb.c
emitinlinextensa.c
emitnarm.c
emitnative.c py/emitnative: Explicitly compare comparison ops in binary_op emitter. 2023-02-27 10:25:39 +11:00
emitnthumb.c
emitnx64.c
emitnx86.c
emitnxtensa.c
emitnxtensawin.c
formatfloat.c
formatfloat.h
frozenmod.c
frozenmod.h
gc.c py/gc: Increase the address length in gc_dump_alloc_table(). 2023-01-16 12:09:20 +11:00
gc.h
grammar.h
lexer.c py/lexer: Wrap in parenthesis all f-string arguments passed to format. 2023-01-20 17:54:32 +11:00
lexer.h
make_root_pointers.py
makecompresseddata.py
makemoduledefs.py
makeqstrdata.py top: Update Python formatting to black "2023 stable style". 2023-02-02 12:51:03 +11:00
makeqstrdefs.py
makeversionhdr.py py/makeversionhdr.py: Optionally get git tag and git hash from env vars. 2023-03-02 23:19:30 +11:00
malloc.c
map.c py/map: Clear value when re-using slot with ordered dictionaries. 2023-01-13 14:21:32 +11:00
misc.h py/misc: Remove use of bitfield from vstr_t. 2022-10-12 00:33:09 +11:00
mkenv.mk
mkrules.cmake py/mkrules.cmake: Force build mpversion.h and frozen_content.c. 2023-02-08 12:24:15 +11:00
mkrules.mk
modarray.c
modbuiltins.c
modcmath.c
modcollections.c
modgc.c
modio.c
modmath.c py/modmath: Fix two-argument math function domain check. 2023-02-24 15:55:12 +11:00
modmicropython.c py/modmicropython: Make module optional. 2022-12-06 13:34:17 +11:00
modstruct.c
modsys.c
modthread.c
moduerrno.c
mpconfig.h py/gc: Avoid valgrind false positives. 2022-12-08 14:29:22 +11:00
mperrno.h
mphal.h
mpprint.c
mpprint.h
mpstate.c
mpstate.h
mpthread.h
mpz.c
mpz.h
nativeglue.c
nativeglue.h
nlr.c
nlr.h py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
nlraarch64.c
nlrmips.c py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
nlrpowerpc.c
nlrsetjmp.c
nlrthumb.c
nlrx64.c
nlrx86.c
nlrxtensa.c
obj.c
obj.h py: Add parenthesis to default impl of MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR. 2023-01-20 21:59:49 +11:00
objarray.c py/objarray: Raise error on out-of-bound memoryview slice start. 2023-01-20 16:31:37 +11:00
objarray.h py/objarray: Raise error on out-of-bound memoryview slice start. 2023-01-20 16:31:37 +11:00
objattrtuple.c
objbool.c
objboundmeth.c
objcell.c
objclosure.c
objcomplex.c
objdeque.c
objdict.c py/objdict: Implement dictionary union (PEP 584). 2022-11-25 12:46:14 +11:00
objenumerate.c
objexcept.c
objexcept.h
objfilter.c
objfloat.c
objfun.c
objfun.h
objgenerator.c
objgenerator.h
objgetitemiter.c
objint.c
objint.h
objint_longlong.c
objint_mpz.c py/objint_mpz: Catch and reject @ and @= operating on big integers. 2023-01-23 13:03:51 +11:00
objlist.c
objlist.h
objmap.c
objmodule.c
objmodule.h
objnamedtuple.c
objnamedtuple.h
objnone.c
objobject.c
objpolyiter.c
objproperty.c
objrange.c
objreversed.c
objset.c
objsingleton.c
objslice.c
objstr.c py: Remove the word "yet" from exception messages. 2022-12-06 13:34:52 +11:00
objstr.h
objstringio.c
objstringio.h
objstrunicode.c
objtuple.c
objtuple.h
objtype.c
objtype.h
objzip.c
opmethods.c
pairheap.c
pairheap.h
parse.c
parse.h
parsenum.c
parsenum.h
parsenumbase.c
parsenumbase.h
persistentcode.c py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
persistentcode.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
profile.c
profile.h
py.cmake py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
py.mk py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
pystack.c
pystack.h
qstr.c
qstr.h
qstrdefs.h
reader.c
reader.h
repl.c
repl.h
ringbuf.c
ringbuf.h
runtime.c
runtime.h
runtime0.h
runtime_utils.c
scheduler.c
scope.c
scope.h
sequence.c
showbc.c
smallint.c
smallint.h
stackctrl.c
stackctrl.h
stream.c
stream.h
unicode.c
unicode.h
usermod.cmake
vm.c
vmentrytable.h
vstr.c
warning.c