[issue45860] UnboundLocalError leads to Illegal instruction crashing CPython

2022-01-23 Thread Xinmeng Xia


Xinmeng Xia  added the comment:

A simpler example to reproduce it:
test.py

import threading
import ctypes
from test import test_code

def test_free_different_thread():
f = test_code.CoExtra().get_func()

class ThreadTest(threading.Thread):
def __init__(CoExtra, f, test):
f.test = f

test_code.SetExtra(f.__code__, test_code.FREE_INDEX, ctypes.c_voidp(500))
tt = ThreadTest(f, f)
test_code.CoExtra().assertEqual(test_code.LAST_FREED, 500)

test_free_different_thread()


Just run test.py on Ubuntu 18.04 and you can observe the crash.
version of Python: Python3.11.0a4

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45860] UnboundLocalError leads to Illegal instruction crashing CPython

2021-11-26 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +lukasz.langa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45860] UnboundLocalError leads to Illegal instruction crashing CPython

2021-11-21 Thread Xinmeng Xia


New submission from Xinmeng Xia :

The following code can lead to a crash and report Illegal instruction (core 
dumped)(few times) or Trace/breakpoint trap (core dumped) (very few times) or 
Segmentation fault (core dumped) (most times) on Python 3.11. 

test_free_different_thread.py

import inspect
import sys
import threading
import unittest
import weakref
import ctypes
from test.support import run_doctest, run_unittest, cpython_only, 
check_impl_detail
import _testcapi
from types import FunctionType
from test import test_code
import test_code

def test_free_different_thread():
f = CoExtra.get_func()

class ThreadTest(threading.Thread):

def __init__(CoExtra, f, test):
super().__init__()
CoExtra.f = CoExtra
CoExtra.test = test

def run(CoExtra):
del CoExtra.f
CoExtra.test.assertEqual(test_code.LAST_FREED, 500)
test_code.SetExtra(f.__code__, test_code.FREE_INDEX, ctypes.c_voidp(500))
f = ThreadTest(CoExtra, f)
del tt
tt.start()
tt.join()
CoExtra.assertEqual(test_code.LAST_FREED, 500)

CoExtra = test_code.CoExtra()
test_free_different_thread()
=

-
Traceback (most recent call last):
  File "/home/xxm/Desktop/test_free_different_thread.py", line 33, in 
test_free_different_thread()

  File "/home/xxm/Desktop/test_free_different_thread.py", line 28, in 
test_free_different_thread
del tt
^^
UnboundLocalError: cannot access local variable 'tt' where it is not associated 
with a value
Illegal instruction (core dumped)/Trace/breakpoint trap (core 
dumped)/Segmentation fault (core dumped)


Version: python 3.9, python 3.10, python 3.11 on ubuntu 16.04

Reproduce step:
1.download test_code.py and place test_free_different_thread.py and test_code 
in a same directory.
2. run with "python test_free_different_thread.py"

The test_code.py is from cpython' test. We can also annotate "import test_code" 
and run test_free_different_thread.py directly. But it seems that Illegal 
instruction and Trace/breakpoint trap cannot be reproduced.

--
components: Interpreter Core
files: test_code.py
messages: 406740
nosy: xxm
priority: normal
severity: normal
status: open
title: UnboundLocalError leads to Illegal instruction crashing CPython
type: crash
versions: Python 3.11
Added file: https://bugs.python.org/file50455/test_code.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com