summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-06-05 19:48:09 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-06-05 19:48:09 +0000
commitc3a153afed84e29dac664bdc6123724a9e3a906f (patch)
tree8249c3dd76ddc9874656ec36f763227327c0a70e /src/backend/utils
parent24a1e20f146f3b4b88f0f5189a7631c511796310 (diff)
downloadpostgresql-c3a153afed84e29dac664bdc6123724a9e3a906f.tar.gz
Tweak palloc/repalloc to allow zero bytes to be requested, as per recent
proposal. Eliminate several dozen now-unnecessary hacks to avoid palloc(0). (It's likely there are more that I didn't find.)
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/name.c6
-rw-r--r--src/backend/utils/mmgr/README22
-rw-r--r--src/backend/utils/mmgr/mcxt.c4
3 files changed, 25 insertions, 7 deletions
diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c
index ecac8d2d50..cf4f14c3e1 100644
--- a/src/backend/utils/adt/name.c
+++ b/src/backend/utils/adt/name.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.52 2004/05/30 23:40:35 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.53 2004/06/05 19:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -358,9 +358,7 @@ current_schemas(PG_FUNCTION_ARGS)
int i;
ArrayType *array;
- /* +1 here is just to avoid palloc(0) error */
-
- names = (Datum *) palloc((list_length(search_path) + 1) * sizeof(Datum));
+ names = (Datum *) palloc(list_length(search_path) * sizeof(Datum));
i = 0;
foreach(l, search_path)
{
diff --git a/src/backend/utils/mmgr/README b/src/backend/utils/mmgr/README
index 409cfd768c..f705827c1b 100644
--- a/src/backend/utils/mmgr/README
+++ b/src/backend/utils/mmgr/README
@@ -1,4 +1,4 @@
-$PostgreSQL: pgsql/src/backend/utils/mmgr/README,v 1.5 2003/11/29 19:52:04 pgsql Exp $
+$PostgreSQL: pgsql/src/backend/utils/mmgr/README,v 1.6 2004/06/05 19:48:09 tgl Exp $
Notes about memory allocation redesign
--------------------------------------
@@ -53,6 +53,26 @@ that can be reset or deleted at strategic times within a query, such as
after each tuple.
+Some notes about the palloc API versus standard C library
+---------------------------------------------------------
+
+The behavior of palloc and friends is similar to the standard C library's
+malloc and friends, but there are some deliberate differences too. Here
+are some notes to clarify the behavior.
+
+* If out of memory, palloc and repalloc exit via elog(ERROR). They never
+return NULL, and it is not necessary or useful to test for such a result.
+
+* palloc(0) is explicitly a valid operation. It does not return a NULL
+pointer, but a valid chunk of which no bytes may be used. (However, the
+chunk might later be repalloc'd larger; it can also be pfree'd without
+error.) (Note: this behavior is new in Postgres 7.5; earlier versions
+disallowed palloc(0). It seems more consistent to allow it, however.)
+Similarly, repalloc allows realloc'ing to zero size.
+
+* pfree and repalloc do not accept a NULL pointer. This is intentional.
+
+
pfree/repalloc no longer depend on CurrentMemoryContext
-------------------------------------------------------
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index bc139a7d96..c444886e14 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.44 2003/11/29 19:52:04 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.45 2004/06/05 19:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -565,7 +565,7 @@ pfree(void *pointer)
/*
* repalloc
- *
+ * Adjust the size of a previously allocated chunk.
*/
void *
repalloc(void *pointer, Size size)