@@ -1285,13 +1285,10 @@ _Py_call_instrumentation_exc2(
12851285}
12861286
12871287int
1288- _Py_Instrumentation_GetLine (PyCodeObject * code , int index )
1288+ _Py_Instrumentation_GetLine (PyCodeObject * code , _PyCoLineInstrumentationData * line_data , int index )
12891289{
1290- _PyCoMonitoringData * monitoring = code -> _co_monitoring ;
1291- assert (monitoring != NULL );
1292- assert (monitoring -> lines != NULL );
1290+ assert (line_data != NULL );
12931291 assert (index < Py_SIZE (code ));
1294- _PyCoLineInstrumentationData * line_data = monitoring -> lines ;
12951292 int line_delta = get_line_delta (line_data , index );
12961293 int line = compute_line (code , line_delta );
12971294 return line ;
@@ -1309,11 +1306,11 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
13091306 _PyCoMonitoringData * monitoring = code -> _co_monitoring ;
13101307 _PyCoLineInstrumentationData * line_data = monitoring -> lines ;
13111308 PyInterpreterState * interp = tstate -> interp ;
1312- int line = _Py_Instrumentation_GetLine (code , i );
1309+ int line = _Py_Instrumentation_GetLine (code , line_data , i );
13131310 assert (line >= 0 );
13141311 assert (prev != NULL );
13151312 int prev_index = (int )(prev - bytecode );
1316- int prev_line = _Py_Instrumentation_GetLine (code , prev_index );
1313+ int prev_line = _Py_Instrumentation_GetLine (code , line_data , prev_index );
13171314 if (prev_line == line ) {
13181315 int prev_opcode = bytecode [prev_index ].op .code ;
13191316 /* RESUME and INSTRUMENTED_RESUME are needed for the operation of
@@ -1510,11 +1507,9 @@ initialize_tools(PyCodeObject *code)
15101507}
15111508
15121509static void
1513- initialize_lines (PyCodeObject * code , int bytes_per_entry )
1510+ initialize_lines (_PyCoLineInstrumentationData * line_data , PyCodeObject * code , int bytes_per_entry )
15141511{
15151512 ASSERT_WORLD_STOPPED_OR_LOCKED (code );
1516- _PyCoLineInstrumentationData * line_data = code -> _co_monitoring -> lines ;
1517-
15181513 assert (line_data != NULL );
15191514 line_data -> bytes_per_entry = bytes_per_entry ;
15201515 int code_len = (int )Py_SIZE (code );
@@ -1655,18 +1650,19 @@ allocate_instrumentation_data(PyCodeObject *code)
16551650 ASSERT_WORLD_STOPPED_OR_LOCKED (code );
16561651
16571652 if (code -> _co_monitoring == NULL ) {
1658- code -> _co_monitoring = PyMem_Malloc (sizeof (_PyCoMonitoringData ));
1659- if (code -> _co_monitoring == NULL ) {
1653+ _PyCoMonitoringData * monitoring = PyMem_Malloc (sizeof (_PyCoMonitoringData ));
1654+ if (monitoring == NULL ) {
16601655 PyErr_NoMemory ();
16611656 return -1 ;
16621657 }
1663- code -> _co_monitoring -> local_monitors = (_Py_LocalMonitors ){ 0 };
1664- code -> _co_monitoring -> active_monitors = (_Py_LocalMonitors ){ 0 };
1665- code -> _co_monitoring -> tools = NULL ;
1666- code -> _co_monitoring -> lines = NULL ;
1667- code -> _co_monitoring -> line_tools = NULL ;
1668- code -> _co_monitoring -> per_instruction_opcodes = NULL ;
1669- code -> _co_monitoring -> per_instruction_tools = NULL ;
1658+ monitoring -> local_monitors = (_Py_LocalMonitors ){ 0 };
1659+ monitoring -> active_monitors = (_Py_LocalMonitors ){ 0 };
1660+ monitoring -> tools = NULL ;
1661+ monitoring -> lines = NULL ;
1662+ monitoring -> line_tools = NULL ;
1663+ monitoring -> per_instruction_opcodes = NULL ;
1664+ monitoring -> per_instruction_tools = NULL ;
1665+ _Py_atomic_store_ptr_release (& code -> _co_monitoring , monitoring );
16701666 }
16711667 return 0 ;
16721668}
@@ -1731,12 +1727,13 @@ update_instrumentation_data(PyCodeObject *code, PyInterpreterState *interp)
17311727 else {
17321728 bytes_per_entry = 5 ;
17331729 }
1734- code -> _co_monitoring -> lines = PyMem_Malloc (1 + code_len * bytes_per_entry );
1735- if (code -> _co_monitoring -> lines == NULL ) {
1730+ _PyCoLineInstrumentationData * lines = PyMem_Malloc (1 + code_len * bytes_per_entry );
1731+ if (lines == NULL ) {
17361732 PyErr_NoMemory ();
17371733 return -1 ;
17381734 }
1739- initialize_lines (code , bytes_per_entry );
1735+ initialize_lines (lines , code , bytes_per_entry );
1736+ _Py_atomic_store_ptr_release (& code -> _co_monitoring -> lines , lines );
17401737 }
17411738 if (multitools && code -> _co_monitoring -> line_tools == NULL ) {
17421739 code -> _co_monitoring -> line_tools = PyMem_Malloc (code_len );
0 commit comments