mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-25 10:23:05 +00:00
acbf14d10c
Most of drgn.dwarf is not performance-sensitive, and the part that is (DwarfIndex) can use some extra tuning which is easier to do in C rather than Cython.
35 lines
1.0 KiB
Python
Executable File
35 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
SIZES = [8, 16, 32, 64]
|
|
|
|
|
|
def generate_read(name, read_type, ret_type=None):
|
|
if ret_type is None:
|
|
ret_type = read_type
|
|
|
|
print(f"""cdef inline int read_{name}(const char *buffer, Py_ssize_t buffer_size, Py_ssize_t *offset, {ret_type} *ret) except -1:
|
|
if not in_bounds(buffer_size, offset[0], sizeof({read_type})):
|
|
raise EOFError()
|
|
ret[0] = (<const {read_type} *>(buffer + offset[0]))[0]
|
|
offset[0] += sizeof({read_type})
|
|
return 0""")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
first = True
|
|
for size in SIZES:
|
|
if first:
|
|
print('# Automatically generated by generate_readwrite.py')
|
|
else:
|
|
print()
|
|
print()
|
|
first = False
|
|
generate_read(f'u{size}', f'uint{size}_t')
|
|
if size < 64:
|
|
print()
|
|
print()
|
|
generate_read(f'u{size}_into_u64', f'uint{size}_t', f'uint64_t')
|
|
print()
|
|
print()
|
|
generate_read(f'u{size}_into_ssize_t', f'uint{size}_t', f'Py_ssize_t')
|