Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 19b1147

Browse files
jasonborgcopybara-github
authored andcommitted
Add support for Python 3.8 opcodes.
PiperOrigin-RevId: 282973931 Change-Id: Id021919aa0bc75fc7cb956d582e41ebdf026845d
1 parent a4ee1e5 commit 19b1147

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/googleclouddebugger/bytecode_manipulator.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,27 @@ static PythonOpcodeType GetOpcodeType(uint8 opcode) {
126126

127127
case FOR_ITER:
128128
case JUMP_FORWARD:
129+
#if PY_VERSION_HEX < 0x03080000
130+
// Removed in Python 3.8.
129131
case SETUP_LOOP:
130132
case SETUP_EXCEPT:
133+
#endif
131134
case SETUP_FINALLY:
132135
case SETUP_WITH:
136+
#if PY_VERSION_HEX >= 0x03080000
137+
case CALL_FINALLY:
138+
#endif
133139
return BRANCH_DELTA_OPCODE;
134140

135141
case JUMP_IF_FALSE_OR_POP:
136142
case JUMP_IF_TRUE_OR_POP:
137143
case JUMP_ABSOLUTE:
138144
case POP_JUMP_IF_FALSE:
139145
case POP_JUMP_IF_TRUE:
146+
#if PY_VERSION_HEX < 0x03080000
147+
// Removed in Python 3.8.
140148
case CONTINUE_LOOP:
149+
#endif
141150
return BRANCH_ABSOLUTE_OPCODE;
142151

143152
default:

src/googleclouddebugger/immutability_tracer.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
331331
case INPLACE_AND:
332332
case INPLACE_XOR:
333333
case INPLACE_OR:
334-
case BREAK_LOOP:
335334
case RETURN_VALUE:
336335
case YIELD_VALUE:
337336
case POP_BLOCK:
@@ -351,8 +350,6 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
351350
case POP_JUMP_IF_TRUE:
352351
case POP_JUMP_IF_FALSE:
353352
case LOAD_GLOBAL:
354-
case CONTINUE_LOOP:
355-
case SETUP_LOOP:
356353
case LOAD_FAST:
357354
case STORE_FAST:
358355
case DELETE_FAST:
@@ -362,6 +359,12 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
362359
case LOAD_DEREF:
363360
case CALL_FUNCTION_KW:
364361
case EXTENDED_ARG:
362+
#if PY_VERSION_HEX < 0x03080000
363+
// These were all removed in Python 3.8.
364+
case BREAK_LOOP:
365+
case CONTINUE_LOOP:
366+
case SETUP_LOOP:
367+
#endif
365368
#if PY_MAJOR_VERSION >= 3
366369
case DUP_TOP_TWO:
367370
case BINARY_MATRIX_MULTIPLY:
@@ -385,6 +388,10 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
385388
case LOAD_METHOD:
386389
case CALL_METHOD:
387390
#endif
391+
#if PY_VERSION_HEX >= 0x03080000
392+
// Added back in Python 3.8 (was in 2.7 as well)
393+
case ROT_FOUR:
394+
#endif
388395
#else
389396
case ROT_FOUR:
390397
case DUP_TOPX:
@@ -412,7 +419,6 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
412419
case IMPORT_STAR:
413420
case IMPORT_NAME:
414421
case IMPORT_FROM:
415-
case SETUP_EXCEPT:
416422
case SETUP_FINALLY:
417423
// TODO: allow changing fields of locally created objects/lists.
418424
case STORE_SUBSCR:
@@ -431,6 +437,10 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
431437
case SETUP_WITH:
432438
// TODO: allow closures
433439
case LOAD_CLOSURE:
440+
#if PY_VERSION_HEX < 0x03080000
441+
// Removed in Python 3.8.
442+
case SETUP_EXCEPT:
443+
#endif
434444
#if PY_MAJOR_VERSION >= 3
435445
case GET_AITER:
436446
case GET_ANEXT:
@@ -447,6 +457,13 @@ static OpcodeMutableStatus IsOpcodeMutable(const uint8 opcode) {
447457
#endif
448458
case DELETE_DEREF:
449459
case SETUP_ASYNC_WITH:
460+
#if PY_VERSION_HEX >= 0x03080000
461+
// Added in Python 3.8.
462+
case BEGIN_FINALLY:
463+
case END_ASYNC_FOR:
464+
case CALL_FINALLY:
465+
case POP_FINALLY:
466+
#endif
450467
#else
451468
case STORE_SLICE+0:
452469
case STORE_SLICE+1:

0 commit comments

Comments
 (0)