From 0c5735bc4a4d73972bc1f5fc418078a1afc272cc Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Sun, 3 Jun 2012 15:09:07 +0100 Subject: [PATCH] reprap: c_utils updates Added a fre accessors Signed-off-by: Michel Pollet --- examples/shared/libc3/src/c_array.h | 3 ++- examples/shared/libc3/src/c_utils.h | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/shared/libc3/src/c_array.h b/examples/shared/libc3/src/c_array.h index 8c08efa..bb1aa22 100644 --- a/examples/shared/libc3/src/c_array.h +++ b/examples/shared/libc3/src/c_array.h @@ -34,7 +34,7 @@ #define C_ARRAY_SIZE_TYPE uint32_t #endif -#define DECLARE_C_ARRAY(__type, __name, __page) \ +#define DECLARE_C_ARRAY(__type, __name, __page, __args...) \ enum { __name##_page_size = __page }; \ typedef __type __name##_element_t; \ typedef C_ARRAY_SIZE_TYPE __name##_count_t; \ @@ -42,6 +42,7 @@ typedef struct __name##_t {\ volatile __name##_count_t count;\ volatile __name##_count_t size;\ __name##_element_t * e;\ + __args ;\ } __name##_t, *__name##_p; #define C_ARRAY_NULL { 0, 0, NULL } diff --git a/examples/shared/libc3/src/c_utils.h b/examples/shared/libc3/src/c_utils.h index 2360fd8..d9eb074 100644 --- a/examples/shared/libc3/src/c_utils.h +++ b/examples/shared/libc3/src/c_utils.h @@ -79,6 +79,12 @@ typedef struct str_t { char str[0]; } str_t, *str_p; +static inline str_p str_alloc(size_t len) +{ + str_p r = (str_p)malloc(sizeof(*r) + len + 1); + r->rom = r->hash = 0; r->len = len; + return r; +} static inline str_p str_new_i(const char *s, void * (*_alloc)(size_t)) { int l = s ? strlen(s) : 0; @@ -97,12 +103,6 @@ static inline str_p str_new(const char *s) { return str_new_i(s, malloc); } -static inline str_p str_anew(const char *s) -{ - str_p r = str_new_i(s, alloca); - r->rom = 1; - return r; -} static inline str_p str_dup(const str_p s) { size_t l = sizeof(*s) + s->len + 1; @@ -111,6 +111,12 @@ static inline str_p str_dup(const str_p s) return r; } #ifndef NO_ALLOCA +static inline str_p str_anew(const char *s) +{ + str_p r = str_new_i(s, alloca); + r->rom = 1; + return r; +} static inline str_p str_adup(const str_p s) { size_t l = sizeof(*s) + s->len + 1; -- 2.39.5