|
3 | 3 |
|
4 | 4 | #include "Python.h" |
5 | 5 | #include "pycore_ceval.h" |
6 | | -#include "pycore_code.h" // stats |
| 6 | +#include "pycore_code.h" // stats |
| 7 | +#include "pycore_dtoa.h" // _dtoa_state_INIT() |
7 | 8 | #include "pycore_frame.h" |
8 | 9 | #include "pycore_initconfig.h" |
9 | 10 | #include "pycore_object.h" // _PyType_InitCache() |
@@ -618,6 +619,18 @@ free_interpreter(PyInterpreterState *interp) |
618 | 619 | e.g. by PyMem_RawCalloc() or memset(), or otherwise pre-initialized. |
619 | 620 | The runtime state is not manipulated. Instead it is assumed that |
620 | 621 | the interpreter is getting added to the runtime. |
| 622 | +
|
| 623 | + Note that the main interpreter was statically initialized as part |
| 624 | + of the runtime and most state is already set properly. That leaves |
| 625 | + a small number of fields to initialize dynamically, as well as some |
| 626 | + that are initialized lazily. |
| 627 | +
|
| 628 | + For subinterpreters we memcpy() the main interpreter in |
| 629 | + PyInterpreterState_New(), leaving it in the same mostly-initialized |
| 630 | + state. The only difference is that the interpreter has some |
| 631 | + self-referential state that is statically initializexd to the |
| 632 | + main interpreter. We fix those fields here, in addition |
| 633 | + to the other dynamically initialized fields. |
621 | 634 | */ |
622 | 635 |
|
623 | 636 | static void |
@@ -645,6 +658,11 @@ init_interpreter(PyInterpreterState *interp, |
645 | 658 | PyConfig_InitPythonConfig(&interp->config); |
646 | 659 | _PyType_InitCache(interp); |
647 | 660 |
|
| 661 | + if (interp != &runtime->_main_interpreter) { |
| 662 | + /* Fix the self-referential, statically initialized fields. */ |
| 663 | + interp->dtoa = (struct _dtoa_state)_dtoa_state_INIT(interp); |
| 664 | + } |
| 665 | + |
648 | 666 | interp->_initialized = 1; |
649 | 667 | } |
650 | 668 |
|
|
0 commit comments