Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Sep 1, 2023
commit a01354d37956d922d7552f1b30b126a387e35293
15 changes: 14 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,20 @@ clear_executors(PyCodeObject *co)
co->co_executors = NULL;
}

void _PyCode_Clear_Executors(PyCodeObject *code) {
void
_PyCode_Clear_Executors(PyCodeObject *code) {
int code_len = (int)Py_SIZE(code);
for (int i = 0; i < code_len; i+= _PyInstruction_GetLength(code, i)) {
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
uint8_t opcode = instr->op.code;
uint8_t oparg = instr->op.arg;
if (opcode == ENTER_EXECUTOR) {
_PyExecutorObject *exec = code->co_executors->executors[oparg];
assert(exec->vm_data.opcode != ENTER_EXECUTOR);
instr->op.code = exec->vm_data.opcode;
instr->op.arg = exec->vm_data.oparg;
}
}
clear_executors(code);
Comment thread
gvanrossum marked this conversation as resolved.
}

Expand Down
15 changes: 2 additions & 13 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,19 +1550,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
);
return 0;
}
int code_len = (int)Py_SIZE(code);
if (code->co_executors != NULL && code->co_executors->size > 0 ) {
for (int i = 0; i < code_len; i += _PyInstruction_GetLength(code, i)) {
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
uint8_t opcode = instr->op.code;
uint8_t oparg = instr->op.arg;
if (opcode == ENTER_EXECUTOR) {
_PyExecutorObject *exec = code->co_executors->executors[oparg];
assert(exec->vm_data.opcode != ENTER_EXECUTOR);
instr->op.code = exec->vm_data.opcode;
instr->op.arg = exec->vm_data.oparg;
}
}
if (code->co_executors != NULL) {
_PyCode_Clear_Executors(code);
Comment thread
gvanrossum marked this conversation as resolved.
}
if (update_instrumentation_data(code, interp)) {
Expand Down Expand Up @@ -1593,6 +1581,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
return 0;
}
/* Insert instrumentation */
int code_len = (int)Py_SIZE(code);
for (int i = code->_co_firsttraceable; i < code_len; i+= _PyInstruction_GetLength(code, i)) {
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
CHECK(instr->op.code != 0);
Expand Down