tonybaloney / Pyjion

Pyjion - A JIT for Python based upon CoreCLR
https://www.trypyjion.com
MIT License
1.42k stars 59 forks source link

Using those freed variables in a class methods crashes pyjion #496

Open xiaxinmeng opened 1 year ago

xiaxinmeng commented 1 year ago

Using an undefined variable in a method of a class may cause a segmentation fault. See the following example 'test.py', we define a class 'A' . In this class we define a method 'clone'. After for loop, we return the undefined variable i, then pyjion crashes.

test.py

class A:
    js = []
    def clone(self):
        for i in self.js:
            pass
        return i
a = A()
a.clone()

Behaviors on Pyjion: python3.10 -m pyjion test.py

Segmentation fault (core dumped)

Behaviors on CPython 3.10.8 python3.10 test.py

Traceback (most recent call last): File "/home/xxm/Desktop/test.py", line 8, in a.clone() File "/home/xxm/Desktop/test.py", line 6, in clone return I UnboundLocalError: local variable 'i' referenced before assignment

Environment: CPython3.10.8 on Ubuntu 18.04