Where is the giant cpython switch case statement moved?
Question:
Not sure if it’s off topic but don’t know any better place to ask.
In cpython
there was a very giant switch
case
statement for executing each opcode.
This switch case previously was placed in the _PyEval_EvalFrameDefault
function.
Here is the link. The switch case statement starts here.
This was a core part of cpython and everyone who was interested in cpython internals, would probably explore it in detail. Recently I was searching for it and I couldn’t find it. In this version of _PyEval_EvalFrameDefault
I can’t find it. It’s much shorter than the last one.
I even tried to find this switch statement by searching for opcodes in my IDE. But even that didn’t helped find where it is.
Can anyone who is aware of latest cpython development changes help me?
Thanks in advance.
Answers:
It’s in Python/generated_cases.c.h
, which gets inserted into _PyEval_EvalFrameDefault
with an #include "generated_cases.c.h"
.
As you might guess from the name, generated_cases.c.h
is generated code. You can see the code generator in Tools/cases_generator/generate_cases.py
Not sure if it’s off topic but don’t know any better place to ask.
In cpython
there was a very giant switch
case
statement for executing each opcode.
This switch case previously was placed in the _PyEval_EvalFrameDefault
function.
Here is the link. The switch case statement starts here.
This was a core part of cpython and everyone who was interested in cpython internals, would probably explore it in detail. Recently I was searching for it and I couldn’t find it. In this version of _PyEval_EvalFrameDefault
I can’t find it. It’s much shorter than the last one.
I even tried to find this switch statement by searching for opcodes in my IDE. But even that didn’t helped find where it is.
Can anyone who is aware of latest cpython development changes help me?
Thanks in advance.
It’s in Python/generated_cases.c.h
, which gets inserted into _PyEval_EvalFrameDefault
with an #include "generated_cases.c.h"
.
As you might guess from the name, generated_cases.c.h
is generated code. You can see the code generator in Tools/cases_generator/generate_cases.py