From 7359c987f8876e55cabe50326f560daf9524bf92 Mon Sep 17 00:00:00 2001
From: "Lucas A. M. Magalhaes" <lucas.magalhaes@ess.eu>
Date: Wed, 2 Aug 2023 10:47:14 +0200
Subject: [PATCH] Simplify getRecordHandle

First change is to remove minsize, we don't need to calculate the size
previously anymore as we don't change the pfield directly.
Also, remove the get_array_info call. This was mandatory to be able to
update the pfield, we don't do it anymore.
---
 require-ess/src/require.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/require-ess/src/require.c b/require-ess/src/require.c
index b4be07c4..eed0ce0d 100644
--- a/require-ess/src/require.c
+++ b/require-ess/src/require.c
@@ -171,11 +171,8 @@ static int setupDbPath(const char *module, const char *dbdir) {
   return 0;
 }
 
-static int getRecordHandle(const char *namepart, short type, long minsize,
-                           DBADDR *paddr) {
+static int getRecordHandle(const char *namepart, short type, DBADDR *paddr) {
   char recordname[PVNAME_STRINGSZ] = {0};
-  long dummy = 0L;
-  long offset = 0L;
 
   sprintf(recordname, "%.*s%s", (int)(PVNAME_STRINGSZ - strnlen(namepart, PVNAME_STRINGSZ-1) - 1),
           getenv("REQUIRE_IOC"), namepart);
@@ -193,13 +190,6 @@ static int getRecordHandle(const char *namepart, short type, long minsize,
         pamapdbfType[type].strvalue);
     return -1;
   }
-  if (paddr->no_elements < minsize) {
-    fprintf(stderr,
-            "require:getRecordHandle : record %s has not enough elements: %lu "
-            "instead of %lu\n",
-            recordname, paddr->no_elements, minsize);
-    return -1;
-  }
   if (paddr->pfield == NULL) {
     fprintf(
         stderr,
@@ -208,9 +198,6 @@ static int getRecordHandle(const char *namepart, short type, long minsize,
     return -1;
   }
 
-  /* update array information */
-  dbGetRset(paddr)->get_array_info(paddr, &dummy, &offset);
-
   return 0;
 }
 
@@ -229,9 +216,9 @@ static void fillModuleListRecord(initHookState state) {
   int i = 0;
   int c = 0;
 
-  getRecordHandle(":Modules", DBF_STRING, 0, &modules);
-  getRecordHandle(":Versions", DBF_STRING, 0, &versions);
-  getRecordHandle(":ModuleVersions", DBF_CHAR, 0, &modver);
+  getRecordHandle(":Modules", DBF_STRING, &modules);
+  getRecordHandle(":Versions", DBF_STRING, &versions);
+  getRecordHandle(":ModuleVersions", DBF_CHAR, &modver);
 
   bufferModules = (char *)calloc(MAX_STRING_SIZE*loadedModules.size, sizeof(char));
   bufferVersions = (char *)calloc(MAX_STRING_SIZE*loadedModules.size, sizeof(char));
-- 
GitLab