From: lottaviano Date: Tue, 17 May 2011 09:49:37 +0000 (+0000) Subject: Better error handling in parser_register_cmd() X-Git-Tag: 2.7.0~66 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=332a7970140d2af1b233d29c0316f51a6a54a637;p=bertos.git Better error handling in parser_register_cmd() The parser_register_cmd() function does not return any error in case the hashtable used for storing the commands is full, a condition that is hard to debug. This patch modifies the function prototype to return success or failure and changes the REGISTER_CMD macro to detect the error. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4900 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/mware/parser.c b/bertos/mware/parser.c index 142feba6..71aec30d 100644 --- a/bertos/mware/parser.c +++ b/bertos/mware/parser.c @@ -309,10 +309,11 @@ bool parser_process_line(const char* input) * Register a new command into the parser * * \param cmd Command template describing the command + * \return true if registration was successful, false otherwise */ -void parser_register_cmd(const struct CmdTemplate* cmd) +bool parser_register_cmd(const struct CmdTemplate* cmd) { - ht_insert(&commands, cmd); + return ht_insert(&commands, cmd); } void parser_init(void) diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h index ca1d26e9..281db396 100644 --- a/bertos/mware/parser.h +++ b/bertos/mware/parser.h @@ -118,6 +118,7 @@ #include "cfg/cfg_parser.h" #include +#include /** * Error generated by the commands through the return code. @@ -163,7 +164,11 @@ struct CmdTemplate * * \param NAME Command name to register */ -#define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) +#define REGISTER_CMD(NAME) \ + do { \ + if (!REGISTER_FUNCTION(&cmd_ ## NAME ## _template)) \ + ASSERT2(0, "Error in registering command, no space left"); \ + } while (0) /** * Utility macro to create a command template. @@ -219,7 +224,7 @@ MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) */ void parser_init(void); -void parser_register_cmd(const struct CmdTemplate* cmd); +bool parser_register_cmd(const struct CmdTemplate* cmd); /**