From e5ffd10d4e2567aeeb205df5e139163c9a5d39c6 Mon Sep 17 00:00:00 2001 From: viandoxdev Date: Fri, 19 May 2023 19:29:46 +0200 Subject: [PATCH] small ser fixes: fix warning and allow same message name in different messages object --- ser/codegen_python.c | 2 -- ser/eval.c | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ser/codegen_python.c b/ser/codegen_python.c index 1223b49..b62c065 100644 --- a/ser/codegen_python.c +++ b/ser/codegen_python.c @@ -403,7 +403,6 @@ static void define_message(Writer *w, const char *prefix, uint16_t tag, Hashmap wt_format(w, "class %s(%sMessage):\n", name, prefix); TypeObject *type; - StructObject *obj; FieldVec fields = vec_clone(&msg.fields); { if (msg.attributes & Attr_versioned) { @@ -418,7 +417,6 @@ static void define_message(Writer *w, const char *prefix, uint16_t tag, Hashmap type->type.struct_.has_funcs = false; type->type.struct_.fields = *(AnyVec *)&fields; type->align = ALIGN_8; - obj = (StructObject *)&type->type.struct_; Layout l = type_layout(type); hashmap_set(layouts, &l); diff --git a/ser/eval.c b/ser/eval.c index 11e8201..22d9ea8 100644 --- a/ser/eval.c +++ b/ser/eval.c @@ -1117,6 +1117,7 @@ static void resolve_constants(EvaluationContext *ctx) { static void resolve_messages(EvaluationContext *ctx) { AstItemVec *items = ctx->items; Hashmap *names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice)); + Hashmap *message_names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice)); Hashmap *field_names = hashmap_init(sss_hash, sss_equal, NULL, sizeof(SpannedStringSlice)); ctx->messages = (MessagesObjectVec)vec_init(); @@ -1166,11 +1167,11 @@ static void resolve_messages(EvaluationContext *ctx) { SpannedStringSlice name = sss_from_token(msg.ident); - SpannedStringSlice *prev_name = hashmap_get(names, &name); + SpannedStringSlice *prev_name = hashmap_get(message_names, &name); if (prev_name != NULL) { vec_push(&ctx->errors, err_duplicate_def(prev_name->span, name.span, ATIdent, name.slice)); } else { - hashmap_set(names, &name); + hashmap_set(message_names, &name); } MessageObject message; @@ -1203,11 +1204,13 @@ static void resolve_messages(EvaluationContext *ctx) { } } + hashmap_clear(message_names); vec_push(&ctx->messages, res); version = ~0; } hashmap_drop(names); + hashmap_drop(message_names); hashmap_drop(field_names); }