From 93f43c15e4719b52a3431d5239849ab27b232a76 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Sat, 26 Aug 2023 10:39:50 +0900 Subject: [PATCH] Address code review --- Python/instrumentation.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 3997131011f2c6..181c944cb16af6 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -571,6 +571,7 @@ de_instrument(PyCodeObject *code, int i, int event) _PyExecutorObject *exec = code->co_executors->executors[oparg]; opcode_ptr = &exec->vm_data.opcode; opcode = *opcode_ptr; + assert(opcode != ENTER_EXECUTOR); } if (opcode == INSTRUMENTED_LINE) { opcode_ptr = &code->_co_monitoring->lines[i].original_opcode; @@ -580,7 +581,6 @@ de_instrument(PyCodeObject *code, int i, int event) opcode_ptr = &code->_co_monitoring->per_instruction_opcodes[i]; opcode = *opcode_ptr; } - assert(opcode != ENTER_EXECUTOR); int deinstrumented = DE_INSTRUMENT[opcode]; if (deinstrumented == 0) { return; @@ -717,22 +717,23 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools) assert(event != PY_MONITORING_EVENT_LINE); assert(event != PY_MONITORING_EVENT_INSTRUCTION); assert(PY_MONITORING_IS_INSTRUMENTED_EVENT(event)); - _Py_CODEUNIT co_instr = _PyCode_CODE(code)[offset]; - uint8_t co_code = co_instr.op.code; - uint8_t co_arg = co_instr.op.arg; - if (co_code == ENTER_EXECUTOR) { - _PyExecutorObject *exec = code->co_executors->executors[co_arg]; - assert(exec != NULL); - assert(exec->vm_data.opcode != ENTER_EXECUTOR); - co_code = _PyOpcode_Deopt[exec->vm_data.opcode]; - co_arg = exec->vm_data.oparg; - } - else { - co_code = _Py_GetBaseOpcode(code, offset); - } - assert(co_code != ENTER_EXECUTOR); - assert(opcode_has_event(co_code)); - _PyCoMonitoringData *monitoring = code->_co_monitoring; + #ifndef NDEBUG + _Py_CODEUNIT co_instr = _PyCode_CODE(code)[offset]; + uint8_t co_code = co_instr.op.code; + uint8_t co_arg = co_instr.op.arg; + if (co_code == ENTER_EXECUTOR) { + _PyExecutorObject *exec = code->co_executors->executors[co_arg]; + assert(exec->vm_data.opcode != ENTER_EXECUTOR); + co_code = _PyOpcode_Deopt[exec->vm_data.opcode]; + co_arg = exec->vm_data.oparg; + } + else { + co_code = _Py_GetBaseOpcode(code, offset); + } + assert(co_code != ENTER_EXECUTOR); + assert(opcode_has_event(co_code)); + _PyCoMonitoringData *monitoring = code->_co_monitoring; + #endif if (monitoring && monitoring->tools) { monitoring->tools[offset] &= ~tools; if (monitoring->tools[offset] == 0) {