rtos: Use ARRAY_SIZE instead of coding it by hand
authorMatthias Blaicher <matthias@blaicher.com>
Sat, 27 Oct 2012 15:21:24 +0000 (17:21 +0200)
committerPeter Stuge <peter@stuge.se>
Sun, 28 Oct 2012 01:25:39 +0000 (01:25 +0000)
Use ARRAY_SIZE in helper/types.h to determine the size of the
symbol list.

Change-Id: Icc9838323510f8602efa5d0162a4daed33f863b9
Signed-off-by: Matthias Blaicher <matthias@blaicher.com>
Reviewed-on: http://openocd.zylin.com/935
Tested-by: jenkins
Reviewed-by: Peter Stuge <peter@stuge.se>
src/rtos/ChibiOS.c
src/rtos/FreeRTOS.c
src/rtos/ThreadX.c
src/rtos/eCos.c

index 2c2b7953334406bd8473fc0f096af1568c1566db..c838b493c7d5f965bab2a2cfe6ee72de61e241d2 100644 (file)
@@ -31,6 +31,7 @@
 #include "target/target_type.h"
 #include "rtos.h"
 #include "helper/log.h"
+#include "helper/types.h"
 #include "rtos_chibios_stackings.h"
 
 
@@ -132,8 +133,6 @@ static char *ChibiOS_symbol_list[] = {
        NULL
 };
 
-#define CHIBIOS_NUM_SYMBOLS (sizeof(ChibiOS_symbol_list)/sizeof(char *))
-
 static int ChibiOS_update_memory_signature(struct rtos *rtos)
 {
        int retval;
@@ -483,9 +482,9 @@ static int ChibiOS_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
 {
        unsigned int i;
        *symbol_list = (symbol_table_elem_t *) malloc(
-                       sizeof(symbol_table_elem_t) * CHIBIOS_NUM_SYMBOLS);
+                       sizeof(symbol_table_elem_t) * ARRAY_SIZE(ChibiOS_symbol_list));
 
-       for (i = 0; i < CHIBIOS_NUM_SYMBOLS; i++)
+       for (i = 0; i < ARRAY_SIZE(ChibiOS_symbol_list); i++)
                (*symbol_list)[i].symbol_name = ChibiOS_symbol_list[i];
 
        return 0;
index 2295d7456532ee1709cc3ec5bc833551934910eb..5ca4ce9594fcc6bb3a5a8bc0d8580d2e50acc3e8 100644 (file)
@@ -28,6 +28,7 @@
 #include "target/target_type.h"
 #include "rtos.h"
 #include "helper/log.h"
+#include "helper/types.h"
 #include "rtos_standard_stackings.h"
 
 #define FREERTOS_MAX_PRIORITIES        63
@@ -121,8 +122,6 @@ static char *FreeRTOS_symbol_list[] = {
        NULL
 };
 
-#define FREERTOS_NUM_SYMBOLS (sizeof(FreeRTOS_symbol_list)/sizeof(char *))
-
 /* TODO: */
 /* this is not safe for little endian yet */
 /* may be problems reading if sizes are not 32 bit long integers. */
@@ -399,9 +398,9 @@ static int FreeRTOS_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]
 {
        unsigned int i;
        *symbol_list = (symbol_table_elem_t *) malloc(
-                       sizeof(symbol_table_elem_t) * FREERTOS_NUM_SYMBOLS);
+                       sizeof(symbol_table_elem_t) * ARRAY_SIZE(FreeRTOS_symbol_list));
 
-       for (i = 0; i < FREERTOS_NUM_SYMBOLS; i++)
+       for (i = 0; i < ARRAY_SIZE(FreeRTOS_symbol_list); i++)
                (*symbol_list)[i].symbol_name = FreeRTOS_symbol_list[i];
 
        return 0;
index a9e313bf2ef44bbe1ae2c4ca6ed45c6d086e07f0..297f3fa8c05ed41fd14cc91cefd2ce9899b91327 100644 (file)
@@ -28,6 +28,7 @@
 #include "target/target_type.h"
 #include "rtos.h"
 #include "helper/log.h"
+#include "helper/types.h"
 #include "rtos_standard_stackings.h"
 
 static int ThreadX_detect_rtos(struct target *target);
@@ -97,8 +98,6 @@ static char *ThreadX_symbol_list[] = {
        NULL
 };
 
-#define THREADX_NUM_SYMBOLS (sizeof(ThreadX_symbol_list)/sizeof(char *))
-
 const struct rtos_type ThreadX_rtos = {
        .name = "ThreadX",
 
@@ -342,9 +341,9 @@ static int ThreadX_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
 {
        unsigned int i;
        *symbol_list = (symbol_table_elem_t *) malloc(
-                       sizeof(symbol_table_elem_t) * THREADX_NUM_SYMBOLS);
+                       sizeof(symbol_table_elem_t) * ARRAY_SIZE(ThreadX_symbol_list));
 
-       for (i = 0; i < THREADX_NUM_SYMBOLS; i++)
+       for (i = 0; i < ARRAY_SIZE(ThreadX_symbol_list); i++)
                (*symbol_list)[i].symbol_name = ThreadX_symbol_list[i];
 
        return 0;
index 5c18916a12ee58908413bd4410f8ede84cb08d7c..7964712f8b2620e76d555d123869461d20a94f15 100644 (file)
@@ -26,6 +26,7 @@
 #include "target/target_type.h"
 #include "rtos.h"
 #include "helper/log.h"
+#include "helper/types.h"
 #include "rtos_ecos_stackings.h"
 
 static int eCos_detect_rtos(struct target *target);
@@ -87,8 +88,6 @@ static char *eCos_symbol_list[] = {
        NULL
 };
 
-#define ECOS_NUM_SYMBOLS (sizeof(eCos_symbol_list)/sizeof(char *))
-
 const struct rtos_type eCos_rtos = {
        .name = "eCos",
 
@@ -379,9 +378,9 @@ static int eCos_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
 {
        unsigned int i;
        *symbol_list = (symbol_table_elem_t *) malloc(
-                       sizeof(symbol_table_elem_t) * ECOS_NUM_SYMBOLS);
+                       sizeof(symbol_table_elem_t) * ARRAY_SIZE(eCos_symbol_list));
 
-       for (i = 0; i < ECOS_NUM_SYMBOLS; i++)
+       for (i = 0; i < ARRAY_SIZE(eCos_symbol_list); i++)
                (*symbol_list)[i].symbol_name = eCos_symbol_list[i];
 
        return 0;