Dennis Sweeney <sweeney.dennis...@gmail.com> added the comment:

I tried some debugging code:

diff --git a/Python/ceval.c b/Python/ceval.c
index f745067069..a8668dbac2 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4864,6 +4864,18 @@ get_exception_handler(PyCodeObject *code, int index)
             return res;
         }
         scan = skip_to_next_entry(scan);
+        if (scan
+            >= (unsigned char *)PyBytes_AS_STRING(code->co_exceptiontable)
+            + PyBytes_GET_SIZE(code->co_exceptiontable))
+        {
+            printf("co_name: --------------------------\n");
+            _PyObject_Dump(code->co_name);
+            printf("co_filename: ----------------------\n");
+            _PyObject_Dump(code->co_filename);
+            printf("co_exceptiontable: -------------\n");
+            _PyObject_Dump(code->co_exceptiontable);
+            printf("\n\n\n\n\n");
+        }
     }
     res.b_handler = -1;
     return res;


It output this:

Python 3.11.0a0 (heads/main-dirty:092f9ddb5e, May  9 2021, 18:45:56) [MSC 
v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from test.test_statistics import *
co_name: --------------------------
object address  : 00000254B63EFB80
object refcount : 7
object type     : 00007FFA1C7E71C0
object type name: str
object repr     : '_find_and_load'
co_filename: ----------------------
object address  : 00000254B63967A0
object refcount : 76
object type     : 00007FFA1C7E71C0
object type name: str
object repr     : '<frozen importlib._bootstrap>'
co_exceptiontable: -------------
object address  : 00000254B63EB290
object refcount : 1
object type     : 00007FFA1C7C9A40
object type name: bytes
object repr     : b'\x84\x10"\x03\xa2\x04&\x0b\xa7\x03&\x0b'


>>> unittest.main()
............................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 364 tests in 24.409s

OK


Here is the disassembly of the offending function:

>>> from dis import dis
>>> from importlib._bootstrap import _find_and_load
>>> dis(_find_and_load)
1024           0 LOAD_GLOBAL              0 (_ModuleLockManager)
               2 LOAD_FAST                0 (name)
               4 CALL_FUNCTION            1
               6 BEFORE_WITH
               8 POP_TOP

1025          10 LOAD_GLOBAL              1 (sys)
              12 LOAD_ATTR                2 (modules)
              14 LOAD_METHOD              3 (get)
              16 LOAD_FAST                0 (name)
              18 LOAD_GLOBAL              4 (_NEEDS_LOADING)
              20 CALL_METHOD              2
              22 STORE_FAST               2 (module)

1026          24 LOAD_FAST                2 (module)
              26 LOAD_GLOBAL              4 (_NEEDS_LOADING)
              28 IS_OP                    0
              30 POP_JUMP_IF_FALSE       27 (to 54)

1027          32 LOAD_GLOBAL              5 (_find_and_load_unlocked)
              34 LOAD_FAST                0 (name)
              36 LOAD_FAST                1 (import_)
              38 CALL_FUNCTION            2

1024          40 ROT_TWO
              42 LOAD_CONST               1 (None)
              44 DUP_TOP
              46 DUP_TOP
              48 CALL_FUNCTION            3
              50 POP_TOP

1027          52 RETURN_VALUE

1026     >>   54 NOP

1024          56 LOAD_CONST               1 (None)
              58 DUP_TOP
              60 DUP_TOP
              62 CALL_FUNCTION            3
              64 POP_TOP
              66 JUMP_FORWARD            11 (to 90)
         >>   68 PUSH_EXC_INFO
              70 WITH_EXCEPT_START
              72 POP_JUMP_IF_TRUE        39 (to 78)
              74 RERAISE                  4
         >>   76 POP_EXCEPT_AND_RERAISE
         >>   78 POP_TOP
              80 POP_TOP
              82 POP_TOP
              84 POP_EXCEPT
              86 POP_TOP
              88 POP_TOP

1029     >>   90 LOAD_FAST                2 (module)
              92 LOAD_CONST               1 (None)
              94 IS_OP                    0
              96 POP_JUMP_IF_FALSE       60 (to 120)

1030          98 LOAD_CONST               2 ('import of {} halted; None in 
sys.modules')

1031         100 LOAD_METHOD              6 (format)
             102 LOAD_FAST                0 (name)
             104 CALL_METHOD              1

1030         106 STORE_FAST               3 (message)

1032         108 LOAD_GLOBAL              7 (ModuleNotFoundError)
             110 LOAD_FAST                3 (message)
             112 LOAD_FAST                0 (name)
             114 LOAD_CONST               3 (('name',))
             116 CALL_FUNCTION_KW         2
             118 RAISE_VARARGS            1

1034     >>  120 LOAD_GLOBAL              8 (_lock_unlock_module)
             122 LOAD_FAST                0 (name)
             124 CALL_FUNCTION            1
             126 POP_TOP

1035         128 LOAD_FAST                2 (module)
             130 RETURN_VALUE
ExceptionTable:
  8 to 38 -> 68 [1] lasti
  68 to 74 -> 76 [5] lasti
  78 to 82 -> 76 [5] lasti


I don't know whether there just needs to be a sentinel 128 appended to all 
co_exceptiontable, or if there is a more subtle bug.

----------
nosy: +Dennis Sweeney

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40222>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to