From 14197e20a612a6fecb894c295855ffc23bc94c55 Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Mon, 25 Dec 2023 12:19:45 +0100 Subject: [PATCH] port: GenMessageParseOk -> GenCallMessage Future proof #2: return the type of message instead of a generic Ok value. Right now we support only calls. Signed-off-by: Davide Bettio --- src/libAtomVM/nifs.c | 2 +- src/libAtomVM/port.c | 2 +- src/libAtomVM/port.h | 2 +- src/platforms/esp32/components/avm_builtins/gpio_driver.c | 2 +- src/platforms/esp32/components/avm_builtins/i2c_driver.c | 2 +- src/platforms/esp32/components/avm_builtins/socket_driver.c | 2 +- src/platforms/esp32/components/avm_builtins/spi_driver.c | 2 +- src/platforms/esp32/components/avm_builtins/uart_driver.c | 2 +- src/platforms/generic_unix/lib/socket_driver.c | 2 +- src/platforms/stm32/src/lib/gpio_driver.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libAtomVM/nifs.c b/src/libAtomVM/nifs.c index fbc048b50a..0b349c069f 100644 --- a/src/libAtomVM/nifs.c +++ b/src/libAtomVM/nifs.c @@ -1034,7 +1034,7 @@ static NativeHandlerResult process_console_message(Context *ctx, term msg) } } - } else if (port_parse_gen_message(msg, &gen_message) == GenMessageParseOk) { + } else if (port_parse_gen_message(msg, &gen_message) == GenCallMessage) { term pid = gen_message.pid; term ref = gen_message.ref; term cmd = gen_message.req; diff --git a/src/libAtomVM/port.c b/src/libAtomVM/port.c index 57d9ad9ca2..4d015ef344 100644 --- a/src/libAtomVM/port.c +++ b/src/libAtomVM/port.c @@ -133,5 +133,5 @@ enum GenMessageParseResult port_parse_gen_message(term msg, GenMessage *gen_mess return GenMessageParseError; } - return GenMessageParseOk; + return GenCallMessage; } diff --git a/src/libAtomVM/port.h b/src/libAtomVM/port.h index 60cc1edf50..a69ab85ad6 100644 --- a/src/libAtomVM/port.h +++ b/src/libAtomVM/port.h @@ -92,7 +92,7 @@ typedef struct enum GenMessageParseResult { - GenMessageParseOk, + GenCallMessage, GenMessageParseError }; diff --git a/src/platforms/esp32/components/avm_builtins/gpio_driver.c b/src/platforms/esp32/components/avm_builtins/gpio_driver.c index 044a4d23b0..b7728378ba 100644 --- a/src/platforms/esp32/components/avm_builtins/gpio_driver.c +++ b/src/platforms/esp32/components/avm_builtins/gpio_driver.c @@ -479,7 +479,7 @@ static NativeHandlerResult consume_gpio_mailbox(Context *ctx) { Message *message = mailbox_first(&ctx->mailbox); GenMessage gen_message; - if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) { + if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) { ESP_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap); return NativeContinue; diff --git a/src/platforms/esp32/components/avm_builtins/i2c_driver.c b/src/platforms/esp32/components/avm_builtins/i2c_driver.c index 1747176b70..da6ebff985 100644 --- a/src/platforms/esp32/components/avm_builtins/i2c_driver.c +++ b/src/platforms/esp32/components/avm_builtins/i2c_driver.c @@ -547,7 +547,7 @@ static NativeHandlerResult i2cdriver_consume_mailbox(Context *ctx) { Message *message = mailbox_first(&ctx->mailbox); GenMessage gen_message; - if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) { + if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) { ESP_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap); return NativeContinue; diff --git a/src/platforms/esp32/components/avm_builtins/socket_driver.c b/src/platforms/esp32/components/avm_builtins/socket_driver.c index 1d93948b5d..180607f327 100644 --- a/src/platforms/esp32/components/avm_builtins/socket_driver.c +++ b/src/platforms/esp32/components/avm_builtins/socket_driver.c @@ -1396,7 +1396,7 @@ static NativeHandlerResult socket_consume_mailbox(Context *ctx) } GenMessage gen_message; - if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenMessageParseOk) + if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenCallMessage) || !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1)) { ESP_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap); diff --git a/src/platforms/esp32/components/avm_builtins/spi_driver.c b/src/platforms/esp32/components/avm_builtins/spi_driver.c index 4ce4f4ebe4..2210552023 100644 --- a/src/platforms/esp32/components/avm_builtins/spi_driver.c +++ b/src/platforms/esp32/components/avm_builtins/spi_driver.c @@ -603,7 +603,7 @@ static NativeHandlerResult spidriver_consume_mailbox(Context *ctx) { Message *message = mailbox_first(&ctx->mailbox); GenMessage gen_message; - if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) { + if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) { ESP_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap); return NativeContinue; diff --git a/src/platforms/esp32/components/avm_builtins/uart_driver.c b/src/platforms/esp32/components/avm_builtins/uart_driver.c index 45b8235252..8713f9bd75 100644 --- a/src/platforms/esp32/components/avm_builtins/uart_driver.c +++ b/src/platforms/esp32/components/avm_builtins/uart_driver.c @@ -454,7 +454,7 @@ static NativeHandlerResult uart_driver_consume_mailbox(Context *ctx) Message *message = mailbox_first(&ctx->mailbox); term msg = message->message; GenMessage gen_message; - if (UNLIKELY(port_parse_gen_message(msg, &gen_message) != GenMessageParseOk)) { + if (UNLIKELY(port_parse_gen_message(msg, &gen_message) != GenCallMessage)) { ESP_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap); return NativeContinue; diff --git a/src/platforms/generic_unix/lib/socket_driver.c b/src/platforms/generic_unix/lib/socket_driver.c index 5f1fa2eadb..3e1792fd0d 100644 --- a/src/platforms/generic_unix/lib/socket_driver.c +++ b/src/platforms/generic_unix/lib/socket_driver.c @@ -1135,7 +1135,7 @@ static NativeHandlerResult socket_consume_mailbox(Context *ctx) } GenMessage gen_message; - if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenMessageParseOk) + if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenCallMessage) || !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1)) { fprintf(stderr, "Received invalid socket message.\n"); mailbox_remove_message(&ctx->mailbox, &ctx->heap); diff --git a/src/platforms/stm32/src/lib/gpio_driver.c b/src/platforms/stm32/src/lib/gpio_driver.c index 0e870f2449..1a8fd5ff02 100644 --- a/src/platforms/stm32/src/lib/gpio_driver.c +++ b/src/platforms/stm32/src/lib/gpio_driver.c @@ -938,7 +938,7 @@ static NativeHandlerResult consume_gpio_mailbox(Context *ctx) { Message *message = mailbox_first(&ctx->mailbox); GenMessage gen_message; - if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk) + if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage) || !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1) { AVM_LOGW(TAG, "Received invalid message."); mailbox_remove_message(&ctx->mailbox, &ctx->heap);