Commit 63b45f3bfdc7b2529377f3d4ad9c5dc1ac07c4ae

tokyovania 2022-08-12T14:38:49

switch from bits to bytes

diff --git a/gtk3/rtbuf_gtk3_connection.c b/gtk3/rtbuf_gtk3_connection.c
index ab0c745..459a731 100644
--- a/gtk3/rtbuf_gtk3_connection.c
+++ b/gtk3/rtbuf_gtk3_connection.c
@@ -19,8 +19,8 @@
 #include "rtbuf_gtk3.h"
 
 s_data_type g_rtbuf_gtk_connection_type = {
-  sizeof(s_rtbuf_gtk_connection) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_gtk_connection),
+  DATA_TYPE_BYTES
 };
 s_data_alloc g_rtbuf_gtk_connection_alloc;
 
diff --git a/gtk3/rtbuf_gtk3_rtbuf_info.c b/gtk3/rtbuf_gtk3_rtbuf_info.c
index 360c234..fa3ec4d 100644
--- a/gtk3/rtbuf_gtk3_rtbuf_info.c
+++ b/gtk3/rtbuf_gtk3_rtbuf_info.c
@@ -19,8 +19,8 @@
 #include "rtbuf_gtk3_rtbuf_info.h"
 
 s_data_type  g_rtbuf_gtk_rtbuf_info_type = {
-  sizeof(s_rtbuf_gtk_rtbuf_info) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_gtk_rtbuf_info),
+  DATA_TYPE_BYTES
 };
 
 s_data_alloc g_rtbuf_gtk_rtbuf_info_alloc;
diff --git a/lib/signal.c b/lib/signal.c
index 6089050..35edbec 100644
--- a/lib/signal.c
+++ b/lib/signal.c
@@ -53,7 +53,7 @@ rtbuf_signal_sample (s_rtbuf *rtb,
     assert(v->out < src->proc->out_n);
     out = &src->proc->out[v->out];
     assert(out->type);
-    if (out->type->t.bits >= sizeof(t_rtbuf_signal_sample) * 8) {
+    if (out->type->t.bytes >= sizeof(t_rtbuf_signal_sample)) {
       t_rtbuf_signal_sample *sample = (t_rtbuf_signal_sample*)
         ((char*) src->data + out->offset);
       return *sample;
@@ -102,9 +102,9 @@ void rtbuf_signal_fun (s_rtbuf *rtb,
     assert(v->out < dest->proc->out_n);
     out = &dest->proc->out[v->out];
     assert(out->type);
-    if (out->type->t.bits >= sizeof(t_rtbuf_signal_sample) * 8)
+    if (out->type->t.bytes >= sizeof(t_rtbuf_signal_sample))
       rsf->signal = (double*)((char*) dest->data + out->offset);
-    if (out->type->t.bits >= sizeof(t_rtbuf_signal) * 8)
+    if (out->type->t.bytes >= sizeof(t_rtbuf_signal))
       rsf->sample_fun = rtbuf_signal_sample_from_signal;
   }
 }
diff --git a/librtbuf/data.c b/librtbuf/data.c
index 6298b2f..663b2b5 100644
--- a/librtbuf/data.c
+++ b/librtbuf/data.c
@@ -20,15 +20,15 @@
 #include "data.h"
 
 s_data_type g_data_alloc_type = {
-  sizeof(s_data_alloc) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_data_alloc),
+  DATA_TYPE_BYTES
 };
 s_data_alloc g_data_alloc_alloc;
 s_data_alloc *g_data_alloc = NULL;
 
 s_data_type g_data_type_type = {
-  sizeof(u_data_type) * 8,
-  DATA_TYPE_BITS
+  sizeof(u_data_type),
+  DATA_TYPE_BYTES
 };
 s_data_alloc *g_data_type_alloc = NULL;
 u_data_type *g_data_type = NULL;
@@ -62,7 +62,7 @@ void data_alloc_init (s_data_alloc *da, s_data_type *t,
   assert(t);
   da->t = t;
   da->max = max;
-  da->mem = calloc(max, (t->bits + 7) / 8);
+  da->mem = calloc(max, t->bytes);
   da->n = 0;
   da->free = calloc(max, sizeof(unsigned int));
   da->free_n = 0;
@@ -73,7 +73,7 @@ void data_alloc_init (s_data_alloc *da, s_data_type *t,
 void data_alloc_clean (s_data_alloc *da)
 {
   assert(da);
-  bzero(da->mem, da->max * ((da->t->bits + 7) / 8));
+  bzero(da->mem, da->max * da->t->bytes);
   bzero(da->free, da->max * sizeof(unsigned int));
   free(da->mem);
   free(da->free);
@@ -81,7 +81,7 @@ void data_alloc_clean (s_data_alloc *da)
 
 void * data_new_at (s_data_alloc *da, unsigned int i)
 {
-  unsigned int octets = (da->t->bits + 7) / 8;
+  unsigned int octets = da->t->bytes;
   unsigned int offset = i * octets;
   void *m = (char*) da->mem + offset;
   bzero(m, octets);
@@ -128,7 +128,7 @@ void data_delete (s_data_alloc *da, void *data)
   unsigned int i;
   assert(da);
   assert(da->t);
-  octets = ((da->t->bits + 7) / 8);
+  octets = da->t->bytes;
   assert(da->mem <= data);
   assert((char*) data < (char*) da->mem + da->max * octets);
   if (da->clean)
@@ -166,13 +166,13 @@ void data_alloc_delete_all ()
   }
 }
 
-u_data_type * data_type_new (unsigned int bits, unsigned int type)
+u_data_type * data_type_new (unsigned int bytes, unsigned int type)
 {
   u_data_type *t;
   assert(g_data_type_alloc);
   t = data_new(g_data_type_alloc);
   assert(t);
-  t->t.bits = bits;
+  t->t.bytes = bytes;
   t->t.type = type;
   return t;
 }
diff --git a/librtbuf/data.h b/librtbuf/data.h
index a59b6b5..2b94404 100644
--- a/librtbuf/data.h
+++ b/librtbuf/data.h
@@ -17,7 +17,7 @@
 #define DATA_H
 
 typedef enum {
-  DATA_TYPE_BITS,
+  DATA_TYPE_BYTES,
   DATA_TYPE_VECTOR,
   DATA_TYPE_INTEGER,
   DATA_TYPE_FLOAT,
@@ -28,7 +28,7 @@ typedef enum {
 #define DATA_TYPE_BIG_ENDIAN 2
 
 typedef struct data_type {
-  unsigned int bits;
+  unsigned int bytes;
   unsigned int type;
 } s_data_type;
 
@@ -63,7 +63,7 @@ typedef union data_type_ {
 
 #define DATA_TYPE_MAX 1024
 
-u_data_type * data_type_new (unsigned int bits, unsigned int type);
+u_data_type * data_type_new (unsigned int bytes, unsigned int type);
 void          data_type_delete (s_data_type *t);
 
 typedef void f_data_init (void *data);
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index 1110a17..72f03d7 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -29,8 +29,8 @@
 #include "symbol.h"
 
 s_data_type   g_rtbuf_type = {
-  sizeof(s_rtbuf) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf),
+  DATA_TYPE_BYTES
 };
 s_data_alloc  g_rtbuf_alloc = {0};
 s_rtbuf      *g_rtbuf = 0;
@@ -276,7 +276,7 @@ int rtbuf_data_set (s_rtbuf *rtb, symbol name, void *value,
   int out_i = rtbuf_proc_out_find(rtb->proc, name);
   if (out_i >= 0) {
     s_rtbuf_proc_out *out = &rtb->proc->out[out_i];
-    if (out->type->t.bits == size * 8) {
+    if (out->type->t.bytes == size) {
       void *data = (char*) rtb->data + out->offset;
       memcpy(data, value, size);
       return size;
@@ -555,7 +555,7 @@ int rtbuf_out_int (s_rtbuf *rtb, unsigned int out, int default_value)
   assert(out < rtb->proc->out_n);
   o = &rtb->proc->out[out];
   assert(o->type);
-  if (o->type->t.bits >= sizeof(int) * 8) {
+  if (o->type->t.bytes >= sizeof(int)) {
     int *i = (int*)((char*) rtb->data + o->offset);
     return *i;
   }
diff --git a/librtbuf/rtbuf_lib.c b/librtbuf/rtbuf_lib.c
index 76671e2..1405167 100644
--- a/librtbuf/rtbuf_lib.c
+++ b/librtbuf/rtbuf_lib.c
@@ -26,8 +26,8 @@
 #include "symbol.h"
 
 s_data_type  g_rtbuf_lib_type = {
-  sizeof(s_rtbuf_lib) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_lib),
+  DATA_TYPE_BYTES
 };
 s_data_alloc g_rtbuf_lib_alloc;
 s_rtbuf_lib *g_rtbuf_lib;
@@ -252,8 +252,8 @@ void rtbuf_lib_proc_init_in (s_rtbuf_proc *proc,
   }
   proc->in_n = i;
   proc->bytes = offset;
-  proc->type.bits = offset * 8;
-  proc->type.type = DATA_TYPE_BITS;
+  proc->type.bytes = offset;
+  proc->type.type = DATA_TYPE_BYTES;
 }
 
 void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
@@ -273,7 +273,7 @@ void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
       g_str_append(": ", 2);
       g_str_append(o->type->name, strlen(o->type->name) + 1);
       assert(o->type);
-      size = (o->type->t.bits + 7) / 8;
+      size = o->type->t.bytes;
       offset = add_padding(offset, size);
       o->offset = offset;
       offset += size;
diff --git a/librtbuf/rtbuf_proc.c b/librtbuf/rtbuf_proc.c
index bb25e8e..b8d8cf8 100644
--- a/librtbuf/rtbuf_proc.c
+++ b/librtbuf/rtbuf_proc.c
@@ -23,8 +23,8 @@
 #include "symbol.h"
 
 s_data_type g_rtbuf_proc_type = {
-  sizeof(s_rtbuf_proc) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_proc),
+  DATA_TYPE_BYTES
 };
 s_data_alloc g_rtbuf_proc_alloc;
 s_rtbuf_proc *g_rtbuf_proc;
diff --git a/librtbuf/rtbuf_type.c b/librtbuf/rtbuf_type.c
index 09b78d2..127d6d0 100644
--- a/librtbuf/rtbuf_type.c
+++ b/librtbuf/rtbuf_type.c
@@ -23,8 +23,8 @@
 #include "symbol.h"
 
 s_data_type   g_rtbuf_data_type_type = {
-  sizeof(s_rtbuf_type) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_type),
+  DATA_TYPE_BYTES
 };
 s_data_alloc  g_rtbuf_data_type_alloc;
 s_rtbuf_type *g_rtbuf_data_type;
@@ -62,8 +62,8 @@ s_rtbuf_type * rtbuf_type_new (const char *name, unsigned int size)
   if (!rt)
     return 0;
   rt->name = symbol_intern(name);
-  rt->t.bits = size * 8;
-  rt->t.type = DATA_TYPE_BITS;
+  rt->t.bytes = size;
+  rt->t.type = DATA_TYPE_BYTES;
   return rt;
 }
 
@@ -105,7 +105,7 @@ s_rtbuf_type * rtbuf_type_find (symbol name)
 s_rtbuf_type * rtbuf_type_define (const char *name, unsigned int size)
 {
   s_rtbuf_type *found = rtbuf_type_find(name);
-  if (found && found->t.bits == size * 8)
+  if (found && found->t.bytes == size)
     return found;
   return rtbuf_type_new(name, size);
 }
@@ -126,7 +126,7 @@ s_rtbuf_type * rtbuf_type_parse_array (const char *name)
       return 0;
     buf[rb] = 0;
     size = atoi(&buf[lb + 1]);
-    return rtbuf_type_new(name, (element_type->t.bits + 7) / 8 * size);
+    return rtbuf_type_new(name, element_type->t.bytes * size);
   }
   return 0;
 }
diff --git a/librtbuf/rtbuf_var.c b/librtbuf/rtbuf_var.c
index a96fc6e..d94f72e 100644
--- a/librtbuf/rtbuf_var.c
+++ b/librtbuf/rtbuf_var.c
@@ -21,8 +21,8 @@
 #include "rtbuf.h"
 
 s_data_type  g_rtbuf_var_type = {
-  sizeof(s_rtbuf_var) * 8,
-  DATA_TYPE_BITS
+  sizeof(s_rtbuf_var),
+  DATA_TYPE_BYTES
 };
 s_data_alloc g_rtbuf_var_alloc;
 s_rtbuf_var *g_rtbuf_var;