gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: PQ: update libgnunetpq implementation to


From: gnunet
Subject: [gnunet] branch master updated: PQ: update libgnunetpq implementation to avoid duplicated nullable tests and to allow for the actual field name to differ from the fname, as done for example by the Taler amounts which are split over two DB fields
Date: Wed, 16 Jun 2021 17:12:18 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 1bc1fbda0 PQ: update libgnunetpq implementation to avoid duplicated 
nullable tests and to allow for the actual field name to differ from the fname, 
as done for example by the Taler amounts which are split over two DB fields
1bc1fbda0 is described below

commit 1bc1fbda00a9e31d2256c52b29a2c758b7818268
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Jun 16 17:09:22 2021 +0200

    PQ: update libgnunetpq implementation to avoid duplicated nullable tests 
and to allow for the actual field name to differ from the fname, as done for 
example by the Taler amounts which are split over two DB fields
---
 src/include/gnunet_pq_lib.h | 19 +++++-----
 src/pq/pq.c                 | 35 +++++++++---------
 src/pq/pq_result_helper.c   | 88 +++++++++++++++++----------------------------
 3 files changed, 59 insertions(+), 83 deletions(-)

diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index c8a648032..d7fa793ca 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -245,15 +245,16 @@ GNUNET_PQ_query_param_uint64 (const uint64_t *x);
  * @param[out] dst where to store the result
  * @return
  *   #GNUNET_YES if all results could be extracted
- *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ *   #GNUNET_NO if the field was NULL
+ *   #GNUNET_SYSERR if a result was invalid (non-existing field)
  */
-typedef int
-(*GNUNET_PQ_ResultConverter) (void *cls,
-                              PGresult *result,
-                              int row,
-                              const char *fname,
-                              size_t *dst_size,
-                              void *dst);
+typedef enum GNUNET_GenericReturnValue
+(*GNUNET_PQ_ResultConverter)(void *cls,
+                             PGresult *result,
+                             int row,
+                             const char *fname,
+                             size_t *dst_size,
+                             void *dst);
 
 
 /**
@@ -310,7 +311,7 @@ struct GNUNET_PQ_ResultSpec
    * Where to store actual size of the result.
    */
   size_t *result_size;
-  
+
   /**
    * True if NULL is allowed for a value in the database.
    */
diff --git a/src/pq/pq.c b/src/pq/pq.c
index e9c960e33..25202a640 100644
--- a/src/pq/pq.c
+++ b/src/pq/pq.c
@@ -133,34 +133,31 @@ GNUNET_PQ_extract_result (PGresult *result,
   for (unsigned int i = 0; NULL != rs[i].conv; i++)
   {
     struct GNUNET_PQ_ResultSpec *spec;
-    int ret;
+    enum GNUNET_GenericReturnValue ret;
 
     spec = &rs[i];
-    if (spec->is_nullable)
-    {
-      int fnum;
-
-      fnum = PQfnumber (result,
-                        spec->fname);
-      if (PQgetisnull (result,
-                       row,
-                       fnum))
-      {
-        if (NULL != spec->is_null)
-          *spec->is_null = true;
-        continue;
-      }
-      if (NULL != spec->is_null)
-        *spec->is_null = false;
-    }
     ret = spec->conv (spec->cls,
                       result,
                       row,
                       spec->fname,
                       &spec->dst_size,
                       spec->dst);
-    if (GNUNET_OK != ret)
+    switch (ret)
     {
+    case GNUNET_OK:
+      /* canonical case, continue below */
+      if (NULL != spec->is_null)
+        *spec->is_null = false;
+      break;
+    case GNUNET_NO:
+      if (spec->is_nullable)
+      {
+        if (NULL != spec->is_null)
+          *spec->is_null = true;
+        continue;
+      }
+    /* intentional fall-through: NULL value for field that is NOT nullable */
+    case GNUNET_SYSERR:
       for (unsigned int j = 0; j < i; j++)
         if (NULL != rs[j].cleaner)
           rs[j].cleaner (rs[j].cls,
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 204ccee72..23fb4f96e 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -75,7 +75,7 @@ clean_varsize_blob (void *cls,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_varsize_blob (void *cls,
                       PGresult *result,
                       int row,
@@ -102,10 +102,7 @@ extract_varsize_blob (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    /* Let's allow this for varsize */
-    return GNUNET_OK;
-  }
+    return GNUNET_NO;
   /* if a field is null, continue but
    * remember that we now return a different result */
   len = PQgetlength (result,
@@ -152,7 +149,7 @@ GNUNET_PQ_result_spec_variable_size (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_fixed_blob (void *cls,
                     PGresult *result,
                     int row,
@@ -178,11 +175,7 @@ extract_fixed_blob (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-
+    return GNUNET_NO;
   /* if a field is null, continue but
    * remember that we now return a different result */
   len = PQgetlength (result,
@@ -236,7 +229,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_rsa_public_key (void *cls,
                         PGresult *result,
                         int row,
@@ -261,10 +254,8 @@ extract_rsa_public_key (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
+
   /* if a field is null, continue but
    * remember that we now return a different result */
   len = PQgetlength (result,
@@ -333,7 +324,7 @@ GNUNET_PQ_result_spec_rsa_public_key (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_rsa_signature (void *cls,
                        PGresult *result,
                        int row,
@@ -358,10 +349,7 @@ extract_rsa_signature (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   /* if a field is null, continue but
    * remember that we now return a different result */
   len = PQgetlength (result,
@@ -430,7 +418,7 @@ GNUNET_PQ_result_spec_rsa_signature (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_string (void *cls,
                 PGresult *result,
                 int row,
@@ -455,10 +443,7 @@ extract_string (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   /* if a field is null, continue but
    * remember that we now return a different result */
   len = PQgetlength (result,
@@ -527,7 +512,7 @@ GNUNET_PQ_result_spec_string (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_rel_time (void *cls,
                   PGresult *result,
                   int row,
@@ -550,10 +535,7 @@ extract_rel_time (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   GNUNET_assert (NULL != dst);
   if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
   {
@@ -610,7 +592,7 @@ GNUNET_PQ_result_spec_relative_time (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_abs_time (void *cls,
                   PGresult *result,
                   int row,
@@ -633,10 +615,7 @@ extract_abs_time (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   GNUNET_assert (NULL != dst);
   if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
   {
@@ -700,7 +679,7 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_uint16 (void *cls,
                 PGresult *result,
                 int row,
@@ -723,10 +702,7 @@ extract_uint16 (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   GNUNET_assert (NULL != dst);
   if (sizeof(uint16_t) != *dst_size)
   {
@@ -776,7 +752,7 @@ GNUNET_PQ_result_spec_uint16 (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_uint32 (void *cls,
                 PGresult *result,
                 int row,
@@ -799,10 +775,7 @@ extract_uint32 (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
   GNUNET_assert (NULL != dst);
   if (sizeof(uint32_t) != *dst_size)
   {
@@ -829,11 +802,15 @@ struct GNUNET_PQ_ResultSpec
 GNUNET_PQ_result_spec_uint32 (const char *name,
                               uint32_t *u32)
 {
-  struct GNUNET_PQ_ResultSpec res =
-  { &extract_uint32,
+  struct GNUNET_PQ_ResultSpec res = {
+    &extract_uint32,
     NULL,
     NULL,
-    (void *) u32, sizeof(*u32), (name), NULL };
+    (void *) u32,
+    sizeof(*u32),
+    (name),
+    NULL
+  };
 
   return res;
 }
@@ -852,7 +829,7 @@ GNUNET_PQ_result_spec_uint32 (const char *name,
  *   #GNUNET_YES if all results could be extracted
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
-static int
+static enum GNUNET_GenericReturnValue
 extract_uint64 (void *cls,
                 PGresult *result,
                 int row,
@@ -878,10 +855,8 @@ extract_uint64 (void *cls,
   if (PQgetisnull (result,
                    row,
                    fnum))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    return GNUNET_NO;
+
   GNUNET_assert (NULL != dst);
   if (sizeof(uint64_t) != *dst_size)
   {
@@ -912,7 +887,10 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
     &extract_uint64,
     NULL,
     NULL,
-    (void *) u64, sizeof(*u64), (name), NULL
+    (void *) u64,
+    sizeof(*u64),
+    (name),
+    NULL
   };
 
   return res;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]