diff options
author | Vadim B. Mikheev <vadim4o@yahoo.com> | 1997-09-24 08:28:37 +0000 |
---|---|---|
committer | Vadim B. Mikheev <vadim4o@yahoo.com> | 1997-09-24 08:28:37 +0000 |
commit | eec610865076ba40ec46f25debebd543c0015867 (patch) | |
tree | da37b1a41f5341eabbde754d5e8fb1341782759d /src | |
parent | af5c86e2d1c4b7b212a47478996dc3bff4b78ae9 (diff) |
+ SPI_palloc(), SPI_repalloc(), SPI_pfree() - for allocations
in upper Executor memory context.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/executor/spi.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 186c0f0313e..12a511be27e 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -69,6 +69,8 @@ extern void ShowUsage(void); #endif +/* =================== interface functions =================== */ + int SPI_connect() { @@ -487,6 +489,69 @@ SPI_getrelname(Relation rel) return (pstrdup(rel->rd_rel->relname.data)); } +void * +SPI_palloc (Size size) +{ + MemoryContext oldcxt = NULL; + void *pointer; + + if (_SPI_curid + 1 == _SPI_connected) /* connected */ + { + if (_SPI_current != &(_SPI_stack[_SPI_curid + 1])) + elog(FATAL, "SPI: stack corrupted"); + oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt); + } + + pointer = palloc (size); + + if (oldcxt) + MemoryContextSwitchTo(oldcxt); + + return (pointer); +} + +void * +SPI_repalloc (void *pointer, Size size) +{ + MemoryContext oldcxt = NULL; + + if (_SPI_curid + 1 == _SPI_connected) /* connected */ + { + if (_SPI_current != &(_SPI_stack[_SPI_curid + 1])) + elog(FATAL, "SPI: stack corrupted"); + oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt); + } + + pointer = repalloc (pointer, size); + + if (oldcxt) + MemoryContextSwitchTo(oldcxt); + + return (pointer); +} + +void +SPI_pfree (void *pointer) +{ + MemoryContext oldcxt = NULL; + + if (_SPI_curid + 1 == _SPI_connected) /* connected */ + { + if (_SPI_current != &(_SPI_stack[_SPI_curid + 1])) + elog(FATAL, "SPI: stack corrupted"); + oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt); + } + + pfree (pointer); + + if (oldcxt) + MemoryContextSwitchTo(oldcxt); + + return; +} + +/* =================== private functions =================== */ + /* * spi_printtup -- * store tuple retrieved by Executor into SPITupleTable |