reprap: c_utils updates
authorMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 14:09:07 +0000 (15:09 +0100)
committerMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 14:09:07 +0000 (15:09 +0100)
Added a fre accessors

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/shared/libc3/src/c_array.h
examples/shared/libc3/src/c_utils.h

index 8c08efa..bb1aa22 100644 (file)
@@ -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 }
index 2360fd8..d9eb074 100644 (file)
@@ -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;