diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-06-28 03:33:33 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-06-28 03:33:33 +0000 |
commit | 1aebc3618a0be13451918581ad390ad9a3518702 (patch) | |
tree | e8ab228245c43ff086bd8e9d65baf3d1d9a5f96a /src/backend/lib | |
parent | b601c8d8828ee02ffb195dead82b233b9572fe32 (diff) | |
download | postgresql-1aebc3618a0be13451918581ad390ad9a3518702.tar.gz postgresql-1aebc3618a0be13451918581ad390ad9a3518702.zip |
First phase of memory management rewrite (see backend/utils/mmgr/README
for details). It doesn't really do that much yet, since there are no
short-term memory contexts in the executor, but the infrastructure is
in place and long-term contexts are handled reasonably. A few long-
standing bugs have been fixed, such as 'VACUUM; anything' in a single
query string crashing. Also, out-of-memory is now considered a
recoverable ERROR, not FATAL.
Eliminate a large amount of crufty, now-dead code in and around
memory management.
Fix problem with holding off SIGTRAP, SIGSEGV, etc in postmaster and
backend startup.
Diffstat (limited to 'src/backend/lib')
-rw-r--r-- | src/backend/lib/Makefile | 4 | ||||
-rw-r--r-- | src/backend/lib/fstack.c | 145 | ||||
-rw-r--r-- | src/backend/lib/stringinfo.c | 15 |
3 files changed, 8 insertions, 156 deletions
diff --git a/src/backend/lib/Makefile b/src/backend/lib/Makefile index 6b8a9d72022..428935f255a 100644 --- a/src/backend/lib/Makefile +++ b/src/backend/lib/Makefile @@ -4,14 +4,14 @@ # Makefile for lib (miscellaneous stuff) # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/lib/Makefile,v 1.13 2000/05/29 05:44:45 tgl Exp $ +# $Header: /cvsroot/pgsql/src/backend/lib/Makefile,v 1.14 2000/06/28 03:31:34 tgl Exp $ # #------------------------------------------------------------------------- SRCDIR = ../.. include ../../Makefile.global -OBJS = bit.o fstack.o hasht.o lispsort.o stringinfo.o dllist.o +OBJS = bit.o hasht.o lispsort.o stringinfo.o dllist.o all: SUBSYS.o diff --git a/src/backend/lib/fstack.c b/src/backend/lib/fstack.c deleted file mode 100644 index 9552909bc01..00000000000 --- a/src/backend/lib/fstack.c +++ /dev/null @@ -1,145 +0,0 @@ -/*------------------------------------------------------------------------- - * - * fstack.c - * Fixed format stack definitions. - * - * Portions Copyright (c) 1996-2000, PostgreSQL, Inc - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/lib/Attic/fstack.c,v 1.14 2000/01/26 05:56:26 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" -#include "lib/fstack.h" - -/* - * Internal function definitions - */ - -/* - * FixedItemIsValid - * True iff item is valid. - */ -#define FixedItemIsValid(item) PointerIsValid(item) - -/* - * FixedStackGetItemBase - * Returns base of enclosing structure. - */ -#define FixedStackGetItemBase(stack, item) \ - ((Pointer)((char *)(item) - (stack)->offset)) - -/* - * FixedStackGetItem - * Returns item of given pointer to enclosing structure. - */ -#define FixedStackGetItem(stack, pointer) \ - ((FixedItem)((char *)(pointer) + (stack)->offset)) - -#define FixedStackIsValid(stack) ((bool)PointerIsValid(stack)) - -/* - * External functions - */ - -void -FixedStackInit(FixedStack stack, Offset offset) -{ - AssertArg(PointerIsValid(stack)); - - stack->top = NULL; - stack->offset = offset; -} - -Pointer -FixedStackPop(FixedStack stack) -{ - Pointer pointer; - - AssertArg(FixedStackIsValid(stack)); - - if (!PointerIsValid(stack->top)) - return NULL; - - pointer = FixedStackGetItemBase(stack, stack->top); - stack->top = stack->top->next; - - return pointer; -} - -void -FixedStackPush(FixedStack stack, Pointer pointer) -{ - FixedItem item = FixedStackGetItem(stack, pointer); - - AssertArg(FixedStackIsValid(stack)); - AssertArg(PointerIsValid(pointer)); - - item->next = stack->top; - stack->top = item; -} - -#ifdef USE_ASSERT_CHECKING -/* - * FixedStackContains - * True iff ordered stack contains given element. - * - * Note: - * This is inefficient. It is intended for debugging use only. - * - * Exceptions: - * BadArg if stack is invalid. - * BadArg if pointer is invalid. - */ -static bool -FixedStackContains(FixedStack stack, Pointer pointer) -{ - FixedItem next; - FixedItem item; - - AssertArg(FixedStackIsValid(stack)); - AssertArg(PointerIsValid(pointer)); - - item = FixedStackGetItem(stack, pointer); - - for (next = stack->top; FixedItemIsValid(next); next = next->next) - { - if (next == item) - return true; - } - return false; -} - -#endif - -Pointer -FixedStackGetTop(FixedStack stack) -{ - AssertArg(FixedStackIsValid(stack)); - - if (!PointerIsValid(stack->top)) - return NULL; - - return FixedStackGetItemBase(stack, stack->top); -} - -Pointer -FixedStackGetNext(FixedStack stack, Pointer pointer) -{ - FixedItem item; - - /* AssertArg(FixedStackIsValid(stack)); */ - /* AssertArg(PointerIsValid(pointer)); */ - AssertArg(FixedStackContains(stack, pointer)); - - item = FixedStackGetItem(stack, pointer)->next; - - if (!PointerIsValid(item)) - return NULL; - - return FixedStackGetItemBase(stack, item); -} diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c index 4f2df746843..379cd795029 100644 --- a/src/backend/lib/stringinfo.c +++ b/src/backend/lib/stringinfo.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: stringinfo.c,v 1.25 2000/04/12 17:15:11 momjian Exp $ + * $Id: stringinfo.c,v 1.26 2000/06/28 03:31:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,8 +29,6 @@ makeStringInfo(void) StringInfo res; res = (StringInfo) palloc(sizeof(StringInfoData)); - if (res == NULL) - elog(ERROR, "makeStringInfo: Out of memory"); initStringInfo(res); @@ -49,9 +47,6 @@ initStringInfo(StringInfo str) int size = 256; /* initial default buffer size */ str->data = (char *) palloc(size); - if (str->data == NULL) - elog(ERROR, - "initStringInfo: Out of memory (%d bytes requested)", size); str->maxlen = size; str->len = 0; str->data[0] = '\0'; @@ -62,6 +57,11 @@ initStringInfo(StringInfo str) * * Internal routine: make sure there is enough space for 'needed' more bytes * ('needed' does not include the terminating null). + * + * NB: because we use repalloc() to enlarge the buffer, the string buffer + * will remain allocated in the same memory context that was current when + * initStringInfo was called, even if another context is now current. + * This is the desired and indeed critical behavior! */ static void enlargeStringInfo(StringInfo str, int needed) @@ -83,9 +83,6 @@ enlargeStringInfo(StringInfo str, int needed) newlen = 2 * newlen; str->data = (char *) repalloc(str->data, newlen); - if (str->data == NULL) - elog(ERROR, - "enlargeStringInfo: Out of memory (%d bytes requested)", newlen); str->maxlen = newlen; } |