diff options
Diffstat (limited to 'src/backend/lib')
-rw-r--r-- | src/backend/lib/Makefile | 30 | ||||
-rw-r--r-- | src/backend/lib/bit.c | 41 | ||||
-rw-r--r-- | src/backend/lib/dllist.c | 238 | ||||
-rw-r--r-- | src/backend/lib/lispsort.c | 59 | ||||
-rw-r--r-- | src/backend/lib/stringinfo.c | 191 |
5 files changed, 0 insertions, 559 deletions
diff --git a/src/backend/lib/Makefile b/src/backend/lib/Makefile deleted file mode 100644 index 58e47f67144..00000000000 --- a/src/backend/lib/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -#------------------------------------------------------------------------- -# -# Makefile-- -# Makefile for lib (miscellaneous stuff) -# -# IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/lib/Makefile,v 1.16 2001/10/05 17:28:12 tgl Exp $ -# -#------------------------------------------------------------------------- - -subdir = src/backend/lib -top_builddir = ../../.. -include $(top_builddir)/src/Makefile.global - -OBJS = bit.o dllist.o lispsort.o stringinfo.o - -all: SUBSYS.o - -SUBSYS.o: $(OBJS) - $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS) - -depend dep: - $(CC) -MM $(CFLAGS) *.c >depend - -clean: - rm -f SUBSYS.o $(OBJS) - -ifeq (depend,$(wildcard depend)) -include depend -endif diff --git a/src/backend/lib/bit.c b/src/backend/lib/bit.c deleted file mode 100644 index fb060d61fd7..00000000000 --- a/src/backend/lib/bit.c +++ /dev/null @@ -1,41 +0,0 @@ -/*------------------------------------------------------------------------- - * - * bit.c - * Standard bit array code. - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/lib/Attic/bit.c,v 1.15 2002/06/20 20:29:28 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" - -#include "utils/bit.h" - - -void -BitArraySetBit(BitArray bitArray, BitIndex bitIndex) -{ - bitArray[bitIndex / BITS_PER_BYTE] |= - (1 << (BITS_PER_BYTE - 1 - (bitIndex % BITS_PER_BYTE))); -} - -void -BitArrayClearBit(BitArray bitArray, BitIndex bitIndex) -{ - bitArray[bitIndex / BITS_PER_BYTE] &= - ~(1 << (BITS_PER_BYTE - 1 - (bitIndex % BITS_PER_BYTE))); -} - -bool -BitArrayBitIsSet(BitArray bitArray, BitIndex bitIndex) -{ - return ((bitArray[bitIndex / BITS_PER_BYTE] & - (1 << (BITS_PER_BYTE - 1 - (bitIndex % BITS_PER_BYTE))) - ) != 0); -} diff --git a/src/backend/lib/dllist.c b/src/backend/lib/dllist.c deleted file mode 100644 index 8c13ddfb0f7..00000000000 --- a/src/backend/lib/dllist.c +++ /dev/null @@ -1,238 +0,0 @@ -/*------------------------------------------------------------------------- - * - * dllist.c - * this is a simple doubly linked list implementation - * the elements of the lists are void* - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/lib/dllist.c,v 1.25 2002/06/20 20:29:28 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -/* can be used in frontend or backend */ -#ifdef FRONTEND -#include "postgres_fe.h" -/* No assert checks in frontend ... */ -#define Assert(condition) -#else -#include "postgres.h" -#endif - -#include "lib/dllist.h" - - -Dllist * -DLNewList(void) -{ - Dllist *l; - - l = (Dllist *) malloc(sizeof(Dllist)); - if (l == NULL) - { -#ifdef FRONTEND - fprintf(stderr, "Memory exhausted in DLNewList\n"); - exit(1); -#else - elog(ERROR, "Memory exhausted in DLNewList"); -#endif - } - l->dll_head = 0; - l->dll_tail = 0; - - return l; -} - -void -DLInitList(Dllist *list) -{ - list->dll_head = 0; - list->dll_tail = 0; -} - -/* - * free up a list and all the nodes in it --- but *not* whatever the nodes - * might point to! - */ -void -DLFreeList(Dllist *list) -{ - Dlelem *curr; - - while ((curr = DLRemHead(list)) != 0) - free(curr); - - free(list); -} - -Dlelem * -DLNewElem(void *val) -{ - Dlelem *e; - - e = (Dlelem *) malloc(sizeof(Dlelem)); - if (e == NULL) - { -#ifdef FRONTEND - fprintf(stderr, "Memory exhausted in DLNewElem\n"); - exit(1); -#else - elog(ERROR, "Memory exhausted in DLNewElem"); -#endif - } - e->dle_next = 0; - e->dle_prev = 0; - e->dle_val = val; - e->dle_list = 0; - return e; -} - -void -DLInitElem(Dlelem *e, void *val) -{ - e->dle_next = 0; - e->dle_prev = 0; - e->dle_val = val; - e->dle_list = 0; -} - -void -DLFreeElem(Dlelem *e) -{ - free(e); -} - -void -DLRemove(Dlelem *e) -{ - Dllist *l = e->dle_list; - - if (e->dle_prev) - e->dle_prev->dle_next = e->dle_next; - else - { - /* must be the head element */ - Assert(e == l->dll_head); - l->dll_head = e->dle_next; - } - if (e->dle_next) - e->dle_next->dle_prev = e->dle_prev; - else - { - /* must be the tail element */ - Assert(e == l->dll_tail); - l->dll_tail = e->dle_prev; - } - - e->dle_next = 0; - e->dle_prev = 0; - e->dle_list = 0; -} - -void -DLAddHead(Dllist *l, Dlelem *e) -{ - e->dle_list = l; - - if (l->dll_head) - l->dll_head->dle_prev = e; - e->dle_next = l->dll_head; - e->dle_prev = 0; - l->dll_head = e; - - if (l->dll_tail == 0) /* if this is first element added */ - l->dll_tail = e; -} - -void -DLAddTail(Dllist *l, Dlelem *e) -{ - e->dle_list = l; - - if (l->dll_tail) - l->dll_tail->dle_next = e; - e->dle_prev = l->dll_tail; - e->dle_next = 0; - l->dll_tail = e; - - if (l->dll_head == 0) /* if this is first element added */ - l->dll_head = e; -} - -Dlelem * -DLRemHead(Dllist *l) -{ - /* remove and return the head */ - Dlelem *result = l->dll_head; - - if (result == 0) - return result; - - if (result->dle_next) - result->dle_next->dle_prev = 0; - - l->dll_head = result->dle_next; - - if (result == l->dll_tail) /* if the head is also the tail */ - l->dll_tail = 0; - - result->dle_next = 0; - result->dle_list = 0; - - return result; -} - -Dlelem * -DLRemTail(Dllist *l) -{ - /* remove and return the tail */ - Dlelem *result = l->dll_tail; - - if (result == 0) - return result; - - if (result->dle_prev) - result->dle_prev->dle_next = 0; - - l->dll_tail = result->dle_prev; - - if (result == l->dll_head) /* if the tail is also the head */ - l->dll_head = 0; - - result->dle_prev = 0; - result->dle_list = 0; - - return result; -} - -/* Same as DLRemove followed by DLAddHead, but faster */ -void -DLMoveToFront(Dlelem *e) -{ - Dllist *l = e->dle_list; - - if (l->dll_head == e) - return; /* Fast path if already at front */ - - Assert(e->dle_prev != 0); /* since it's not the head */ - e->dle_prev->dle_next = e->dle_next; - - if (e->dle_next) - e->dle_next->dle_prev = e->dle_prev; - else - { - /* must be the tail element */ - Assert(e == l->dll_tail); - l->dll_tail = e->dle_prev; - } - - l->dll_head->dle_prev = e; - e->dle_next = l->dll_head; - e->dle_prev = 0; - l->dll_head = e; - /* We need not check dll_tail, since there must have been > 1 entry */ -} diff --git a/src/backend/lib/lispsort.c b/src/backend/lib/lispsort.c deleted file mode 100644 index 5b1f9595734..00000000000 --- a/src/backend/lib/lispsort.c +++ /dev/null @@ -1,59 +0,0 @@ -/*------------------------------------------------------------------------- - * - * lispsort.c - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/lib/Attic/lispsort.c,v 1.17 2002/06/20 20:29:28 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include <sys/types.h> - -#include "postgres.h" - - -#ifdef NOT_USED -/* -** lisp_qsort: Takes a lisp list as input, copies it into an array of lisp -** nodes which it sorts via qsort() with the comparison function -** as passed into lisp_qsort(), and returns a new list with -** the nodes sorted. The old list is *not* freed or modified (?) -*/ -List * -lisp_qsort(List *the_list, /* the list to be sorted */ - int (*compare) ()) /* function to compare two nodes */ -{ - int i; - size_t num; - List **nodearray; - List *tmp, - *output; - - /* find size of list */ - num = length(the_list); - if (num < 2) - return copyObject(the_list); - - /* copy elements of the list into an array */ - nodearray = (List **) palloc(num * sizeof(List *)); - - for (tmp = the_list, i = 0; tmp != NIL; tmp = lnext(tmp), i++) - nodearray[i] = copyObject(lfirst(tmp)); - - /* sort the array */ - pg_qsort(nodearray, num, sizeof(List *), compare); - - /* lcons together the array elements */ - output = NIL; - for (i = num - 1; i >= 0; i--) - output = lcons(nodearray[i], output); - - return output; -} - -#endif diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c deleted file mode 100644 index 62f63a547f2..00000000000 --- a/src/backend/lib/stringinfo.c +++ /dev/null @@ -1,191 +0,0 @@ -/*------------------------------------------------------------------------- - * - * stringinfo.c - * - * StringInfo provides an indefinitely-extensible string data type. - * It can be used to buffer either ordinary C strings (null-terminated text) - * or arbitrary binary data. All storage is allocated with palloc(). - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * $Id: stringinfo.c,v 1.31 2002/06/20 20:29:28 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - - -#include "postgres.h" -#include "lib/stringinfo.h" - -/* - * makeStringInfo - * - * Create an empty 'StringInfoData' & return a pointer to it. - */ -StringInfo -makeStringInfo(void) -{ - StringInfo res; - - res = (StringInfo) palloc(sizeof(StringInfoData)); - - initStringInfo(res); - - return res; -} - -/* - * initStringInfo - * - * Initialize a StringInfoData struct (with previously undefined contents) - * to describe an empty string. - */ -void -initStringInfo(StringInfo str) -{ - int size = 256; /* initial default buffer size */ - - str->data = (char *) palloc(size); - str->maxlen = size; - str->len = 0; - str->data[0] = '\0'; -} - -/* - * enlargeStringInfo - * - * 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) -{ - int newlen; - - needed += str->len + 1; /* total space required now */ - if (needed <= str->maxlen) - return; /* got enough space already */ - - /* - * We don't want to allocate just a little more space with each - * append; for efficiency, double the buffer size each time it - * overflows. Actually, we might need to more than double it if - * 'needed' is big... - */ - newlen = 2 * str->maxlen; - while (needed > newlen) - newlen = 2 * newlen; - - str->data = (char *) repalloc(str->data, newlen); - - str->maxlen = newlen; -} - -/* - * appendStringInfo - * - * Format text data under the control of fmt (an sprintf-like format string) - * and append it to whatever is already in str. More space is allocated - * to str if necessary. This is sort of like a combination of sprintf and - * strcat. - */ -void -appendStringInfo(StringInfo str, const char *fmt,...) -{ - va_list args; - int avail, - nprinted; - - Assert(str != NULL); - - for (;;) - { - /* - * Try to format the given string into the available space; but if - * there's hardly any space, don't bother trying, just fall - * through to enlarge the buffer first. - */ - avail = str->maxlen - str->len - 1; - if (avail > 16) - { - /* - * Assert check here is to catch buggy vsnprintf that overruns - * the specified buffer length. Solaris 7 in 64-bit mode is - * an example of a platform with such a bug. - */ -#ifdef USE_ASSERT_CHECKING - str->data[str->maxlen-1] = '\0'; -#endif - - va_start(args, fmt); - nprinted = vsnprintf(str->data + str->len, avail, - fmt, args); - va_end(args); - - Assert(str->data[str->maxlen-1] == '\0'); - - /* - * Note: some versions of vsnprintf return the number of chars - * actually stored, but at least one returns -1 on failure. Be - * conservative about believing whether the print worked. - */ - if (nprinted >= 0 && nprinted < avail - 1) - { - /* Success. Note nprinted does not include trailing null. */ - str->len += nprinted; - break; - } - } - /* Double the buffer size and try again. */ - enlargeStringInfo(str, str->maxlen); - } -} - -/*------------------------ - * appendStringInfoChar - * Append a single byte to str. - * Like appendStringInfo(str, "%c", ch) but much faster. - */ -void -appendStringInfoChar(StringInfo str, char ch) -{ - /* Make more room if needed */ - if (str->len + 1 >= str->maxlen) - enlargeStringInfo(str, 1); - - /* OK, append the character */ - str->data[str->len] = ch; - str->len++; - str->data[str->len] = '\0'; -} - -/* - * appendBinaryStringInfo - * - * Append arbitrary binary data to a StringInfo, allocating more space - * if necessary. - */ -void -appendBinaryStringInfo(StringInfo str, const char *data, int datalen) -{ - Assert(str != NULL); - - /* Make more room if needed */ - enlargeStringInfo(str, datalen); - - /* OK, append the data */ - memcpy(str->data + str->len, data, datalen); - str->len += datalen; - - /* - * Keep a trailing null in place, even though it's probably useless - * for binary data... - */ - str->data[str->len] = '\0'; -} |