Get test_balloc to compile again.
authorRobert Haas <rhaas@postgresql.org>
Wed, 11 Jun 2014 21:21:47 +0000 (17:21 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 11 Jun 2014 21:21:47 +0000 (17:21 -0400)
contrib/test_balloc/test_balloc--1.0.sql
contrib/test_balloc/test_balloc.c

index dd2e8b4e202a99e21ee6e3fd3f4f2ec944df9402..dda88a9ca708f711c69d01bdf4bd9f981536782f 100644 (file)
@@ -3,18 +3,12 @@
 -- complain if script is sourced in psql, rather than via CREATE EXTENSION
 \echo Use "CREATE EXTENSION test_balloc" to load this file. \quit
 
-CREATE FUNCTION alloc(size pg_catalog.int8, count pg_catalog.int8)
+CREATE FUNCTION alloc(size pg_catalog.int8, count pg_catalog.int8,
+                                         usenew pg_catalog.bool default true)
     RETURNS pg_catalog.void
        AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
 
-CREATE FUNCTION alloc_with_palloc(size pg_catalog.int8, count pg_catalog.int8)
-    RETURNS pg_catalog.void
-       AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
-
-CREATE FUNCTION alloc_list(size pg_catalog.int8, count pg_catalog.int8)
-    RETURNS pg_catalog.void
-       AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
-
-CREATE FUNCTION alloc_list_with_palloc(size pg_catalog.int8, count pg_catalog.int8)
+CREATE FUNCTION alloc_list(size pg_catalog.int8, count pg_catalog.int8,
+                                                  usenew pg_catalog.bool default true)
     RETURNS pg_catalog.void
        AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
index e1a6ff1a477321dc831af50db350f3ed5de72e13..eedeb7e473a010446f043e705f6db95ad0c15eba 100644 (file)
@@ -25,93 +25,52 @@ typedef struct llnode
 
 PG_MODULE_MAGIC;
 PG_FUNCTION_INFO_V1(alloc);
-PG_FUNCTION_INFO_V1(alloc_with_palloc);
 PG_FUNCTION_INFO_V1(alloc_list);
-PG_FUNCTION_INFO_V1(alloc_list_with_palloc);
 
 Datum
 alloc(PG_FUNCTION_ARGS)
 {
        int64 size = PG_GETARG_INT64(0);
        int64 count = PG_GETARG_INT64(1);
-       int64 i;
-       int64 *p;
-       BlockAllocatorContext *context;
-
-       context = BlockAllocatorContextCreate();
-       for (i = 0; i < count; ++i)
-       {
-               p = BlockAllocatorAlloc(context, size, 0);
-               *p = i;
-       }
-       BlockAllocatorReset(context);
-       DumpAllocatorRegions();
-
-       PG_RETURN_VOID();
-}
-
-Datum
-alloc_with_palloc(PG_FUNCTION_ARGS)
-{
-       int64 size = PG_GETARG_INT64(0);
-       int64 count = PG_GETARG_INT64(1);
+       bool  usenew = PG_GETARG_INT64(2);
        int64 i;
        int64 *p;
        MemoryContext context;
 
-       context = AllocSetContextCreate(CurrentMemoryContext,
-                                                                   "alloc_with_palloc test",
-                                                                   ALLOCSET_DEFAULT_MINSIZE,
-                                                                   ALLOCSET_DEFAULT_INITSIZE,
-                                                                   ALLOCSET_DEFAULT_MAXSIZE);
+       if (usenew)
+               context = BlockAllocatorContextCreate(CurrentMemoryContext, "test");
+       else
+               context = AllocSetContextCreate(CurrentMemoryContext,
+                                                                           "alloc test",
+                                                                           ALLOCSET_DEFAULT_MINSIZE,
+                                                                           ALLOCSET_DEFAULT_INITSIZE,
+                                                                           ALLOCSET_DEFAULT_MAXSIZE);
+
        for (i = 0; i < count; ++i)
        {
                p = MemoryContextAlloc(context, size);
                *p = i;
        }
-       MemoryContextStats(context);
-       MemoryContextDelete(context);
-
-       PG_RETURN_VOID();
-}
-
-Datum
-alloc_list(PG_FUNCTION_ARGS)
-{
-       int64 size = PG_GETARG_INT64(0);
-       int64 count = PG_GETARG_INT64(1);
-       int64 i;
-       llnode *h = NULL;
-       llnode *p;
-       BlockAllocatorContext *context;
-
-       if (size < sizeof(llnode))
-               elog(ERROR, "size too small");
-
-       context = BlockAllocatorContextCreate();
-       for (i = 0; i < count; ++i)
+       if (usenew)
        {
-               p = BlockAllocatorAlloc(context, size, 0);
-               p->next = h;
-               h = p;
+               BlockAllocatorReset(context);
+               DumpAllocatorRegions();
        }
-       while (h != NULL)
+       else
        {
-               p = h->next;
-               BlockAllocatorFree(h);
-               h = p;
+               MemoryContextStats(context);
+               MemoryContextDelete(context);
        }
-       DumpAllocatorRegions();
-       BlockAllocatorReset(context);
 
        PG_RETURN_VOID();
 }
 
 Datum
-alloc_list_with_palloc(PG_FUNCTION_ARGS)
+alloc_list(PG_FUNCTION_ARGS)
 {
        int64 size = PG_GETARG_INT64(0);
        int64 count = PG_GETARG_INT64(1);
+       bool  usenew = PG_GETARG_INT64(2);
        int64 i;
        llnode *h = NULL;
        llnode *p;
@@ -120,11 +79,15 @@ alloc_list_with_palloc(PG_FUNCTION_ARGS)
        if (size < sizeof(llnode))
                elog(ERROR, "size too small");
 
-       context = AllocSetContextCreate(CurrentMemoryContext,
-                                                                   "alloc_list_with_palloc test",
-                                                                   ALLOCSET_DEFAULT_MINSIZE,
-                                                                   ALLOCSET_DEFAULT_INITSIZE,
-                                                                   ALLOCSET_DEFAULT_MAXSIZE);
+       if (usenew)
+               context = BlockAllocatorContextCreate(CurrentMemoryContext, "test");
+       else
+               context = AllocSetContextCreate(CurrentMemoryContext,
+                                                                           "alloc test",
+                                                                           ALLOCSET_DEFAULT_MINSIZE,
+                                                                           ALLOCSET_DEFAULT_INITSIZE,
+                                                                           ALLOCSET_DEFAULT_MAXSIZE);
+
        for (i = 0; i < count; ++i)
        {
                p = MemoryContextAlloc(context, size);
@@ -137,8 +100,16 @@ alloc_list_with_palloc(PG_FUNCTION_ARGS)
                pfree(h);
                h = p;
        }
-       MemoryContextStats(context);
-       MemoryContextDelete(context);
+       if (usenew)
+       {
+               DumpAllocatorRegions();
+               BlockAllocatorReset(context);
+       }
+       else
+       {
+               MemoryContextStats(context);
+               MemoryContextDelete(context);
+       }
 
        PG_RETURN_VOID();
 }