("s1", uctypes.UINT16),
    ("s2", uctypes.UINT8),
    ("arr", (uctypes.ARRAY, uctypes.UINT16 | 2)),
    ("s3", uctypes.UINT8),
    ("sub", (0, o((
        ("b0", uctypes.UINT8),
        ("b1", uctypes.UINT8),
    )))),
    ("arr2", (uctypes.ARRAY, 2, {
        "fi": uctypes.UINT32
    })),
    ("bitf0", uctypes.BFUINT16 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN),
    ("bitf1", uctypes.BFUINT16 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN),
))

offset_less1 = [(x[0] if isinstance(x, tuple) else x) & ~OFFSET_MASK
                for x in desc.values()]

sizeof = uctypes.calc_offsets(desc, uctypes.LITTLE_ENDIAN)

print(sizeof)

offsets = [(x[0] if isinstance(x, tuple) else x) & OFFSET_MASK
           for x in desc.values()]
print(offsets)

# Nothing except offsets should have changed
offset_less2 = [(x[0] if isinstance(x, tuple) else x) & ~OFFSET_MASK
                for x in desc.values()]
print(offset_less1 == offset_less2)
Beispiel #2
0
FLAG_VARARGS = 0x04
FLAG_DEFKWARGS = 0x08

mp_raw_code_t_layout = OrderedDict({
    "kind":
    uctypes.BFUINT32 | 0 << uctypes.BF_POS | 3 << uctypes.BF_LEN,
    "scope_flags":
    uctypes.BFUINT32 | 3 << uctypes.BF_POS | 7 << uctypes.BF_LEN
    | uctypes.PREV_OFFSET,
    "n_pos_args":
    uctypes.BFUINT32 | 10 << uctypes.BF_POS | 11 << uctypes.BF_LEN
    | uctypes.PREV_OFFSET,
    "fun_data": (uctypes.PTR, uctypes.VOID),
    "const_table": (uctypes.PTR, uctypes.VOID),
})
uctypes.calc_offsets(mp_raw_code_t_layout)


def str2qstr(s):
    return id(sys.intern(s)) >> 3


class CodeType:
    def __init__(self):
        self.co_name = "??"
        self.co_filename = "??"
        self.co_firstlineno = 0
        self.co_lnotab = b'\x00'
        self.co_cellvars = ()
        self.mpy_cellvars = ()
        self.co_consts = ()
av_packet_alloc = _avcodec.func("P", "av_packet_alloc", "")
avcodec_find_decoder = _avcodec.func("P", "avcodec_find_decoder", "i")
av_parser_init = _avcodec.func("P", "av_parser_init", "i")
avcodec_alloc_context3 = _avcodec.func("P", "avcodec_alloc_context3", "P")
avcodec_open2 = _avcodec.func("i", "avcodec_open2", "PPP")
av_frame_alloc = _avcodec.func("P", "av_frame_alloc", "")

AVPacket_layout = OrderedDict({
    "buf": (uctypes.PTR, uctypes.VOID),
    "pts": uctypes.INT64,
    "dts": uctypes.INT64,
    "data": (uctypes.PTR, uctypes.UINT8),
    "size": uctypes.INT32,
    # There're more, but for now we don't care
})
uctypes.calc_offsets(AVPacket_layout)
print(AVPacket_layout)

print("sizeof(AVPacket_layout) =", uctypes.sizeof(AVPacket_layout))

AV_NUM_DATA_POINTERS = 8

AVFrame_layout = OrderedDict({
    "data":
    (uctypes.ARRAY, AV_NUM_DATA_POINTERS, (uctypes.PTR, uctypes.UINT8)),
    "linesize": (uctypes.ARRAY, AV_NUM_DATA_POINTERS | uctypes.INT32),
    "extended_data": (uctypes.PTR, uctypes.VOID),
    "width":
    uctypes.INT32,
    "height":
    uctypes.INT32,