Skip to content

Commit

Permalink
internal/utils: corrected the stack size calculation for the code obj…
Browse files Browse the repository at this point in the history
…ects generated by the `wrap.assemble` functions.
  • Loading branch information
arizvisa committed Aug 22, 2022
1 parent b3bc8d6 commit cd3c2fd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions base/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,24 +1451,24 @@ def assemble_38x(cls, function, wrapper, bound=False):
asm(cls.co_assemble('LOAD_FAST', co_varnames.index(item)))
co_stacksize += 1

# then we can finally pack it into a tuple.
asm(cls.co_assemble('BUILD_TUPLE', 1 + len(Fargs[int(bound):])))
# then we can finally pack it into a tuple
asm(cls.co_assemble('BUILD_TUPLE', 1 + len(Fargs[int(bound):]))) # pack(F, args...)

## now we need to pack all wildcard arguments...
for item in Fvarargs:
asm(cls.co_assemble('LOAD_FAST', co_varnames.index(item)))
co_stacksize = max(1 + len(Fvarargs), co_stacksize)
co_stacksize = max(2 + len(Fvarargs), co_stacksize) # len(varags) + build_tuple + wrapper

# ...into this unpack-with-call tuple.
asm(cls.co_assemble('BUILD_TUPLE_UNPACK_WITH_CALL', 1 + len(Fvarargs)))
asm(cls.co_assemble('BUILD_TUPLE_UNPACK_WITH_CALL', 1 + len(Fvarargs))) # pack(pack(F, args...), varargs)

## now we need to pack all kw arguments...
for item in Fvarkwds:
asm(cls.co_assemble('LOAD_FAST', co_varnames.index(item)))
co_stacksize = max(len(Fvarkwds), co_stacksize)
co_stacksize = max(2 + len(Fvarkwds), co_stacksize) # len(varkwds) + build_tuple_unpack + wrapper

# ...into this unpack-with-call map.
asm(cls.co_assemble('BUILD_MAP_UNPACK_WITH_CALL', len(Fvarkwds)))
asm(cls.co_assemble('BUILD_MAP_UNPACK_WITH_CALL', len(Fvarkwds))) # pack(pack(F, args..., varargs), kwargs)

## finally we have our arguments, and can now assemble our call...
asm(cls.co_assemble('CALL_FUNCTION_EX', 1))
Expand Down Expand Up @@ -1553,13 +1553,13 @@ def assemble_39x(cls, function, wrapper, bound=False):
co_stacksize += 1

# then we can finally pack it into a list
asm(cls.co_assemble('BUILD_LIST', 1 + len(Fargs[int(bound):])))
asm(cls.co_assemble('BUILD_LIST', 1 + len(Fargs[int(bound):]))) # pack(F, args)

## now we need to pack all wildcard arguments...
for item in Fvarargs:
asm(cls.co_assemble('LOAD_FAST', co_varnames.index(item)))
asm(cls.co_assemble('LIST_EXTEND', 1))
co_stacksize = max(1 + len(Fvarargs), co_stacksize)
co_stacksize = max(2 + len(Fvarargs), co_stacksize) # wrapper + pack(F, args) + load_fast(varargs)

# ...and convert it into a tuple
asm(cls.co_assemble('LIST_TO_TUPLE'))
Expand All @@ -1570,7 +1570,7 @@ def assemble_39x(cls, function, wrapper, bound=False):
for item in Fvarkwds:
asm(cls.co_assemble('LOAD_FAST', co_varnames.index(item)))
asm(cls.co_assemble('DICT_MERGE', 1))
co_stacksize = max(len(Fvarkwds), co_stacksize)
co_stacksize = max(2 + len(Fvarkwds), co_stacksize) # wrapper + pack(F, args, varargs) + load_fast(varkwds)

## finally we have our arguments, and can now assemble our call...
asm(cls.co_assemble('CALL_FUNCTION_EX', 1))
Expand Down

0 comments on commit cd3c2fd

Please sign in to comment.