@@ -18,22 +18,27 @@ class SourcePart:
1818
1919#ifndef COMPOST_ALLOW_SMALL_INT
2020#if INT_MAX < 2147483647
21- #error "int is smaller than 32b - Compost expects Enums to have 32b. You can allow smaller int by defining macro COMPOST_ALLOW_SMALL_INT"
21+ #error \\
22+ "int is smaller than 32b - Compost expects Enums to have 32b. You can allow smaller int by defining macro COMPOST_ALLOW_SMALL_INT"
2223#endif
2324#endif
2425
2526#ifdef COMPOST_DEBUG
26- #define COMPOST_ASSERT(expr) \\
27- do { \\
28- if (!(expr)) { \\
29- if (compost_assert_func != NULL) { \\
30- compost_assert_func(__LINE__); \\
31- } \\
32- while(1); \\
33- } \\
27+ #define COMPOST_ASSERT(expr) \\
28+ do { \\
29+ if (!(expr)) { \\
30+ if (compost_assert_func != NULL) { \\
31+ compost_assert_func(__LINE__); \\
32+ } \\
33+ while (1) \\
34+ ; \\
35+ } \\
3436 } while (0)
3537#else
36- #define COMPOST_ASSERT(expr) do { (void)sizeof(expr); } while (0)
38+ #define COMPOST_ASSERT(expr) \\
39+ do { \\
40+ (void)sizeof(expr); \\
41+ } while (0)
3742#endif
3843
3944#define LEN_OFFSET 0
@@ -42,11 +47,11 @@ class SourcePart:
4247#define RPC_ID_LO_OFFSET 3
4348#define PAYLOAD_OFFSET 4
4449
45- #define RPC_ID_HI_MASK 0x0F
46- #define FLAGS_MASK 0xF0
47- #define RESP_MASK 0x10
50+ #define RPC_ID_HI_MASK 0x0F
51+ #define FLAGS_MASK 0xF0
52+ #define RESP_MASK 0x10
4853
49- static void(*compost_assert_func)(uint32_t line) = NULL;
54+ static void (*compost_assert_func)(uint32_t line) = NULL;
5055
5156void compost_invoke_switch(struct CompostMsg *tx, const struct CompostMsg rx);
5257
@@ -110,7 +115,7 @@ class SourcePart:
110115 */
111116static inline int8_t compost_i8_load(const uint8_t **src)
112117{
113- return (int8_t) compost_u8_load(src);
118+ return (int8_t)compost_u8_load(src);
114119}
115120
116121/**
@@ -126,9 +131,7 @@ class SourcePart:
126131 */
127132static inline uint16_t compost_u16_load(const uint8_t **src)
128133{
129- uint16_t val =
130- ((uint16_t)(*src)[0] << 8) |
131- ((uint16_t)(*src)[1]);
134+ uint16_t val = ((uint16_t)(*src)[0] << 8) | ((uint16_t)(*src)[1]);
132135 *src += sizeof(uint16_t);
133136 return val;
134137}
@@ -164,11 +167,8 @@ class SourcePart:
164167 */
165168static inline uint32_t compost_u32_load(const uint8_t **src)
166169{
167- uint32_t val =
168- ((uint32_t)(*src)[0] << 24) |
169- ((uint32_t)(*src)[1] << 16) |
170- ((uint32_t)(*src)[2] << 8) |
171- ((uint32_t)(*src)[3]);
170+ uint32_t val = ((uint32_t)(*src)[0] << 24) | ((uint32_t)(*src)[1] << 16) |
171+ ((uint32_t)(*src)[2] << 8) | ((uint32_t)(*src)[3]);
172172 *src += sizeof(uint32_t);
173173 return val;
174174}
@@ -206,15 +206,10 @@ class SourcePart:
206206 */
207207static inline uint64_t compost_u64_load(const uint8_t **src)
208208{
209- uint64_t val =
210- ((uint64_t)(*src)[0] << 56) |
211- ((uint64_t)(*src)[1] << 48) |
212- ((uint64_t)(*src)[2] << 40) |
213- ((uint64_t)(*src)[3] << 32) |
214- ((uint64_t)(*src)[4] << 24) |
215- ((uint64_t)(*src)[5] << 16) |
216- ((uint64_t)(*src)[6] << 8) |
217- ((uint64_t)(*src)[7]);
209+ uint64_t val = ((uint64_t)(*src)[0] << 56) | ((uint64_t)(*src)[1] << 48) |
210+ ((uint64_t)(*src)[2] << 40) | ((uint64_t)(*src)[3] << 32) |
211+ ((uint64_t)(*src)[4] << 24) | ((uint64_t)(*src)[5] << 16) |
212+ ((uint64_t)(*src)[6] << 8) | ((uint64_t)(*src)[7]);
218213 *src += sizeof(uint64_t);
219214 return val;
220215}
@@ -240,7 +235,7 @@ class SourcePart:
240235 */
241236static inline int64_t compost_i64_load(const uint8_t **src)
242237{
243- return (int64_t) compost_u64_load(src);
238+ return (int64_t)compost_u64_load(src);
244239}
245240
246241/**
@@ -296,7 +291,7 @@ class SourcePart:
296291/**
297292 * Loads bit precise integer from the backing value
298293 */
299- uint32_t compost_bituint_load(const uint8_t* src, uint32_t offset_bits, uint32_t size_bits)
294+ uint32_t compost_bituint_load(const uint8_t * src, uint32_t offset_bits, uint32_t size_bits)
300295{
301296 COMPOST_ASSERT(src != NULL);
302297 uint64_t val = 0;
@@ -323,7 +318,7 @@ class SourcePart:
323318/**
324319 * Stores bit precise integer to the backing value
325320 */
326- void compost_bituint_store(uint8_t* dest, uint32_t value, uint32_t offset_bits, uint32_t size_bits)
321+ void compost_bituint_store(uint8_t * dest, uint32_t value, uint32_t offset_bits, uint32_t size_bits)
327322{
328323 COMPOST_ASSERT(dest != NULL);
329324 uint32_t byte_index = offset_bits / 8;
@@ -350,7 +345,7 @@ class SourcePart:
350345static inline struct CompostSlice${struct_suffix} compost_slice_${fn_suffix}_load(const uint8_t **src)
351346{
352347 uint16_t len = compost_u16_load(src);
353- struct CompostSlice${struct_suffix} ret = (struct CompostSlice${struct_suffix}){ .ptr = (uint8_t*)(*src), .len = len / sizeof(${type}) };
348+ struct CompostSlice${struct_suffix} ret = (struct CompostSlice${struct_suffix}){.ptr = (uint8_t *)(*src), .len = len / sizeof(${type})};
354349 *src += len;
355350 return ret;
356351}
@@ -474,7 +469,7 @@ class SourcePart:
474469 }
475470}
476471
477- void compost_set_assert_func(void(*assert_func)(uint32_t line))
472+ void compost_set_assert_func(void (*assert_func)(uint32_t line))
478473{
479474 compost_assert_func = assert_func;
480475}
@@ -484,7 +479,7 @@ class SourcePart:
484479source_parts .append (SourcePart (True ,'''
485480struct CompostSlice${struct_suffix} compost_slice_${fn_suffix}_init(void *ptr, uint16_t len)
486481{
487- return (struct CompostSlice${struct_suffix}){ .ptr = ptr, .len = len };
482+ return (struct CompostSlice${struct_suffix}){.ptr = ptr, .len = len};
488483}
489484
490485struct CompostSlice${struct_suffix} compost_slice_${fn_suffix}_new(struct CompostAlloc *alloc, uint16_t len)
@@ -493,22 +488,22 @@ class SourcePart:
493488 if (ptr == NULL) {
494489 len = 0;
495490 }
496- return (struct CompostSlice${struct_suffix}){ .ptr = ptr, .len = len};
491+ return (struct CompostSlice${struct_suffix}){.ptr = ptr, .len = len};
497492}
498493
499494${type} compost_slice_${fn_suffix}_get(struct CompostSlice${struct_suffix} target, uint16_t idx)
500495{
501496 COMPOST_ASSERT(idx < target.len);
502497 COMPOST_ASSERT(target.ptr != NULL);
503- const uint8_t* ptr = target.ptr + (sizeof(${type}) * idx);
498+ const uint8_t * ptr = target.ptr + (sizeof(${type}) * idx);
504499 return compost_${fn_suffix}_load(&ptr);
505500}
506501
507502void compost_slice_${fn_suffix}_set(struct CompostSlice${struct_suffix} target, uint16_t idx, ${type} value)
508503{
509504 COMPOST_ASSERT(idx < target.len);
510505 COMPOST_ASSERT(target.ptr != NULL);
511- uint8_t* ptr = target.ptr + (sizeof(${type}) * idx);
506+ uint8_t * ptr = target.ptr + (sizeof(${type}) * idx);
512507 compost_${fn_suffix}_store(&ptr, value);
513508}
514509
@@ -517,7 +512,7 @@ class SourcePart:
517512 COMPOST_ASSERT(dest.ptr != NULL);
518513 COMPOST_ASSERT(src != NULL);
519514 int len_limit = len <= dest.len ? len : dest.len;
520- if ((uint8_t*)src != dest.ptr) {
515+ if ((uint8_t *)src != dest.ptr) {
521516 for (int i = 0; i < len_limit; i++) {
522517 compost_slice_${fn_suffix}_set(dest, i, src[i]);
523518 }
@@ -537,7 +532,7 @@ class SourcePart:
537532 COMPOST_ASSERT(src.ptr != NULL);
538533 COMPOST_ASSERT(dest != NULL);
539534 int len_limit = len <= src.len ? len : src.len;
540- if (src.ptr != (uint8_t*)dest) {
535+ if (src.ptr != (uint8_t *)dest) {
541536 for (int i = 0; i < len_limit; i++) {
542537 dest[i] = compost_slice_${fn_suffix}_get(src, i);
543538 }
@@ -563,10 +558,10 @@ class SourcePart:
563558struct CompostAlloc compost_alloc_init(uint8_t *buffer, uint16_t len)
564559{
565560 return (struct CompostAlloc){.suffixes = NULL,
566- .suffixes_len = 0,
567- .alloc_ctr = 0,
568- .ptr = buffer,
569- .buffer = compost_slice_u8_init(buffer, len)};
561+ .suffixes_len = 0,
562+ .alloc_ctr = 0,
563+ .ptr = buffer,
564+ .buffer = compost_slice_u8_init(buffer, len)};
570565}
571566
572567void compost_alloc_set_suffixes(struct CompostAlloc *alloc, uint16_t *suffixes, uint16_t len)
@@ -590,7 +585,8 @@ class SourcePart:
590585{
591586 COMPOST_ASSERT(alloc != NULL);
592587 int capacity = alloc->buffer.len - (alloc->ptr - alloc->buffer.ptr);
593- if ((int)len > capacity || (alloc->suffixes != NULL && alloc->alloc_ctr >= alloc->suffixes_len)) {
588+ if ((int)len > capacity ||
589+ (alloc->suffixes != NULL && alloc->alloc_ctr >= alloc->suffixes_len)) {
594590 return NULL;
595591 }
596592
@@ -624,7 +620,7 @@ class SourcePart:
624620 compost_slice_copy_from(dest, (void *)src, len);
625621 if (len < dest.len) {
626622 for (int i = len; i < dest.len; i++) {
627- compost_slice_set(dest, i, '\\ 0');
623+ compost_slice_set(dest, i, '\0 ');
628624 }
629625 }
630626}
0 commit comments