@@ -1511,11 +1511,9 @@ initialize_tools(PyCodeObject *code)
15111511}
15121512
15131513static void
1514- initialize_lines (PyCodeObject * code , int bytes_per_entry )
1514+ initialize_lines (_PyCoLineInstrumentationData * line_data , PyCodeObject * code , int bytes_per_entry )
15151515{
15161516 ASSERT_WORLD_STOPPED_OR_LOCKED (code );
1517- _PyCoLineInstrumentationData * line_data = code -> _co_monitoring -> lines ;
1518-
15191517 assert (line_data != NULL );
15201518 line_data -> bytes_per_entry = bytes_per_entry ;
15211519 int code_len = (int )Py_SIZE (code );
@@ -1635,6 +1633,7 @@ initialize_lines(PyCodeObject *code, int bytes_per_entry)
16351633 set_original_opcode (line_data , handler , original_opcode );
16361634 }
16371635 }
1636+ FT_ATOMIC_STORE_PTR_RELEASE (code -> _co_monitoring -> lines , line_data );
16381637}
16391638
16401639static void
@@ -1656,18 +1655,19 @@ allocate_instrumentation_data(PyCodeObject *code)
16561655 ASSERT_WORLD_STOPPED_OR_LOCKED (code );
16571656
16581657 if (code -> _co_monitoring == NULL ) {
1659- code -> _co_monitoring = PyMem_Malloc (sizeof (_PyCoMonitoringData ));
1660- if (code -> _co_monitoring == NULL ) {
1658+ _PyCoMonitoringData * monitoring = PyMem_Malloc (sizeof (_PyCoMonitoringData ));
1659+ if (monitoring == NULL ) {
16611660 PyErr_NoMemory ();
16621661 return -1 ;
16631662 }
1664- code -> _co_monitoring -> local_monitors = (_Py_LocalMonitors ){ 0 };
1665- code -> _co_monitoring -> active_monitors = (_Py_LocalMonitors ){ 0 };
1666- code -> _co_monitoring -> tools = NULL ;
1667- code -> _co_monitoring -> lines = NULL ;
1668- code -> _co_monitoring -> line_tools = NULL ;
1669- code -> _co_monitoring -> per_instruction_opcodes = NULL ;
1670- code -> _co_monitoring -> per_instruction_tools = NULL ;
1663+ monitoring -> local_monitors = (_Py_LocalMonitors ){ 0 };
1664+ monitoring -> active_monitors = (_Py_LocalMonitors ){ 0 };
1665+ monitoring -> tools = NULL ;
1666+ monitoring -> lines = NULL ;
1667+ monitoring -> line_tools = NULL ;
1668+ monitoring -> per_instruction_opcodes = NULL ;
1669+ monitoring -> per_instruction_tools = NULL ;
1670+ FT_ATOMIC_STORE_PTR_RELEASE (code -> _co_monitoring , monitoring );
16711671 }
16721672 return 0 ;
16731673}
@@ -1732,12 +1732,12 @@ update_instrumentation_data(PyCodeObject *code, PyInterpreterState *interp)
17321732 else {
17331733 bytes_per_entry = 5 ;
17341734 }
1735- code -> _co_monitoring -> lines = PyMem_Malloc (1 + code_len * bytes_per_entry );
1736- if (code -> _co_monitoring -> lines == NULL ) {
1735+ _PyCoLineInstrumentationData * lines = PyMem_Malloc (1 + code_len * bytes_per_entry );
1736+ if (lines == NULL ) {
17371737 PyErr_NoMemory ();
17381738 return -1 ;
17391739 }
1740- initialize_lines (code , bytes_per_entry );
1740+ initialize_lines (lines , code , bytes_per_entry );
17411741 }
17421742 if (multitools && code -> _co_monitoring -> line_tools == NULL ) {
17431743 code -> _co_monitoring -> line_tools = PyMem_Malloc (code_len );
0 commit comments