Fixes 32 bit compile issue, #135
authorJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 10 Sep 2020 13:37:15 +0000 (15:37 +0200)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 10 Sep 2020 13:37:15 +0000 (15:37 +0200)
include/llist/llist.h
include/siri/db/query.h
include/siri/grammar/gramp.h
include/siri/inc.h [new file with mode: 0644]
include/siri/version.h
src/llist/llist.c
src/siri/db/query.c

index e5c57250f1f9761635d526b57a53133d896a7f30..b49bc6fe509b7c8f850e27ffb4ac56be9ab73941 100644 (file)
@@ -11,9 +11,11 @@ typedef struct llist_node_s llist_node_t;
 #include <vec/vec.h>
 
 typedef int (*llist_cb)(void * data, void * args);
+typedef void (*llist_destroy_cb)(void * data);
 
 llist_t * llist_new(void);
 void llist_free_cb(llist_t * llist, llist_cb cb, void * args);
+void llist_destroy(llist_t * llist, llist_destroy_cb cb);
 int llist_append(llist_t * llist, void * data);
 int llist_walk(llist_t * llist, llist_cb cb, void * args);
 void llist_walkn(llist_t * llist, size_t * n, llist_cb cb, void * args);
index fbe2ef761dd1ca714001d369c5d5275d3b32f648..b7f8971f9bd32dbf5a03f1fc916381ab18512861 100644 (file)
@@ -44,6 +44,11 @@ typedef struct siridb_query_s siridb_query_t;
 #include <siri/db/series.h>
 #include <siri/db/db.h>
 #include <siri/net/protocol.h>
+#include <siri/inc.h>
+
+#if SIRIDB_EXPR_ALLOC
+#include <llist/llist.h>
+#endif
 
 void siridb_query_run(
         uint16_t pid,
@@ -83,6 +88,9 @@ struct siridb_query_s
     cleri_parse_t * pr;
     siridb_nodes_t * nodes;
     struct timespec start;
+#if SIRIDB_EXPR_ALLOC
+    llist_t * expr_cache;
+#endif
 };
 
 #endif  /* SIRIDB_QUERY_H_ */
index 1c1826f90dd84b0abb4bc901ae93d9eaae80cb92..f2796951c1d47b90be9c42457b185d091b06bac2 100644 (file)
 
 
 #if CLERI_VERSION_MINOR >= 12
+#if SIRIDB_IS64BIT
 #define CLERI_NODE_DATA(__node) ((int64_t)(__node)->data)
 #define CLERI_NODE_DATA_ADDR(__node) ((int64_t *) &(__node)->data)
 #else
+#define CLERI_NODE_DATA(__node) *((int64_t *)(__node)->data)
+#define CLERI_NODE_DATA_ADDR(__node) ((int64_t *)(__node)->data)
+#endif
+#else
 #define CLERI_NODE_DATA(__node) (__node)->result
 #define CLERI_NODE_DATA_ADDR(__node) &(__node)->result
 #endif
diff --git a/include/siri/inc.h b/include/siri/inc.h
new file mode 100644 (file)
index 0000000..c55c7c1
--- /dev/null
@@ -0,0 +1,14 @@
+#if UINTPTR_MAX == 0xffffffff
+#define SIRIDB_IS64BIT 0
+#elif UINTPTR_MAX == 0xffffffffffffffff
+#define SIRIDB_IS64BIT 1
+#else
+#define SIRIDB_IS64BIT __WORDSIZE == 64
+#endif
+
+
+#if SIRIDB_IS64BIT
+#define SIRIDB_EXPR_ALLOC 0
+#else
+#define SIRIDB_EXPR_ALLOC CLERI_VERSION_MINOR >= 12
+#endif
index ac332a3943f5ee1ea5b6f4632fd0b06a91c4d780..26b90996afe8cc7fe5e0f4021096dad3197226b7 100644 (file)
@@ -6,7 +6,7 @@
 
 #define SIRIDB_VERSION_MAJOR 2
 #define SIRIDB_VERSION_MINOR 0
-#define SIRIDB_VERSION_PATCH 38
+#define SIRIDB_VERSION_PATCH 39
 
 /*
  * Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions.
@@ -15,7 +15,7 @@
  * Note that debian alpha packages should use versions like this:
  *   2.0.34-0alpha0
  */
-#define SIRIDB_VERSION_PRE_RELEASE ""
+#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0"
 
 #ifndef NDEBUG
 #define SIRIDB_VERSION_BUILD_RELEASE "+debug"
index 893ed3630d736abcf5819199fb10e14b91d8bdfc..adb8aa91e8095d1539c499781d20971b3555d6eb 100644 (file)
@@ -42,6 +42,25 @@ void llist_free_cb(llist_t * llist, llist_cb cb, void * args)
     free(llist);
 }
 
+/*
+ * Destroys the linked list and calls a call-back function on each item.
+ * The result of the call back function will be ignored.
+ */
+void llist_destroy(llist_t * llist, llist_destroy_cb cb)
+{
+    llist_node_t * node = llist->first;
+    llist_node_t * next;
+
+    while (node != NULL)
+    {
+        cb(node->data);
+        next = node->next;
+        free(node);
+        node = next;
+    }
+    free(llist);
+}
+
 /*
  * Appends to the end of the list.
  *
index ae744d09aed227349f009cf1f3dc1ee0d046097a..941614a748f2c215710410ff00a835c68bf352a7 100644 (file)
 #include <sys/time.h>
 #include <siri/err.h>
 
+#if SIRIDB_EXPR_ALLOC
+#include <llist/llist.h>
+#endif
+
+
 #define QUERY_TOO_LONG -1
 #define QUERY_MAX_LENGTH 8192
 #define QUERY_EXTRA_ALLOC_SIZE 200
 
 static void QUERY_send_invalid_error(uv_async_t * handle);
 static void QUERY_parse(uv_async_t * handle);
-static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker);
+static int QUERY_walk(
+#if SIRIDB_EXPR_ALLOC
+        siridb_query_t * query,
+#endif
+        cleri_node_t * node,
+        siridb_walker_t * walker);
 static int QUERY_to_packer(qp_packer_t * packer, siridb_query_t * query);
 static int QUERY_time_expr(
         cleri_node_t * node,
@@ -82,6 +92,17 @@ void siridb_query_run(
         return;
     }
 
+    #if SIRIDB_EXPR_ALLOC
+    if ((query->expr_cache = llist_new()) == NULL)
+    {
+        ERR_ALLOC
+        free(query->q);
+        free(query);
+        free(handle);
+        return;
+    }
+    #endif
+
     /*
      * Set start time.
      * (must be real time since we translate now with this value)
@@ -160,6 +181,13 @@ void siridb_query_free(uv_handle_t * handle)
         cleri_parse_free(query->pr);
     }
 
+    #if SIRIDB_EXPR_ALLOC
+    if (query->expr_cache != NULL)
+    {
+        llist_destroy(query->expr_cache, (llist_destroy_cb) free);
+    }
+    #endif
+
     /* decrement client reference counter */
     sirinet_stream_decref(query->client);
 
@@ -589,6 +617,9 @@ static void QUERY_parse(uv_async_t * handle)
     }
 
     if ((rc = QUERY_walk(
+#if SIRIDB_EXPR_ALLOC
+            query,
+#endif
             query->pr->tree->children->node,
             walker)))
     {
@@ -678,7 +709,12 @@ static int QUERY_to_packer(qp_packer_t * packer, siridb_query_t * query)
     return 0;
 }
 
-static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker)
+static int QUERY_walk(
+#if SIRIDB_EXPR_ALLOC
+        siridb_query_t * query,
+#endif
+        cleri_node_t * node,
+        siridb_walker_t * walker)
 {
     int rc;
     uint32_t gid;
@@ -723,6 +759,18 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker)
         /* terminate buffer */
         buffer[EXPR_MAX_SIZE - size] = 0;
 
+        #if SIRIDB_EXPR_ALLOC
+        {
+            int64_t * itmp = malloc(sizeof(int64_t));
+            if (itmp == NULL || llist_append(query->expr_cache, itmp))
+            {
+                free(itmp);
+                return EXPR_MEM_ALLOC_ERR;
+            }
+            node->data = itmp;
+        }
+        #endif
+
         /* evaluate the expression */
         if ((rc = expr_parse(CLERI_NODE_DATA_ADDR(node), buffer)))
         {
@@ -751,6 +799,18 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker)
         /* terminate buffer */
         buffer[EXPR_MAX_SIZE - size] = 0;
 
+        #if SIRIDB_EXPR_ALLOC
+        {
+            int64_t * itmp = malloc(sizeof(int64_t));
+            if (itmp == NULL || llist_append(query->expr_cache, itmp))
+            {
+                free(itmp);
+                return EXPR_MEM_ALLOC_ERR;
+            }
+            node->data = itmp;
+        }
+        #endif
+
         /* evaluate the expression */
         if ((rc = expr_parse(CLERI_NODE_DATA_ADDR(node), buffer)))
         {
@@ -770,7 +830,12 @@ static int QUERY_walk(cleri_node_t * node, siridb_walker_t * walker)
             {
                 current = current->node->children;
             }
-            if ((rc = QUERY_walk(current->node, walker)))
+            if ((rc = QUERY_walk(
+#if SIRIDB_EXPR_ALLOC
+                    query,
+#endif
+                    current->node,
+                    walker)))
             {
                 return rc;
             }