Skip to content

Commit

Permalink
In Python 3.11 LOAD_GLOBAL can push a NULL onto the stack (GH-31933)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanor authored and kozlovsky committed Sep 5, 2023
1 parent 4e29a1a commit b544637
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pony/orm/decompiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(decompiler, code, start=0, end=None):
throw(DecompileError, 'Compiled code should represent a single expression')
def get_instructions(decompiler):
PY36 = sys.version_info >= (3, 6)
PY311 = sys.version_info >= (3, 11)
before_yield = True
code = decompiler.code
co_code = code.co_code
Expand Down Expand Up @@ -194,7 +195,14 @@ def get_instructions(decompiler):
if op in hasconst:
arg = [code.co_consts[oparg]]
elif op in hasname:
arg = [code.co_names[oparg]]
if opname == 'LOAD_GLOBAL':
push_null = False
if PY311:
push_null = oparg & 1
oparg >>= 1
arg = [code.co_names[oparg], push_null]
else:
arg = [code.co_names[oparg]]
elif op in hasjrel:
arg = [i + oparg * (2 if PY310 else 1)
* (-1 if 'BACKWARD' in opname else 1)]
Expand Down Expand Up @@ -666,7 +674,9 @@ def LOAD_FAST(decompiler, varname):
decompiler.names.add(varname)
return ast.Name(varname, ast.Load())

def LOAD_GLOBAL(decompiler, varname):
def LOAD_GLOBAL(decompiler, varname, push_null):
if push_null:
decompiler.stack.append(None)
decompiler.names.add(varname)
return ast.Name(varname, ast.Load())

Expand Down

0 comments on commit b544637

Please sign in to comment.