2018-03-10 20:40:15 +00:00
|
|
|
#!/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
|
|
|
|
|
2018-03-25 10:10:15 +01:00
|
|
|
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()
|
2018-03-15 07:49:12 +00:00
|
|
|
ret[0] = (<const {read_type} *>(buffer + offset[0]))[0]
|
2018-03-10 20:40:15 +00:00
|
|
|
offset[0] += sizeof({read_type})
|
|
|
|
return 0""")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-03-25 10:10:15 +01:00
|
|
|
first = True
|
2018-03-10 20:40:15 +00:00
|
|
|
for size in SIZES:
|
2018-03-25 10:10:15 +01:00
|
|
|
if first:
|
|
|
|
print('# Automatically generated by generate_readwrite.py')
|
|
|
|
else:
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
first = False
|
2018-03-10 20:40:15 +00:00
|
|
|
generate_read(f'u{size}', f'uint{size}_t')
|
|
|
|
if size < 64:
|
2018-03-25 10:10:15 +01:00
|
|
|
print()
|
|
|
|
print()
|
2018-03-10 20:40:15 +00:00
|
|
|
generate_read(f'u{size}_into_u64', f'uint{size}_t', f'uint64_t')
|
2018-03-25 10:10:15 +01:00
|
|
|
print()
|
|
|
|
print()
|
2018-03-10 20:40:15 +00:00
|
|
|
generate_read(f'u{size}_into_ssize_t', f'uint{size}_t', f'Py_ssize_t')
|