From 8cbca387269e5c0371cda8d4e2e801399ea743cb Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 2 Jul 2024 06:26:17 +0200 Subject: [PATCH 1/3] Bugfix incrementing count by correct amount in rb_push_many --- ringbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ringbuf.c b/ringbuf.c index e3c7067..23adb94 100644 --- a/ringbuf.c +++ b/ringbuf.c @@ -107,7 +107,7 @@ rb_push_many(struct RingBuf *rb, const void *items, MEMCPY_T memcpy_fn, // Advance the write head rb->write_head = (char *)rb->write_head + rb->struct_size * n; - rb->count+=n; + rb->count += n; return WriteOk; } From 8e77f810ec3c5dce234e16df06f753f838712796 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 2 Jul 2024 06:27:05 +0200 Subject: [PATCH 2/3] Better enum docs, added errors related to *_many functions --- ringbuf.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ringbuf.h b/ringbuf.h index 0117887..efffe50 100644 --- a/ringbuf.h +++ b/ringbuf.h @@ -25,8 +25,24 @@ struct RingBuf { void *buffer_end; /** The end of the buffer */ } __attribute__((packed)); -enum WriteResult { Full, WriteOk }; /** Result of a write */ -enum ReadResult { Empty, ReadOk }; /** Result of a read */ +/* + * Considerations: One hot encoding for the enum values + * (8 bit each with -fshort-enums) + */ + +/** Result of a write */ +enum WriteResult { + WriteOk, /** The write was successful */ + Full, /** The buffer is full */ + InsufficientSpace /** There is not enough space to write */ +}; + +/** Result of a read */ +enum ReadResult { + Empty, /** The buffer is empty */ + ReadOk, /** The read was successful */ + InsufficientData /** There is not enough data to read */ +}; /** * @brief Initialize the ring buffer From 68af34c42869248860238a5edfed51879ffe7d21 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 2 Jul 2024 06:27:22 +0200 Subject: [PATCH 3/3] -fshort-enums in release mode --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 49f09d0..760129d 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ ifneq ($(DEBUG), 1) CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -fno-ident CFLAGS += -fno-unwind-tables -fno-stack-protector -fno-plt -fno-pic CFLAGS += -O3 -std=c99 -march=native -mtune=native -fomit-frame-pointer +CFLAGS += -fshort-enums else CFLAGS += -g -O0 -std=c99 -march=native -mtune=native CFLAGS += -DDEBUG