OSSP CVS Repository

ossp - Check-in [4165]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4165
Date: 2001-Jul-08 17:22:00 (local)
2001-Jul-08 15:22:00 (UTC)
User:simons
Branch:
Comment: xds_find_engine() can now handle a NULL pointer for "engines" as long as "last" is set correctly to 0. This is necessary so that we don't have to allocate an array before we actually have any entries.
Tickets:
Inspections:
Files:
ossp-pkg/xds/destroy.c      1.4 -> 1.5     4 inserted, 1 deleted
ossp-pkg/xds/find-engine.c      1.1 -> 1.2     1 inserted, 3 deleted
ossp-pkg/xds/init.c      1.3 -> 1.4     0 inserted, 10 deleted
ossp-pkg/xds/register.c      1.1 -> 1.2     53 inserted, 1 deleted
ossp-pkg/xds/regression-tests/Makefile      1.4 -> 1.5     1 inserted, 1 deleted

ossp-pkg/xds/destroy.c 1.4 -> 1.5

--- destroy.c    2001/07/08 14:21:08     1.4
+++ destroy.c    2001/07/08 15:22:00     1.5
@@ -39,6 +39,9 @@
 
     /* Free allocated memory. */
 
-    free(xds->engines);
+    assert(xds->engines != NULL || xds->engines_capacity == 0);
+    if (xds->engines != NULL)
+        free(xds->engines);
+
     free(xds);
     }


ossp-pkg/xds/find-engine.c 1.1 -> 1.2

--- find-engine.c        2001/07/08 14:10:32     1.1
+++ find-engine.c        2001/07/08 15:22:00     1.2
@@ -35,11 +35,9 @@
 
     /* Sanity checks. */
 
-    assert(engines != NULL);
+    assert(engines != NULL || last == 0);
     assert(name != NULL);
     assert(pos != NULL);
-    if (engines == NULL || name == NULL || pos == NULL)
-        return XDS_ERR_INVALID_ARG;
 
     /* Use binary search to find "name" in "engines". */
 


ossp-pkg/xds/init.c 1.3 -> 1.4

--- init.c       2001/07/08 14:21:08     1.3
+++ init.c       2001/07/08 15:22:00     1.4
@@ -53,16 +53,6 @@
 
     ctx->mode = mode;
 
-    /* Allocate engines array. */
-
-    ctx->engines = calloc(32, sizeof(engine_map_t));
-    if (ctx->engines == NULL)
-        {
-        free(ctx);
-        return NULL;
-        }
-    ctx->engines_capacity = 32;
-
     /* We are initialized. */
 
     return ctx;


ossp-pkg/xds/register.c 1.1 -> 1.2

--- register.c   2001/07/04 15:58:51     1.1
+++ register.c   2001/07/08 15:22:00     1.2
@@ -25,9 +25,61 @@
    SUCH DAMAGE.
 */
 
+#include <stdio.h>              /* delete me */
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
 #include "internal.h"
 
 int xds_register(xds_t* xds, const char* name, xds_engine_t engine, void* engine_context)
     {
-    return XDS_ERR_INVALID_ARG;
+    size_t pos;
+
+    printf("*** Inserting '%s' ...\n", name);
+    printf("Before the insertion:\n");
+    for (pos = 0; pos < xds->engines_len; ++pos)
+        printf("\tengines[%d] = '%s'\n", pos, xds->engines[pos].name);
+
+    /* Sanity checks. */
+
+    assert(xds != NULL);
+    assert(name != NULL);
+    assert(engine != NULL);
+    if (xds == NULL || name == NULL || engine == NULL)
+        return XDS_ERR_INVALID_ARG;
+
+    /* Copy the name argument into our own memory. */
+
+    name = strdup(name);
+    if (name == NULL)
+        return XDS_ERR_NO_MEM;
+
+    /* Search engines for the entry. */
+
+    if (xds_find_engine(xds->engines, xds->engines_len, name, &pos))
+        {                       /* overwrite existing entry */
+        free(xds->engines[pos].name);
+        }
+    else
+        {                       /* insert new entry */
+        xds_set_capacity((void**)&xds->engines, &xds->engines_capacity, xds->engines_len + 1, sizeof(engine_map_t), 1);
+        memmove(&xds->engines[pos+1], &xds->engines[pos], (xds->engines_len - pos) * sizeof(engine_map_t));
+        ++xds->engines_len;
+        }
+
+    /* Insert entry. */
+
+    xds->engines[pos].name    = (char*)name;
+    xds->engines[pos].engine  = engine;
+    xds->engines[pos].context = engine_context;
+
+    printf("After the insertion:\n");
+    for (pos = 0; pos < xds->engines_len; ++pos)
+        printf("\tengines[%d] = '%s'\n", pos, xds->engines[pos].name);
+    printf("\n");
+
+    /* Everything is fine. */
+
+    return XDS_OK;
     }


ossp-pkg/xds/regression-tests/Makefile 1.4 -> 1.5

--- Makefile     2001/07/08 14:05:03     1.4
+++ Makefile     2001/07/08 15:22:00     1.5
@@ -8,7 +8,7 @@
 CFLAGS          =
 LDFLAGS         = -L..
 
-TESTS           = xds-core.exe xds-find-engine.exe xds-register.exe
+TESTS           = xds-core.exe xds-find-engine.exe xds-register.exe xds-callback-semantics.exe
 
 .SUFFIXES:
 .SUFFIXES:      .c .exe

CVSTrac 2.0.1