From 5a123a34055cf398d00744c8365ba9b27d15b01c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 25 Apr 2016 21:00:28 +0200 Subject: [PATCH] tcpip_priv.h: More flexible API by including return value in API_VAR_ALLOC macro --- src/api/api_lib.c | 4 ++-- src/api/netifapi.c | 2 +- src/api/tcpip.c | 2 +- src/include/lwip/priv/tcpip_priv.h | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 410984a6..3f46d623 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -57,7 +57,7 @@ #define API_MSG_VAR_REF(name) API_VAR_REF(name) #define API_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct api_msg, name) -#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name) +#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, ERR_MEM) #define API_MSG_VAR_ALLOC_DONTFAIL(name) API_VAR_ALLOC_DONTFAIL(struct api_msg, MEMP_API_MSG, name) #define API_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_API_MSG, name) @@ -881,7 +881,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr) } #endif - API_VAR_ALLOC(struct dns_api_msg, MEMP_DNS_API_MSG, msg); + API_VAR_ALLOC(struct dns_api_msg, MEMP_DNS_API_MSG, msg, ERR_MEM); #if LWIP_MPU_COMPATIBLE strncpy(API_VAR_REF(msg).name, name, DNS_MAX_NAME_LENGTH-1); API_VAR_REF(msg).name[DNS_MAX_NAME_LENGTH-1] = 0; diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 35074e4a..a2137fc7 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -41,7 +41,7 @@ #define NETIFAPI_VAR_REF(name) API_VAR_REF(name) #define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name) -#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name) +#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM) #define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name) /** diff --git a/src/api/tcpip.c b/src/api/tcpip.c index f930816b..57934751 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -51,7 +51,7 @@ #define TCPIP_MSG_VAR_REF(name) API_VAR_REF(name) #define TCPIP_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct tcpip_msg, name) -#define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name) +#define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM) #define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name) /* global variables */ diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index b1d3a72e..1aecdc38 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -50,16 +50,16 @@ struct netif; #if LWIP_MPU_COMPATIBLE #define API_VAR_REF(name) (*(name)) #define API_VAR_DECLARE(type, name) type * name -#define API_VAR_ALLOC(type, pool, name) do { \ +#define API_VAR_ALLOC(type, pool, name, errorval) do { \ name = (type *)memp_malloc(pool); \ if (name == NULL) { \ - return ERR_MEM; \ + return errorval; \ } \ } while(0) -#define API_VAR_ALLOC_POOL(type, pool, name) do { \ +#define API_VAR_ALLOC_POOL(type, pool, name, errorval) do { \ name = (type *)LWIP_MEMPOOL_ALLOC(pool); \ if (name == NULL) { \ - return ERR_MEM; \ + return errorval; \ } \ } while(0) #define API_VAR_ALLOC_DONTFAIL(type, pool, name) do { \