From: Robert Haas Date: Wed, 11 Jun 2014 21:21:47 +0000 (-0400) Subject: Get test_balloc to compile again. X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=8117118f2de965de6d1e9e30a8aa50622df19485;p=users%2Frhaas%2Fpostgres.git Get test_balloc to compile again. --- diff --git a/contrib/test_balloc/test_balloc--1.0.sql b/contrib/test_balloc/test_balloc--1.0.sql index dd2e8b4e20..dda88a9ca7 100644 --- a/contrib/test_balloc/test_balloc--1.0.sql +++ b/contrib/test_balloc/test_balloc--1.0.sql @@ -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; diff --git a/contrib/test_balloc/test_balloc.c b/contrib/test_balloc/test_balloc.c index e1a6ff1a47..eedeb7e473 100644 --- a/contrib/test_balloc/test_balloc.c +++ b/contrib/test_balloc/test_balloc.c @@ -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(); }