mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* aset.c--
|
||||
* Allocation set definitions.
|
||||
* Allocation set definitions.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.5 1997/08/19 21:35:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.6 1997/09/07 04:54:01 momjian Exp $
|
||||
*
|
||||
* NOTE
|
||||
* XXX This is a preliminary implementation which lacks fail-fast
|
||||
* XXX validity checking of arguments.
|
||||
* XXX This is a preliminary implementation which lacks fail-fast
|
||||
* XXX validity checking of arguments.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "postgres.h"
|
||||
#include "utils/excid.h" /* for ExhaustedMemory */
|
||||
#include "utils/memutils.h" /* where funnction declarations go */
|
||||
#include "utils/excid.h" /* for ExhaustedMemory */
|
||||
#include "utils/memutils.h" /* where funnction declarations go */
|
||||
#ifndef HAVE_MEMMOVE
|
||||
# include <regex/utils.h>
|
||||
#include <regex/utils.h>
|
||||
#else
|
||||
# include <string.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
static void AllocPointerDump(AllocPointer pointer);
|
||||
static int AllocSetIterate(AllocSet set,
|
||||
void (*function)(AllocPointer pointer));
|
||||
static void AllocPointerDump(AllocPointer pointer);
|
||||
static int
|
||||
AllocSetIterate(AllocSet set,
|
||||
void (*function) (AllocPointer pointer));
|
||||
|
||||
#undef AllocSetReset
|
||||
#undef malloc
|
||||
@@ -39,12 +40,13 @@ static int AllocSetIterate(AllocSet set,
|
||||
|
||||
/*
|
||||
* AllocElem --
|
||||
* Allocation element.
|
||||
* Allocation element.
|
||||
*/
|
||||
typedef struct AllocElemData {
|
||||
OrderedElemData elemData; /* elem in AllocSet */
|
||||
Size size;
|
||||
} AllocElemData;
|
||||
typedef struct AllocElemData
|
||||
{
|
||||
OrderedElemData elemData; /* elem in AllocSet */
|
||||
Size size;
|
||||
} AllocElemData;
|
||||
|
||||
typedef AllocElemData *AllocElem;
|
||||
|
||||
@@ -55,21 +57,21 @@ typedef AllocElemData *AllocElem;
|
||||
|
||||
/*
|
||||
* AllocPointerGetAllocElem --
|
||||
* Returns allocation (internal) elem given (external) pointer.
|
||||
* Returns allocation (internal) elem given (external) pointer.
|
||||
*/
|
||||
#define AllocPointerGetAllocElem(pointer) (&((AllocElem)(pointer))[-1])
|
||||
#define AllocPointerGetAllocElem(pointer) (&((AllocElem)(pointer))[-1])
|
||||
|
||||
/*
|
||||
* AllocElemGetAllocPointer --
|
||||
* Returns allocation (external) pointer given (internal) elem.
|
||||
* Returns allocation (external) pointer given (internal) elem.
|
||||
*/
|
||||
#define AllocElemGetAllocPointer(alloc) ((AllocPointer)&(alloc)[1])
|
||||
#define AllocElemGetAllocPointer(alloc) ((AllocPointer)&(alloc)[1])
|
||||
|
||||
/*
|
||||
* AllocElemIsValid --
|
||||
* True iff alloc is valid.
|
||||
* True iff alloc is valid.
|
||||
*/
|
||||
#define AllocElemIsValid(alloc) PointerIsValid(alloc)
|
||||
#define AllocElemIsValid(alloc) PointerIsValid(alloc)
|
||||
|
||||
/* non-export function prototypes */
|
||||
static AllocPointer AllocSetGetFirst(AllocSet set);
|
||||
@@ -79,242 +81,250 @@ static AllocPointer AllocPointerGetNext(AllocPointer pointer);
|
||||
* Public routines
|
||||
*/
|
||||
|
||||
/*
|
||||
* AllocPointerIsValid(pointer)
|
||||
* AllocSetIsValid(set)
|
||||
/*
|
||||
* AllocPointerIsValid(pointer)
|
||||
* AllocSetIsValid(set)
|
||||
*
|
||||
* .. are now macros in aset.h -cim 4/27/91
|
||||
* .. are now macros in aset.h -cim 4/27/91
|
||||
*/
|
||||
|
||||
/*
|
||||
* AllocSetInit --
|
||||
* Initializes given allocation set.
|
||||
* Initializes given allocation set.
|
||||
*
|
||||
* Note:
|
||||
* The semantics of the mode are explained above. Limit is ignored
|
||||
* for dynamic and static modes.
|
||||
* The semantics of the mode are explained above. Limit is ignored
|
||||
* for dynamic and static modes.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid pointer.
|
||||
* BadArg if mode is invalid.
|
||||
* BadArg if set is invalid pointer.
|
||||
* BadArg if mode is invalid.
|
||||
*/
|
||||
void
|
||||
AllocSetInit(AllocSet set, AllocMode mode, Size limit)
|
||||
{
|
||||
AssertArg(PointerIsValid(set));
|
||||
AssertArg((int)DynamicAllocMode <= (int)mode);
|
||||
AssertArg((int)mode <= (int)BoundedAllocMode);
|
||||
|
||||
/*
|
||||
* XXX mode is currently ignored and treated as DynamicAllocMode.
|
||||
* XXX limit is also ignored. This affects this whole file.
|
||||
*/
|
||||
|
||||
OrderedSetInit(&set->setData, offsetof(AllocElemData, elemData));
|
||||
AssertArg(PointerIsValid(set));
|
||||
AssertArg((int) DynamicAllocMode <= (int) mode);
|
||||
AssertArg((int) mode <= (int) BoundedAllocMode);
|
||||
|
||||
/*
|
||||
* XXX mode is currently ignored and treated as DynamicAllocMode. XXX
|
||||
* limit is also ignored. This affects this whole file.
|
||||
*/
|
||||
|
||||
OrderedSetInit(&set->setData, offsetof(AllocElemData, elemData));
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetReset --
|
||||
* Frees memory which is allocated in the given set.
|
||||
* Frees memory which is allocated in the given set.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if set is invalid.
|
||||
*/
|
||||
void
|
||||
AllocSetReset(AllocSet set)
|
||||
{
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
while (AllocPointerIsValid(pointer = AllocSetGetFirst(set))) {
|
||||
AllocSetFree(set, pointer);
|
||||
}
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
while (AllocPointerIsValid(pointer = AllocSetGetFirst(set)))
|
||||
{
|
||||
AllocSetFree(set, pointer);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
void
|
||||
AllocSetReset_debug(char *file, int line, AllocSet set)
|
||||
{
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
while (AllocPointerIsValid(pointer = AllocSetGetFirst(set))) {
|
||||
AllocSetFree(set, pointer);
|
||||
}
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
while (AllocPointerIsValid(pointer = AllocSetGetFirst(set)))
|
||||
{
|
||||
AllocSetFree(set, pointer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* AllocSetContains --
|
||||
* True iff allocation set contains given allocation element.
|
||||
* True iff allocation set contains given allocation element.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
*/
|
||||
bool
|
||||
AllocSetContains(AllocSet set, AllocPointer pointer)
|
||||
{
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
AssertArg(AllocPointerIsValid(pointer));
|
||||
|
||||
return (OrderedSetContains(&set->setData,
|
||||
&AllocPointerGetAllocElem(pointer)->elemData));
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
AssertArg(AllocPointerIsValid(pointer));
|
||||
|
||||
return (OrderedSetContains(&set->setData,
|
||||
&AllocPointerGetAllocElem(pointer)->elemData));
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetAlloc --
|
||||
* Returns pointer to allocated memory of given size; memory is added
|
||||
* to the set.
|
||||
* Returns pointer to allocated memory of given size; memory is added
|
||||
* to the set.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* MemoryExhausted if allocation fails.
|
||||
* BadArg if set is invalid.
|
||||
* MemoryExhausted if allocation fails.
|
||||
*/
|
||||
AllocPointer
|
||||
AllocSetAlloc(AllocSet set, Size size)
|
||||
{
|
||||
AllocElem alloc;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
/* allocate */
|
||||
alloc = (AllocElem)malloc(sizeof (*alloc) + size);
|
||||
|
||||
if (!PointerIsValid(alloc)) {
|
||||
elog (FATAL, "palloc failure: memory exhausted");
|
||||
}
|
||||
|
||||
/* add to allocation list */
|
||||
OrderedElemPushInto(&alloc->elemData, &set->setData);
|
||||
|
||||
/* set size */
|
||||
alloc->size = size;
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
AllocElem alloc;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
/* allocate */
|
||||
alloc = (AllocElem) malloc(sizeof(*alloc) + size);
|
||||
|
||||
if (!PointerIsValid(alloc))
|
||||
{
|
||||
elog(FATAL, "palloc failure: memory exhausted");
|
||||
}
|
||||
|
||||
/* add to allocation list */
|
||||
OrderedElemPushInto(&alloc->elemData, &set->setData);
|
||||
|
||||
/* set size */
|
||||
alloc->size = size;
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetFree --
|
||||
* Frees allocated memory; memory is removed from the set.
|
||||
* Frees allocated memory; memory is removed from the set.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
* BadArg if pointer is not member of set.
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
* BadArg if pointer is not member of set.
|
||||
*/
|
||||
void
|
||||
AllocSetFree(AllocSet set, AllocPointer pointer)
|
||||
{
|
||||
AllocElem alloc;
|
||||
|
||||
/* AssertArg(AllocSetIsValid(set)); */
|
||||
/* AssertArg(AllocPointerIsValid(pointer)); */
|
||||
AssertArg(AllocSetContains(set, pointer));
|
||||
|
||||
alloc = AllocPointerGetAllocElem(pointer);
|
||||
|
||||
/* remove from allocation set */
|
||||
OrderedElemPop(&alloc->elemData);
|
||||
|
||||
/* free storage */
|
||||
free(alloc);
|
||||
AllocElem alloc;
|
||||
|
||||
/* AssertArg(AllocSetIsValid(set)); */
|
||||
/* AssertArg(AllocPointerIsValid(pointer)); */
|
||||
AssertArg(AllocSetContains(set, pointer));
|
||||
|
||||
alloc = AllocPointerGetAllocElem(pointer);
|
||||
|
||||
/* remove from allocation set */
|
||||
OrderedElemPop(&alloc->elemData);
|
||||
|
||||
/* free storage */
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetRealloc --
|
||||
* Returns new pointer to allocated memory of given size; this memory
|
||||
* is added to the set. Memory associated with given pointer is copied
|
||||
* into the new memory, and the old memory is freed.
|
||||
* Returns new pointer to allocated memory of given size; this memory
|
||||
* is added to the set. Memory associated with given pointer is copied
|
||||
* into the new memory, and the old memory is freed.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
* BadArg if pointer is not member of set.
|
||||
* MemoryExhausted if allocation fails.
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if pointer is invalid.
|
||||
* BadArg if pointer is not member of set.
|
||||
* MemoryExhausted if allocation fails.
|
||||
*/
|
||||
AllocPointer
|
||||
AllocSetRealloc(AllocSet set, AllocPointer pointer, Size size)
|
||||
{
|
||||
AllocPointer newPointer;
|
||||
AllocElem alloc;
|
||||
|
||||
/* AssertArg(AllocSetIsValid(set)); */
|
||||
/* AssertArg(AllocPointerIsValid(pointer)); */
|
||||
AssertArg(AllocSetContains(set, pointer));
|
||||
|
||||
/*
|
||||
* Calling realloc(3) directly is not be possible (unless we use
|
||||
* our own hacked version of malloc) since we must keep the
|
||||
* allocations in the allocation set.
|
||||
*/
|
||||
|
||||
alloc = AllocPointerGetAllocElem(pointer);
|
||||
|
||||
/* allocate new pointer */
|
||||
newPointer = AllocSetAlloc(set, size);
|
||||
|
||||
/* fill new memory */
|
||||
memmove(newPointer, pointer, (alloc->size < size) ? alloc->size : size);
|
||||
|
||||
/* free old pointer */
|
||||
AllocSetFree(set, pointer);
|
||||
|
||||
return (newPointer);
|
||||
AllocPointer newPointer;
|
||||
AllocElem alloc;
|
||||
|
||||
/* AssertArg(AllocSetIsValid(set)); */
|
||||
/* AssertArg(AllocPointerIsValid(pointer)); */
|
||||
AssertArg(AllocSetContains(set, pointer));
|
||||
|
||||
/*
|
||||
* Calling realloc(3) directly is not be possible (unless we use our
|
||||
* own hacked version of malloc) since we must keep the allocations in
|
||||
* the allocation set.
|
||||
*/
|
||||
|
||||
alloc = AllocPointerGetAllocElem(pointer);
|
||||
|
||||
/* allocate new pointer */
|
||||
newPointer = AllocSetAlloc(set, size);
|
||||
|
||||
/* fill new memory */
|
||||
memmove(newPointer, pointer, (alloc->size < size) ? alloc->size : size);
|
||||
|
||||
/* free old pointer */
|
||||
AllocSetFree(set, pointer);
|
||||
|
||||
return (newPointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetIterate --
|
||||
* Returns size of set. Iterates through set elements calling function
|
||||
* (if valid) on each.
|
||||
* Returns size of set. Iterates through set elements calling function
|
||||
* (if valid) on each.
|
||||
*
|
||||
* Note:
|
||||
* This was written as an aid to debugging. It is intended for
|
||||
* debugging use only.
|
||||
* This was written as an aid to debugging. It is intended for
|
||||
* debugging use only.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if set is invalid.
|
||||
* BadArg if set is invalid.
|
||||
*/
|
||||
static int
|
||||
AllocSetIterate(AllocSet set,
|
||||
void (*function)(AllocPointer pointer))
|
||||
void (*function) (AllocPointer pointer))
|
||||
{
|
||||
int count = 0;
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
for (pointer = AllocSetGetFirst(set);
|
||||
AllocPointerIsValid(pointer);
|
||||
pointer = AllocPointerGetNext(pointer)) {
|
||||
|
||||
if (PointerIsValid(function)) {
|
||||
(*function)(pointer);
|
||||
int count = 0;
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
for (pointer = AllocSetGetFirst(set);
|
||||
AllocPointerIsValid(pointer);
|
||||
pointer = AllocPointerGetNext(pointer))
|
||||
{
|
||||
|
||||
if (PointerIsValid(function))
|
||||
{
|
||||
(*function) (pointer);
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
|
||||
return (count);
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
int
|
||||
AllocSetCount(AllocSet set)
|
||||
{
|
||||
int count = 0;
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
for (pointer = AllocSetGetFirst(set);
|
||||
AllocPointerIsValid(pointer);
|
||||
pointer = AllocPointerGetNext(pointer)) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
int count = 0;
|
||||
AllocPointer pointer;
|
||||
|
||||
AssertArg(AllocSetIsValid(set));
|
||||
|
||||
for (pointer = AllocSetGetFirst(set);
|
||||
AllocPointerIsValid(pointer);
|
||||
pointer = AllocPointerGetNext(pointer))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -323,45 +333,47 @@ AllocSetCount(AllocSet set)
|
||||
|
||||
/*
|
||||
* AllocSetGetFirst --
|
||||
* Returns "first" allocation pointer in a set.
|
||||
* Returns "first" allocation pointer in a set.
|
||||
*
|
||||
* Note:
|
||||
* Assumes set is valid.
|
||||
* Assumes set is valid.
|
||||
*/
|
||||
static AllocPointer
|
||||
static AllocPointer
|
||||
AllocSetGetFirst(AllocSet set)
|
||||
{
|
||||
AllocElem alloc;
|
||||
|
||||
alloc = (AllocElem)OrderedSetGetHead(&set->setData);
|
||||
|
||||
if (!AllocElemIsValid(alloc)) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
AllocElem alloc;
|
||||
|
||||
alloc = (AllocElem) OrderedSetGetHead(&set->setData);
|
||||
|
||||
if (!AllocElemIsValid(alloc))
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocPointerGetNext --
|
||||
* Returns "successor" allocation pointer.
|
||||
* Returns "successor" allocation pointer.
|
||||
*
|
||||
* Note:
|
||||
* Assumes pointer is valid.
|
||||
* Assumes pointer is valid.
|
||||
*/
|
||||
static AllocPointer
|
||||
static AllocPointer
|
||||
AllocPointerGetNext(AllocPointer pointer)
|
||||
{
|
||||
AllocElem alloc;
|
||||
|
||||
alloc = (AllocElem)
|
||||
OrderedElemGetSuccessor(&AllocPointerGetAllocElem(pointer)->elemData);
|
||||
|
||||
if (!AllocElemIsValid(alloc)) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
AllocElem alloc;
|
||||
|
||||
alloc = (AllocElem)
|
||||
OrderedElemGetSuccessor(&AllocPointerGetAllocElem(pointer)->elemData);
|
||||
|
||||
if (!AllocElemIsValid(alloc))
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (AllocElemGetAllocPointer(alloc));
|
||||
}
|
||||
|
||||
|
||||
@@ -371,22 +383,23 @@ AllocPointerGetNext(AllocPointer pointer)
|
||||
|
||||
/*
|
||||
* XXX AllocPointerDump --
|
||||
* Displays allocated pointer.
|
||||
* Displays allocated pointer.
|
||||
*/
|
||||
static void
|
||||
AllocPointerDump(AllocPointer pointer)
|
||||
{
|
||||
printf("\t%-10ld@ %0#lx\n", ((long*)pointer)[-1], (long)pointer); /* XXX */
|
||||
printf("\t%-10ld@ %0#lx\n", ((long *) pointer)[-1], (long) pointer); /* XXX */
|
||||
}
|
||||
|
||||
/*
|
||||
* AllocSetDump --
|
||||
* Displays allocated set.
|
||||
* Displays allocated set.
|
||||
*/
|
||||
void
|
||||
AllocSetDump(AllocSet set)
|
||||
{
|
||||
int count;
|
||||
count = AllocSetIterate(set, AllocPointerDump);
|
||||
printf("\ttotal %d allocations\n", count);
|
||||
int count;
|
||||
|
||||
count = AllocSetIterate(set, AllocPointerDump);
|
||||
printf("\ttotal %d allocations\n", count);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* mcxt.c--
|
||||
* POSTGRES memory context code.
|
||||
* POSTGRES memory context code.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.3 1997/08/19 21:35:57 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.4 1997/09/07 04:54:08 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <stdio.h> /* XXX for printf debugging */
|
||||
#include <stdio.h> /* XXX for printf debugging */
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
@@ -35,90 +35,93 @@
|
||||
/*
|
||||
* Global State
|
||||
*/
|
||||
static int MemoryContextEnableCount = 0;
|
||||
static int MemoryContextEnableCount = 0;
|
||||
|
||||
#define MemoryContextEnabled (MemoryContextEnableCount > 0)
|
||||
|
||||
static OrderedSetData ActiveGlobalMemorySetData; /* uninitialized */
|
||||
static OrderedSetData ActiveGlobalMemorySetData; /* uninitialized */
|
||||
|
||||
#define ActiveGlobalMemorySet (&ActiveGlobalMemorySetData)
|
||||
|
||||
/*
|
||||
* description of allocated memory representation goes here
|
||||
*/
|
||||
|
||||
#define PSIZE(PTR) (*((int32 *)(PTR) - 1))
|
||||
#define PSIZE(PTR) (*((int32 *)(PTR) - 1))
|
||||
#define PSIZEALL(PTR) (*((int32 *)(PTR) - 1) + sizeof (int32))
|
||||
#define PSIZESKIP(PTR) ((char *)((int32 *)(PTR) + 1))
|
||||
#define PSIZEFIND(PTR) ((char *)((int32 *)(PTR) - 1))
|
||||
#define PSIZESPACE(LEN) ((LEN) + sizeof (int32))
|
||||
#define PSIZESPACE(LEN) ((LEN) + sizeof (int32))
|
||||
|
||||
/*
|
||||
* AllocSizeIsValid --
|
||||
* True iff 0 < size and size <= MaxAllocSize.
|
||||
* True iff 0 < size and size <= MaxAllocSize.
|
||||
*/
|
||||
#define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize)
|
||||
#define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize)
|
||||
|
||||
/*****************************************************************************
|
||||
* GLOBAL MEMORY *
|
||||
* GLOBAL MEMORY *
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* CurrentMemoryContext --
|
||||
* Memory context for general global allocations.
|
||||
* Memory context for general global allocations.
|
||||
*/
|
||||
MemoryContext CurrentMemoryContext = NULL;
|
||||
|
||||
/*****************************************************************************
|
||||
* PRIVATE DEFINITIONS *
|
||||
* PRIVATE DEFINITIONS *
|
||||
*****************************************************************************/
|
||||
|
||||
static Pointer GlobalMemoryAlloc(GlobalMemory this, Size size);
|
||||
static void GlobalMemoryFree(GlobalMemory this, Pointer pointer);
|
||||
static Pointer GlobalMemoryRealloc(GlobalMemory this, Pointer pointer,
|
||||
Size size);
|
||||
static char *GlobalMemoryGetName(GlobalMemory this);
|
||||
static void GlobalMemoryDump(GlobalMemory this);
|
||||
static Pointer GlobalMemoryAlloc(GlobalMemory this, Size size);
|
||||
static void GlobalMemoryFree(GlobalMemory this, Pointer pointer);
|
||||
static Pointer
|
||||
GlobalMemoryRealloc(GlobalMemory this, Pointer pointer,
|
||||
Size size);
|
||||
static char *GlobalMemoryGetName(GlobalMemory this);
|
||||
static void GlobalMemoryDump(GlobalMemory this);
|
||||
|
||||
#ifdef NOT_USED
|
||||
static void DumpGlobalMemories(void);
|
||||
static void DumpGlobalMemories(void);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Global Memory Methods
|
||||
*/
|
||||
|
||||
static struct MemoryContextMethodsData GlobalContextMethodsData = {
|
||||
GlobalMemoryAlloc, /* Pointer (*)(this, uint32) palloc */
|
||||
GlobalMemoryFree, /* void (*)(this, Pointer) pfree */
|
||||
GlobalMemoryRealloc, /* Pointer (*)(this, Pointer) repalloc */
|
||||
GlobalMemoryGetName, /* char* (*)(this) getName */
|
||||
GlobalMemoryDump /* void (*)(this) dump */
|
||||
static struct MemoryContextMethodsData GlobalContextMethodsData = {
|
||||
GlobalMemoryAlloc, /* Pointer (*)(this, uint32) palloc */
|
||||
GlobalMemoryFree, /* void (*)(this, Pointer) pfree */
|
||||
GlobalMemoryRealloc, /* Pointer (*)(this, Pointer) repalloc */
|
||||
GlobalMemoryGetName, /* char* (*)(this) getName */
|
||||
GlobalMemoryDump /* void (*)(this) dump */
|
||||
};
|
||||
|
||||
/*
|
||||
* Note:
|
||||
* TopGlobalMemory is handled specially because of bootstrapping.
|
||||
* TopGlobalMemory is handled specially because of bootstrapping.
|
||||
*/
|
||||
/* extern bool EqualGlobalMemory(); */
|
||||
|
||||
static struct GlobalMemory TopGlobalMemoryData = {
|
||||
T_GlobalMemory, /* NodeTag tag */
|
||||
&GlobalContextMethodsData, /* ContextMethods method */
|
||||
{ { 0 } }, /* uninitialized
|
||||
* OrderedSetData allocSetD
|
||||
*/
|
||||
"TopGlobal", /* char* name */
|
||||
{ 0 } /* uninitialized OrderedElemData elemD */
|
||||
T_GlobalMemory, /* NodeTag tag */
|
||||
&GlobalContextMethodsData, /* ContextMethods method */
|
||||
{{0}}, /* uninitialized OrderedSetData allocSetD */
|
||||
"TopGlobal", /* char* name */
|
||||
{0} /* uninitialized OrderedElemData elemD */
|
||||
};
|
||||
|
||||
/*
|
||||
* TopMemoryContext --
|
||||
* Memory context for general global allocations.
|
||||
* Memory context for general global allocations.
|
||||
*
|
||||
* Note:
|
||||
* Don't use this memory context for random allocations. If you
|
||||
* allocate something here, you are expected to clean it up when
|
||||
* appropriate.
|
||||
* Don't use this memory context for random allocations. If you
|
||||
* allocate something here, you are expected to clean it up when
|
||||
* appropriate.
|
||||
*/
|
||||
MemoryContext TopMemoryContext = (MemoryContext)&TopGlobalMemoryData;
|
||||
MemoryContext TopMemoryContext = (MemoryContext) & TopGlobalMemoryData;
|
||||
|
||||
|
||||
|
||||
@@ -129,213 +132,223 @@ MemoryContext TopMemoryContext = (MemoryContext)&TopGlobalMemoryData;
|
||||
|
||||
/*
|
||||
* EnableMemoryContext --
|
||||
* Enables/disables memory management and global contexts.
|
||||
* Enables/disables memory management and global contexts.
|
||||
*
|
||||
* Note:
|
||||
* This must be called before creating contexts or allocating memory.
|
||||
* This must be called before other contexts are created.
|
||||
* This must be called before creating contexts or allocating memory.
|
||||
* This must be called before other contexts are created.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if on is invalid.
|
||||
* BadState if on is false when disabled.
|
||||
* BadArg if on is invalid.
|
||||
* BadState if on is false when disabled.
|
||||
*/
|
||||
void
|
||||
EnableMemoryContext(bool on)
|
||||
{
|
||||
static bool processing = false;
|
||||
|
||||
AssertState(!processing);
|
||||
AssertArg(BoolIsValid(on));
|
||||
|
||||
if (BypassEnable(&MemoryContextEnableCount, on)) {
|
||||
return;
|
||||
}
|
||||
|
||||
processing = true;
|
||||
|
||||
if (on) { /* initialize */
|
||||
/* initialize TopGlobalMemoryData.setData */
|
||||
AllocSetInit(&TopGlobalMemoryData.setData, DynamicAllocMode,
|
||||
(Size)0);
|
||||
|
||||
/* make TopGlobalMemoryData member of ActiveGlobalMemorySet */
|
||||
OrderedSetInit(ActiveGlobalMemorySet,
|
||||
offsetof(struct GlobalMemory, elemData));
|
||||
OrderedElemPushInto(&TopGlobalMemoryData.elemData,
|
||||
ActiveGlobalMemorySet);
|
||||
|
||||
/* initialize CurrentMemoryContext */
|
||||
CurrentMemoryContext = TopMemoryContext;
|
||||
|
||||
} else { /* cleanup */
|
||||
GlobalMemory context;
|
||||
|
||||
/* walk the list of allocations */
|
||||
while (PointerIsValid(context = (GlobalMemory)
|
||||
OrderedSetGetHead(ActiveGlobalMemorySet))) {
|
||||
|
||||
if (context == &TopGlobalMemoryData) {
|
||||
/* don't free it and clean it last */
|
||||
OrderedElemPop(&TopGlobalMemoryData.elemData);
|
||||
} else {
|
||||
GlobalMemoryDestroy(context);
|
||||
}
|
||||
/* what is needed for the top? */
|
||||
static bool processing = false;
|
||||
|
||||
AssertState(!processing);
|
||||
AssertArg(BoolIsValid(on));
|
||||
|
||||
if (BypassEnable(&MemoryContextEnableCount, on))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Freeing memory here should be safe as this is called
|
||||
* only after all modules which allocate in TopMemoryContext
|
||||
* have been disabled.
|
||||
*/
|
||||
|
||||
/* step through remaining allocations and log */
|
||||
/* AllocSetStep(...); */
|
||||
|
||||
/* deallocate whatever is left */
|
||||
AllocSetReset(&TopGlobalMemoryData.setData);
|
||||
}
|
||||
|
||||
processing = false;
|
||||
|
||||
processing = true;
|
||||
|
||||
if (on)
|
||||
{ /* initialize */
|
||||
/* initialize TopGlobalMemoryData.setData */
|
||||
AllocSetInit(&TopGlobalMemoryData.setData, DynamicAllocMode,
|
||||
(Size) 0);
|
||||
|
||||
/* make TopGlobalMemoryData member of ActiveGlobalMemorySet */
|
||||
OrderedSetInit(ActiveGlobalMemorySet,
|
||||
offsetof(struct GlobalMemory, elemData));
|
||||
OrderedElemPushInto(&TopGlobalMemoryData.elemData,
|
||||
ActiveGlobalMemorySet);
|
||||
|
||||
/* initialize CurrentMemoryContext */
|
||||
CurrentMemoryContext = TopMemoryContext;
|
||||
|
||||
}
|
||||
else
|
||||
{ /* cleanup */
|
||||
GlobalMemory context;
|
||||
|
||||
/* walk the list of allocations */
|
||||
while (PointerIsValid(context = (GlobalMemory)
|
||||
OrderedSetGetHead(ActiveGlobalMemorySet)))
|
||||
{
|
||||
|
||||
if (context == &TopGlobalMemoryData)
|
||||
{
|
||||
/* don't free it and clean it last */
|
||||
OrderedElemPop(&TopGlobalMemoryData.elemData);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalMemoryDestroy(context);
|
||||
}
|
||||
/* what is needed for the top? */
|
||||
}
|
||||
|
||||
/*
|
||||
* Freeing memory here should be safe as this is called only after
|
||||
* all modules which allocate in TopMemoryContext have been
|
||||
* disabled.
|
||||
*/
|
||||
|
||||
/* step through remaining allocations and log */
|
||||
/* AllocSetStep(...); */
|
||||
|
||||
/* deallocate whatever is left */
|
||||
AllocSetReset(&TopGlobalMemoryData.setData);
|
||||
}
|
||||
|
||||
processing = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* MemoryContextAlloc --
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* BadState if called before InitMemoryManager.
|
||||
* BadArg if context is invalid or if size is 0.
|
||||
* BadAllocSize if size is larger than MaxAllocSize.
|
||||
* BadState if called before InitMemoryManager.
|
||||
* BadArg if context is invalid or if size is 0.
|
||||
* BadAllocSize if size is larger than MaxAllocSize.
|
||||
*/
|
||||
Pointer
|
||||
MemoryContextAlloc(MemoryContext context, Size size)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
||||
("size=%d [0x%x]", size, size));
|
||||
|
||||
return (context->method->alloc(context, size));
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
||||
("size=%d [0x%x]", size, size));
|
||||
|
||||
return (context->method->alloc(context, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* MemoryContextFree --
|
||||
* Frees allocated memory referenced by pointer in the given context.
|
||||
* Frees allocated memory referenced by pointer in the given context.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
*/
|
||||
void
|
||||
MemoryContextFree(MemoryContext context, Pointer pointer)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
context->method->free_p(context, pointer);
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
context->method->free_p(context, pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* MemoryContextRelloc --
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
*/
|
||||
Pointer
|
||||
MemoryContextRealloc(MemoryContext context,
|
||||
Pointer pointer,
|
||||
Size size)
|
||||
Pointer pointer,
|
||||
Size size)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
||||
("size=%d [0x%x]", size, size));
|
||||
|
||||
return (context->method->realloc(context, pointer, size));
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
|
||||
("size=%d [0x%x]", size, size));
|
||||
|
||||
return (context->method->realloc(context, pointer, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* MemoryContextGetName --
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
* Returns pointer to aligned allocated memory in the given context.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
char*
|
||||
char *
|
||||
MemoryContextGetName(MemoryContext context)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
return (context->method->getName(context));
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
return (context->method->getName(context));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PointerGetAllocSize --
|
||||
* Returns size of aligned allocated memory given pointer to it.
|
||||
* Returns size of aligned allocated memory given pointer to it.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
* ???
|
||||
* BadArgumentsErr if firstTime is true for subsequent calls.
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
Size
|
||||
PointerGetAllocSize(Pointer pointer)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
return (PSIZE(pointer));
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(PointerIsValid(pointer));
|
||||
|
||||
return (PSIZE(pointer));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MemoryContextSwitchTo --
|
||||
* Returns the current context; installs the given context.
|
||||
* Returns the current context; installs the given context.
|
||||
*
|
||||
* Note:
|
||||
* none
|
||||
* none
|
||||
*
|
||||
* Exceptions:
|
||||
* BadState if called when disabled.
|
||||
* BadArg if context is invalid.
|
||||
* BadState if called when disabled.
|
||||
* BadArg if context is invalid.
|
||||
*/
|
||||
MemoryContext
|
||||
MemoryContextSwitchTo(MemoryContext context)
|
||||
{
|
||||
MemoryContext old;
|
||||
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
old = CurrentMemoryContext;
|
||||
CurrentMemoryContext = context;
|
||||
return (old);
|
||||
MemoryContext old;
|
||||
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(MemoryContextIsValid(context));
|
||||
|
||||
old = CurrentMemoryContext;
|
||||
CurrentMemoryContext = context;
|
||||
return (old);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -343,174 +356,178 @@ MemoryContextSwitchTo(MemoryContext context)
|
||||
*/
|
||||
/*
|
||||
* CreateGlobalMemory --
|
||||
* Returns new global memory context.
|
||||
* Returns new global memory context.
|
||||
*
|
||||
* Note:
|
||||
* Assumes name is static.
|
||||
* Assumes name is static.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadState if called when disabled.
|
||||
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
||||
* BadArg if name is invalid.
|
||||
* BadState if called when disabled.
|
||||
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
||||
* BadArg if name is invalid.
|
||||
*/
|
||||
GlobalMemory
|
||||
CreateGlobalMemory(char *name) /* XXX MemoryContextName */
|
||||
CreateGlobalMemory(char *name) /* XXX MemoryContextName */
|
||||
{
|
||||
GlobalMemory context;
|
||||
MemoryContext savecxt;
|
||||
|
||||
AssertState(MemoryContextEnabled);
|
||||
|
||||
savecxt = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
context = (GlobalMemory)newNode(sizeof(struct GlobalMemory), T_GlobalMemory);
|
||||
context->method = &GlobalContextMethodsData;
|
||||
context->name = name; /* assumes name is static */
|
||||
AllocSetInit(&context->setData, DynamicAllocMode, (Size)0);
|
||||
|
||||
/* link the context */
|
||||
OrderedElemPushInto(&context->elemData, ActiveGlobalMemorySet);
|
||||
|
||||
MemoryContextSwitchTo(savecxt);
|
||||
return (context);
|
||||
GlobalMemory context;
|
||||
MemoryContext savecxt;
|
||||
|
||||
AssertState(MemoryContextEnabled);
|
||||
|
||||
savecxt = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
context = (GlobalMemory) newNode(sizeof(struct GlobalMemory), T_GlobalMemory);
|
||||
context->method = &GlobalContextMethodsData;
|
||||
context->name = name; /* assumes name is static */
|
||||
AllocSetInit(&context->setData, DynamicAllocMode, (Size) 0);
|
||||
|
||||
/* link the context */
|
||||
OrderedElemPushInto(&context->elemData, ActiveGlobalMemorySet);
|
||||
|
||||
MemoryContextSwitchTo(savecxt);
|
||||
return (context);
|
||||
}
|
||||
|
||||
/*
|
||||
* GlobalMemoryDestroy --
|
||||
* Destroys given global memory context.
|
||||
* Destroys given global memory context.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadState if called when disabled.
|
||||
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
||||
* BadArg if context is invalid GlobalMemory.
|
||||
* BadArg if context is TopMemoryContext (TopGlobalMemory).
|
||||
* BadState if called when disabled.
|
||||
* BadState if called outside TopMemoryContext (TopGlobalMemory).
|
||||
* BadArg if context is invalid GlobalMemory.
|
||||
* BadArg if context is TopMemoryContext (TopGlobalMemory).
|
||||
*/
|
||||
void
|
||||
GlobalMemoryDestroy(GlobalMemory context)
|
||||
{
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(IsA(context,GlobalMemory));
|
||||
AssertArg(context != &TopGlobalMemoryData);
|
||||
|
||||
AllocSetReset(&context->setData);
|
||||
|
||||
/* unlink and delete the context */
|
||||
OrderedElemPop(&context->elemData);
|
||||
MemoryContextFree(TopMemoryContext, (Pointer)context);
|
||||
AssertState(MemoryContextEnabled);
|
||||
AssertArg(IsA(context, GlobalMemory));
|
||||
AssertArg(context != &TopGlobalMemoryData);
|
||||
|
||||
AllocSetReset(&context->setData);
|
||||
|
||||
/* unlink and delete the context */
|
||||
OrderedElemPop(&context->elemData);
|
||||
MemoryContextFree(TopMemoryContext, (Pointer) context);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* PRIVATE *
|
||||
* PRIVATE *
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* GlobalMemoryAlloc --
|
||||
* Returns pointer to aligned space in the global context.
|
||||
* Returns pointer to aligned space in the global context.
|
||||
*
|
||||
* Exceptions:
|
||||
* ExhaustedMemory if allocation fails.
|
||||
* ExhaustedMemory if allocation fails.
|
||||
*/
|
||||
static Pointer
|
||||
static Pointer
|
||||
GlobalMemoryAlloc(GlobalMemory this, Size size)
|
||||
{
|
||||
return (AllocSetAlloc(&this->setData, size));
|
||||
return (AllocSetAlloc(&this->setData, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* GlobalMemoryFree --
|
||||
* Frees allocated memory in the global context.
|
||||
* Frees allocated memory in the global context.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadContextErr if current context is not the global context.
|
||||
* BadArgumentsErr if pointer is invalid.
|
||||
* BadContextErr if current context is not the global context.
|
||||
* BadArgumentsErr if pointer is invalid.
|
||||
*/
|
||||
static void
|
||||
GlobalMemoryFree(GlobalMemory this,
|
||||
Pointer pointer)
|
||||
Pointer pointer)
|
||||
{
|
||||
AllocSetFree(&this->setData, pointer);
|
||||
AllocSetFree(&this->setData, pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* GlobalMemoryRealloc --
|
||||
* Returns pointer to aligned space in the global context.
|
||||
* Returns pointer to aligned space in the global context.
|
||||
*
|
||||
* Note:
|
||||
* Memory associated with the pointer is freed before return.
|
||||
* Memory associated with the pointer is freed before return.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadContextErr if current context is not the global context.
|
||||
* BadArgumentsErr if pointer is invalid.
|
||||
* NoMoreMemoryErr if allocation fails.
|
||||
* BadContextErr if current context is not the global context.
|
||||
* BadArgumentsErr if pointer is invalid.
|
||||
* NoMoreMemoryErr if allocation fails.
|
||||
*/
|
||||
static Pointer
|
||||
static Pointer
|
||||
GlobalMemoryRealloc(GlobalMemory this,
|
||||
Pointer pointer,
|
||||
Size size)
|
||||
Pointer pointer,
|
||||
Size size)
|
||||
{
|
||||
return (AllocSetRealloc(&this->setData, pointer, size));
|
||||
return (AllocSetRealloc(&this->setData, pointer, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* GlobalMemoryGetName --
|
||||
* Returns name string for context.
|
||||
* Returns name string for context.
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* ???
|
||||
*/
|
||||
static char*
|
||||
static char *
|
||||
GlobalMemoryGetName(GlobalMemory this)
|
||||
{
|
||||
return (this->name);
|
||||
return (this->name);
|
||||
}
|
||||
|
||||
/*
|
||||
* GlobalMemoryDump --
|
||||
* Dumps global memory context for debugging.
|
||||
* Dumps global memory context for debugging.
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* ???
|
||||
*/
|
||||
static void
|
||||
GlobalMemoryDump(GlobalMemory this)
|
||||
{
|
||||
GlobalMemory context;
|
||||
|
||||
printf("--\n%s:\n", GlobalMemoryGetName(this));
|
||||
|
||||
context = (GlobalMemory)OrderedElemGetPredecessor(&this->elemData);
|
||||
if (PointerIsValid(context)) {
|
||||
printf("\tpredecessor=%s\n", GlobalMemoryGetName(context));
|
||||
}
|
||||
|
||||
context = (GlobalMemory)OrderedElemGetSuccessor(&this->elemData);
|
||||
if (PointerIsValid(context)) {
|
||||
printf("\tsucessor=%s\n", GlobalMemoryGetName(context));
|
||||
}
|
||||
|
||||
AllocSetDump(&this->setData); /* XXX is this right interface */
|
||||
GlobalMemory context;
|
||||
|
||||
printf("--\n%s:\n", GlobalMemoryGetName(this));
|
||||
|
||||
context = (GlobalMemory) OrderedElemGetPredecessor(&this->elemData);
|
||||
if (PointerIsValid(context))
|
||||
{
|
||||
printf("\tpredecessor=%s\n", GlobalMemoryGetName(context));
|
||||
}
|
||||
|
||||
context = (GlobalMemory) OrderedElemGetSuccessor(&this->elemData);
|
||||
if (PointerIsValid(context))
|
||||
{
|
||||
printf("\tsucessor=%s\n", GlobalMemoryGetName(context));
|
||||
}
|
||||
|
||||
AllocSetDump(&this->setData); /* XXX is this right interface */
|
||||
}
|
||||
|
||||
/*
|
||||
* DumpGlobalMemories --
|
||||
* Dumps all global memory contexts for debugging.
|
||||
* Dumps all global memory contexts for debugging.
|
||||
*
|
||||
* Exceptions:
|
||||
* ???
|
||||
* ???
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
static void
|
||||
DumpGlobalMemories()
|
||||
{
|
||||
GlobalMemory context;
|
||||
|
||||
context = (GlobalMemory)OrderedSetGetHead(&ActiveGlobalMemorySetData);
|
||||
|
||||
while (PointerIsValid(context)) {
|
||||
GlobalMemoryDump(context);
|
||||
|
||||
context = (GlobalMemory)OrderedElemGetSuccessor(
|
||||
&context->elemData);
|
||||
}
|
||||
GlobalMemory context;
|
||||
|
||||
context = (GlobalMemory) OrderedSetGetHead(&ActiveGlobalMemorySetData);
|
||||
|
||||
while (PointerIsValid(context))
|
||||
{
|
||||
GlobalMemoryDump(context);
|
||||
|
||||
context = (GlobalMemory) OrderedElemGetSuccessor(
|
||||
&context->elemData);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* oset.c--
|
||||
* Fixed format ordered set definitions.
|
||||
* Fixed format ordered set definitions.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.3 1997/08/24 23:07:50 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.4 1997/09/07 04:54:11 momjian Exp $
|
||||
*
|
||||
* NOTE
|
||||
* XXX This is a preliminary implementation which lacks fail-fast
|
||||
* XXX validity checking of arguments.
|
||||
* XXX This is a preliminary implementation which lacks fail-fast
|
||||
* XXX validity checking of arguments.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "c.h"
|
||||
|
||||
#include "utils/memutils.h" /* where declarations of this file goes */
|
||||
#include "utils/memutils.h" /* where declarations of this file goes */
|
||||
|
||||
static Pointer OrderedElemGetBase(OrderedElem elem);
|
||||
static void OrderedElemPush(OrderedElem elem);
|
||||
static void OrderedElemPushHead(OrderedElem elem);
|
||||
static Pointer OrderedElemGetBase(OrderedElem elem);
|
||||
static void OrderedElemPush(OrderedElem elem);
|
||||
static void OrderedElemPushHead(OrderedElem elem);
|
||||
|
||||
/*
|
||||
* OrderedElemGetBase --
|
||||
* Returns base of enclosing structure.
|
||||
* Returns base of enclosing structure.
|
||||
*/
|
||||
static Pointer
|
||||
static Pointer
|
||||
OrderedElemGetBase(OrderedElem elem)
|
||||
{
|
||||
if (elem == (OrderedElem) NULL)
|
||||
return (Pointer) NULL;
|
||||
|
||||
return ((Pointer)((char*)(elem) - (elem)->set->offset));
|
||||
if (elem == (OrderedElem) NULL)
|
||||
return (Pointer) NULL;
|
||||
|
||||
return ((Pointer) ((char *) (elem) - (elem)->set->offset));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -42,20 +42,20 @@ OrderedElemGetBase(OrderedElem elem)
|
||||
void
|
||||
OrderedSetInit(OrderedSet set, Offset offset)
|
||||
{
|
||||
set->head = (OrderedElem)&set->dummy;
|
||||
set->dummy = NULL;
|
||||
set->tail = (OrderedElem)&set->head;
|
||||
set->offset = offset;
|
||||
set->head = (OrderedElem) & set->dummy;
|
||||
set->dummy = NULL;
|
||||
set->tail = (OrderedElem) & set->head;
|
||||
set->offset = offset;
|
||||
}
|
||||
|
||||
/*
|
||||
* OrderedSetContains --
|
||||
* True iff ordered set contains given element.
|
||||
* True iff ordered set contains given element.
|
||||
*/
|
||||
bool
|
||||
OrderedSetContains(OrderedSet set, OrderedElem elem)
|
||||
{
|
||||
return ((bool)(elem->set == set && (elem->next || elem->prev)));
|
||||
return ((bool) (elem->set == set && (elem->next || elem->prev)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -64,13 +64,14 @@ OrderedSetContains(OrderedSet set, OrderedElem elem)
|
||||
Pointer
|
||||
OrderedSetGetHead(OrderedSet set)
|
||||
{
|
||||
register OrderedElem elem;
|
||||
|
||||
elem = set->head;
|
||||
if (elem->next) {
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
register OrderedElem elem;
|
||||
|
||||
elem = set->head;
|
||||
if (elem->next)
|
||||
{
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -80,14 +81,16 @@ OrderedSetGetHead(OrderedSet set)
|
||||
Pointer
|
||||
OrderedSetGetTail(OrderedSet set)
|
||||
{
|
||||
register OrderedElem elem;
|
||||
|
||||
elem = set->tail;
|
||||
if (elem->prev) {
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
register OrderedElem elem;
|
||||
|
||||
elem = set->tail;
|
||||
if (elem->prev)
|
||||
{
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -96,11 +99,12 @@ OrderedSetGetTail(OrderedSet set)
|
||||
Pointer
|
||||
OrderedElemGetPredecessor(OrderedElem elem)
|
||||
{
|
||||
elem = elem->prev;
|
||||
if (elem->prev) {
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
elem = elem->prev;
|
||||
if (elem->prev)
|
||||
{
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -109,24 +113,25 @@ OrderedElemGetPredecessor(OrderedElem elem)
|
||||
Pointer
|
||||
OrderedElemGetSuccessor(OrderedElem elem)
|
||||
{
|
||||
elem = elem->next;
|
||||
if (elem->next) {
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
elem = elem->next;
|
||||
if (elem->next)
|
||||
{
|
||||
return (OrderedElemGetBase(elem));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* OrderedElemPop --
|
||||
*/
|
||||
void
|
||||
void
|
||||
OrderedElemPop(OrderedElem elem)
|
||||
{
|
||||
elem->next->prev = elem->prev;
|
||||
elem->prev->next = elem->next;
|
||||
/* assignments used only for error detection */
|
||||
elem->next = NULL;
|
||||
elem->prev = NULL;
|
||||
elem->next->prev = elem->prev;
|
||||
elem->prev->next = elem->next;
|
||||
/* assignments used only for error detection */
|
||||
elem->next = NULL;
|
||||
elem->prev = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -135,11 +140,11 @@ OrderedElemPop(OrderedElem elem)
|
||||
void
|
||||
OrderedElemPushInto(OrderedElem elem, OrderedSet set)
|
||||
{
|
||||
elem->set = set;
|
||||
/* mark as unattached */
|
||||
elem->next = NULL;
|
||||
elem->prev = NULL;
|
||||
OrderedElemPush(elem);
|
||||
elem->set = set;
|
||||
/* mark as unattached */
|
||||
elem->next = NULL;
|
||||
elem->prev = NULL;
|
||||
OrderedElemPush(elem);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -148,7 +153,7 @@ OrderedElemPushInto(OrderedElem elem, OrderedSet set)
|
||||
static void
|
||||
OrderedElemPush(OrderedElem elem)
|
||||
{
|
||||
OrderedElemPushHead(elem);
|
||||
OrderedElemPushHead(elem);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -157,9 +162,8 @@ OrderedElemPush(OrderedElem elem)
|
||||
static void
|
||||
OrderedElemPushHead(OrderedElem elem)
|
||||
{
|
||||
elem->next = elem->set->head;
|
||||
elem->prev = (OrderedElem)&elem->set->head;
|
||||
elem->next->prev = elem;
|
||||
elem->prev->next = elem;
|
||||
elem->next = elem->set->head;
|
||||
elem->prev = (OrderedElem) & elem->set->head;
|
||||
elem->next->prev = elem;
|
||||
elem->prev->next = elem;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* palloc.c--
|
||||
* POSTGRES memory allocator code.
|
||||
* POSTGRES memory allocator code.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/palloc.c,v 1.3 1996/11/26 03:19:12 bryanh Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/palloc.c,v 1.4 1997/09/07 04:54:12 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "utils/palloc.h"
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* User library functions
|
||||
* User library functions
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -36,84 +36,84 @@
|
||||
#undef malloc
|
||||
#undef free
|
||||
|
||||
/* define PALLOC_IS_MALLOC if you want palloc to go straight to the
|
||||
/* define PALLOC_IS_MALLOC if you want palloc to go straight to the
|
||||
raw malloc, without concern for the extra bookkeeping needed to
|
||||
ensure garbage is collected at the end of transactions - jolly 1/12/94 */
|
||||
|
||||
|
||||
/*
|
||||
* palloc --
|
||||
* Returns pointer to aligned memory of specified size.
|
||||
* Returns pointer to aligned memory of specified size.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArgument if size < 1 or size >= MaxAllocSize.
|
||||
* ExhaustedMemory if allocation fails.
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been freed already.
|
||||
* BadArgument if size < 1 or size >= MaxAllocSize.
|
||||
* ExhaustedMemory if allocation fails.
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been freed already.
|
||||
*
|
||||
* pfree --
|
||||
* Frees memory associated with pointer returned from palloc or repalloc.
|
||||
* Frees memory associated with pointer returned from palloc or repalloc.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArgument if pointer is invalid.
|
||||
* FreeInWrongContext if pointer was allocated in a different "context."
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been subsequently freed.
|
||||
* BadArgument if pointer is invalid.
|
||||
* FreeInWrongContext if pointer was allocated in a different "context."
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been subsequently freed.
|
||||
*/
|
||||
void*
|
||||
void *
|
||||
palloc(Size size)
|
||||
{
|
||||
#ifdef PALLOC_IS_MALLOC
|
||||
return malloc(size);
|
||||
return malloc(size);
|
||||
#else
|
||||
return (MemoryContextAlloc(CurrentMemoryContext, size));
|
||||
#endif /* PALLOC_IS_MALLOC */
|
||||
return (MemoryContextAlloc(CurrentMemoryContext, size));
|
||||
#endif /* PALLOC_IS_MALLOC */
|
||||
}
|
||||
|
||||
void
|
||||
pfree(void *pointer)
|
||||
{
|
||||
{
|
||||
#ifdef PALLOC_IS_MALLOC
|
||||
free(pointer);
|
||||
free(pointer);
|
||||
#else
|
||||
MemoryContextFree(CurrentMemoryContext, pointer);
|
||||
#endif /* PALLOC_IS_MALLOC */
|
||||
MemoryContextFree(CurrentMemoryContext, pointer);
|
||||
#endif /* PALLOC_IS_MALLOC */
|
||||
}
|
||||
|
||||
/*
|
||||
* repalloc --
|
||||
* Returns pointer to aligned memory of specified size.
|
||||
* Returns pointer to aligned memory of specified size.
|
||||
*
|
||||
* Side effects:
|
||||
* The returned memory is first filled with the contents of *pointer
|
||||
* up to the minimum of size and psize(pointer). Pointer is freed.
|
||||
* The returned memory is first filled with the contents of *pointer
|
||||
* up to the minimum of size and psize(pointer). Pointer is freed.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArgument if pointer is invalid or size < 1 or size >= MaxAllocSize.
|
||||
* ExhaustedMemory if allocation fails.
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been freed already.
|
||||
* BadArgument if pointer is invalid or size < 1 or size >= MaxAllocSize.
|
||||
* ExhaustedMemory if allocation fails.
|
||||
* NonallocatedPointer if pointer was not returned by palloc or repalloc
|
||||
* or may have been freed already.
|
||||
*/
|
||||
void *
|
||||
void *
|
||||
repalloc(void *pointer, Size size)
|
||||
{
|
||||
#ifdef PALLOC_IS_MALLOC
|
||||
return realloc(pointer, size);
|
||||
return realloc(pointer, size);
|
||||
#else
|
||||
return (MemoryContextRealloc(CurrentMemoryContext, pointer, size));
|
||||
return (MemoryContextRealloc(CurrentMemoryContext, pointer, size));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* pstrdup
|
||||
allocates space for and copies a string
|
||||
just like strdup except it uses palloc instead of malloc */
|
||||
char*
|
||||
pstrdup(char* string)
|
||||
/* pstrdup
|
||||
allocates space for and copies a string
|
||||
just like strdup except it uses palloc instead of malloc */
|
||||
char *
|
||||
pstrdup(char *string)
|
||||
{
|
||||
char *nstr;
|
||||
char *nstr;
|
||||
|
||||
nstr = (char *)palloc(strlen(string)+1);
|
||||
strcpy(nstr, string);
|
||||
nstr = (char *) palloc(strlen(string) + 1);
|
||||
strcpy(nstr, string);
|
||||
|
||||
return nstr;
|
||||
return nstr;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user