MCPcopy Index your code
hub / github.com/python/cpython / _unpack_opargs

Function _unpack_opargs

Lib/dis.py:940–969  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

938_INT_OVERFLOW = 2 ** (_INT_BITS - 1)
939
940def _unpack_opargs(code):
941 extended_arg = 0
942 extended_args_offset = 0 # Number of EXTENDED_ARG instructions preceding the current instruction
943 caches = 0
944 for i in range(0, len(code), 2):
945 # Skip inline CACHE entries:
946 if caches:
947 caches -= 1
948 continue
949 op = code[i]
950 deop = _deoptop(op)
951 caches = _get_cache_size(_all_opname[deop])
952 if deop in hasarg:
953 arg = code[i+1] | extended_arg
954 extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
955 # The oparg is stored as a signed integer
956 # If the value exceeds its upper limit, it will overflow and wrap
957 # to a negative integer
958 if extended_arg >= _INT_OVERFLOW:
959 extended_arg -= 2 * _INT_OVERFLOW
960 else:
961 arg = None
962 extended_arg = 0
963 if deop == EXTENDED_ARG:
964 extended_args_offset += 1
965 yield (i, i, op, arg)
966 else:
967 start_offset = i - extended_args_offset*2
968 yield (i, start_offset, op, arg)
969 extended_args_offset = 0
970
971def findlabels(code):
972 """Detect all offsets in a byte code which are jump targets.

Callers 4

_get_instructions_bytesFunction · 0.85
findlabelsFunction · 0.85
_find_importsFunction · 0.85
_find_store_namesFunction · 0.85

Calls 2

_deoptopFunction · 0.85
_get_cache_sizeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…