summaryrefslogtreecommitdiff
path: root/lib9p/core_gen/c_marshal.py
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-21 17:30:52 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-21 17:30:52 -0600
commitef3adc0d857cc0df7579ee66b7d25172ca8af2e1 (patch)
tree8028357729649fcf8678c69b63342aa13c34e635 /lib9p/core_gen/c_marshal.py
parent59e1fc370371c8da876d6c2ce68794bb7f89e525 (diff)
parent1a55efa8be3769d9e31724be31db8f967813133d (diff)
Merge branch 'lukeshu/9p-misc'HEADmain
Diffstat (limited to 'lib9p/core_gen/c_marshal.py')
-rw-r--r--lib9p/core_gen/c_marshal.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib9p/core_gen/c_marshal.py b/lib9p/core_gen/c_marshal.py
index 620bdea..322e1ef 100644
--- a/lib9p/core_gen/c_marshal.py
+++ b/lib9p/core_gen/c_marshal.py
@@ -370,21 +370,21 @@ def gen_c_marshal(versions: set[str], typs: list[idl.UserType]) -> str:
# Pass 1 - check size
max_size = max(typ.max_size(v) for v in typ.in_versions)
+ szbits = 32
if max_size > cutil.UINT32_MAX: # SPECIAL (9P2000.e)
- ret += get_offset_expr(typ, go_to_end).gen_c(
- "uint64_t", "needed_size", "val->", 1, 0
- )
+ szbits = 64
+ ret += get_offset_expr(typ, go_to_end).gen_c(
+ f"uint{szbits}_t", "needed_size", "val->", 1, 0
+ )
+ if szbits > 32: # SPECIAL (9P2000.e)
ret += "\tif (needed_size > (uint64_t)(ctx->max_msg_size)) {\n"
else:
- ret += get_offset_expr(typ, go_to_end).gen_c(
- "uint32_t", "needed_size", "val->", 1, 0
- )
ret += "\tif (needed_size > ctx->max_msg_size) {\n"
if isinstance(typ, idl.Message): # SPECIAL (disable for stat)
- ret += f'\t\tlib9p_errorf(ctx, {c9util.IDENT("ERRNO_L_ERANGE")}, "%s message too large to marshal into %s limit (limit=%"PRIu32")",\n'
+ ret += f'\t\tlib9p_errorf(ctx, {c9util.IDENT("ERRNO_L_ERANGE")}, "%s message too large to marshal into %s limit (%"PRIu{szbits}" > %"PRIu32")",\n'
ret += f'\t\t\t"{typ.typname}",\n'
ret += f'\t\t\tctx->version ? "negotiated" : "{'client' if typ.msgid % 2 == 0 else 'server'}",\n'
- ret += "\t\t\tctx->max_msg_size);\n"
+ ret += "\t\t\tneeded_size, ctx->max_msg_size);\n"
ret += "\t\treturn true;\n"
ret += "\t}\n"