[New-bugs-announce] [issue42882] Restarting the interpreter causes UB on 3.10.0a4

Yannick Jadoul report at bugs.python.org
Sun Jan 10 08:00:18 EST 2021


New submission from Yannick Jadoul <yannick.jadoul at gmail.com>:

Issue detected in the embedding tests of pybind11, running on the latest alpha of 3.10: https://github.com/pybind/pybind11/issues/2774

I have reduced the weird issue/crash to a minimal reproducer, which consistently reproduces the crash on my Linux machine:

```
#include <Python.h>

int main() {
    Py_InitializeEx(1);

    Py_Finalize();
    Py_InitializeEx(1);

    PyRun_SimpleString("class Widget: pass\n"
                       "class DerivedWidget(Widget):\n"
                       "    def __init__(self):\n"
                       "        super().__init__()\n");

    Py_Finalize();

    printf("Works\n");

    return 0;
}
```

Removing the two lines in the middle that restart the interpreter makes the example work.

I've also bisected CPython to find the issue (3.10.0a3 is fine, 3.10.0a4 is not), and arrived at https://github.com/python/cpython/pull/20058 (ba3d67c2fb04a7842741b1b6da5d67f22c579f33 being the first commit that breaks the example above). But I am not entirely sure where to start debugging.

The reproducing example above consistently crashes on my local machine (SIGABRT, exit code 134):

```
Fatal Python error: compiler_make_closure: lookup '__class__' in DerivedWidget 5 -1
freevars of __init__: ('__class__',)

Python runtime state: initialized

Current thread 0x00007f036485b680 (most recent call first):
<no Python frame>
Aborted (core dumped)
```

But note that in the pybind11 tests, the underlying issue causes a different error (Python throwing a weird, seemingly unrelated exception). So something seems to be messed up in the interpreter internals, and the above example just triggers it.

----------
components: Interpreter Core
messages: 384761
nosy: YannickJadoul
priority: normal
severity: normal
status: open
title: Restarting the interpreter causes UB on 3.10.0a4
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42882>
_______________________________________


More information about the New-bugs-announce mailing list