summaryrefslogtreecommitdiff
path: root/lib9p/idl.gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/idl.gen')
-rwxr-xr-xlib9p/idl.gen41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index 262e5f0..ae7f1a5 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -708,7 +708,7 @@ def gen_c(versions: set[str], typs: list[Type]) -> str:
return arg
def unused(arg: str) -> str:
- return f"UNUSED({arg})"
+ return f"LM_UNUSED({arg})"
# strings ##################################################################
ret += f"""
@@ -724,7 +724,10 @@ static const char *version_strs[{c_ver_enum('NUM')}] = {{
ret += "};\n"
ret += f"""
const char *{idprefix}version_str(enum {idprefix}version ver) {{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
assert(0 <= ver && ver < {c_ver_enum('NUM')});
+#pragma GCC diagnostic pop
return version_strs[ver];
}}
"""
@@ -733,7 +736,7 @@ const char *{idprefix}version_str(enum {idprefix}version ver) {{
ret += """
/* validate_* *****************************************************************/
-ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) {
+LM_ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) {
if (__builtin_add_overflow(ctx->net_offset, n, &ctx->net_offset))
/* If needed-net-size overflowed uint32_t, then
* there's no way that actual-net-size will live up to
@@ -744,7 +747,7 @@ ALWAYS_INLINE static bool _validate_size_net(struct _validate_ctx *ctx, uint32_t
return false;
}
-ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) {
+LM_ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t n) {
if (__builtin_add_overflow(ctx->host_extra, n, &ctx->host_extra))
/* If needed-host-size overflowed size_t, then there's
* no way that actual-net-size will live up to
@@ -753,7 +756,7 @@ ALWAYS_INLINE static bool _validate_size_host(struct _validate_ctx *ctx, size_t
return false;
}
-ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
+LM_ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
size_t cnt,
_validate_fn_t item_fn, size_t item_host_size) {
for (size_t i = 0; i < cnt; i++)
@@ -768,7 +771,7 @@ ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
#define validate_8(ctx) _validate_size_net(ctx, 8)
"""
for typ in typs:
- inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE"
+ inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE"
argfn = unused if (isinstance(typ, Struct) and not typ.members) else used
ret += "\n"
ret += ifdef_push(1, c_ver_ifdef(typ.in_versions))
@@ -900,28 +903,28 @@ ALWAYS_INLINE static bool _validate_list(struct _validate_ctx *ctx,
ret += """
/* unmarshal_* ****************************************************************/
-ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) {
+LM_ALWAYS_INLINE static void unmarshal_1(struct _unmarshal_ctx *ctx, uint8_t *out) {
*out = decode_u8le(&ctx->net_bytes[ctx->net_offset]);
ctx->net_offset += 1;
}
-ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) {
+LM_ALWAYS_INLINE static void unmarshal_2(struct _unmarshal_ctx *ctx, uint16_t *out) {
*out = decode_u16le(&ctx->net_bytes[ctx->net_offset]);
ctx->net_offset += 2;
}
-ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) {
+LM_ALWAYS_INLINE static void unmarshal_4(struct _unmarshal_ctx *ctx, uint32_t *out) {
*out = decode_u32le(&ctx->net_bytes[ctx->net_offset]);
ctx->net_offset += 4;
}
-ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) {
+LM_ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out) {
*out = decode_u64le(&ctx->net_bytes[ctx->net_offset]);
ctx->net_offset += 8;
}
"""
for typ in typs:
- inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE"
+ inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE"
argfn = unused if (isinstance(typ, Struct) and not typ.members) else used
ret += "\n"
ret += ifdef_push(1, c_ver_ifdef(typ.in_versions))
@@ -973,7 +976,7 @@ ALWAYS_INLINE static void unmarshal_8(struct _unmarshal_ctx *ctx, uint64_t *out)
ret += """
/* marshal_* ******************************************************************/
-ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) {
+LM_ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) {
lib9p_errorf(ctx->ctx, LINUX_ERANGE, "%s too large to marshal into %s limit (limit=%"PRIu32")",
(ctx->net_bytes[4] % 2 == 0) ? "T-message" : "R-message",
ctx->ctx->version ? "negotiated" : ((ctx->net_bytes[4] % 2 == 0) ? "client" : "server"),
@@ -981,7 +984,7 @@ ALWAYS_INLINE static bool _marshal_too_large(struct _marshal_ctx *ctx) {
return true;
}
-ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) {
+LM_ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) {
if (ctx->net_offset + 1 > ctx->ctx->max_msg_size)
return _marshal_too_large(ctx);
ctx->net_bytes[ctx->net_offset] = *val;
@@ -989,7 +992,7 @@ ALWAYS_INLINE static bool marshal_1(struct _marshal_ctx *ctx, uint8_t *val) {
return false;
}
-ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) {
+LM_ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) {
if (ctx->net_offset + 2 > ctx->ctx->max_msg_size)
return _marshal_too_large(ctx);
encode_u16le(*val, &ctx->net_bytes[ctx->net_offset]);
@@ -997,7 +1000,7 @@ ALWAYS_INLINE static bool marshal_2(struct _marshal_ctx *ctx, uint16_t *val) {
return false;
}
-ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) {
+LM_ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) {
if (ctx->net_offset + 4 > ctx->ctx->max_msg_size)
return true;
encode_u32le(*val, &ctx->net_bytes[ctx->net_offset]);
@@ -1005,7 +1008,7 @@ ALWAYS_INLINE static bool marshal_4(struct _marshal_ctx *ctx, uint32_t *val) {
return false;
}
-ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
+LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
if (ctx->net_offset + 8 > ctx->ctx->max_msg_size)
return true;
encode_u64le(*val, &ctx->net_bytes[ctx->net_offset]);
@@ -1014,7 +1017,7 @@ ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
}
"""
for typ in typs:
- inline = "FLATTEN" if isinstance(typ, Message) else "ALWAYS_INLINE"
+ inline = "LM_FLATTEN" if isinstance(typ, Message) else "LM_ALWAYS_INLINE"
argfn = unused if (isinstance(typ, Struct) and not typ.members) else used
ret += "\n"
ret += ifdef_push(1, c_ver_ifdef(typ.in_versions))
@@ -1133,13 +1136,13 @@ struct _table_version _{idprefix}versions[{c_ver_enum('NUM')}] = {{
ret += "};\n"
ret += f"""
-FLATTEN bool _{idprefix}validate_stat(struct _validate_ctx *ctx) {{
+LM_FLATTEN bool _{idprefix}validate_stat(struct _validate_ctx *ctx) {{
return validate_stat(ctx);
}}
-FLATTEN void _{idprefix}unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{
+LM_FLATTEN void _{idprefix}unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{
unmarshal_stat(ctx, out);
}}
-FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{
+LM_FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{
return marshal_stat(ctx, val);
}}
"""