Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eec6108

Browse files
committed
+ SPI_palloc(), SPI_repalloc(), SPI_pfree() - for allocations
in upper Executor memory context.
1 parent af5c86e commit eec6108

File tree

1 file changed

+65
-0
lines changed
  • src/backend/executor

1 file changed

+65
-0
lines changed

src/backend/executor/spi.c

+65
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ extern void ShowUsage(void);
6969

7070
#endif
7171

72+
/* =================== interface functions =================== */
73+
7274
int
7375
SPI_connect()
7476
{
@@ -487,6 +489,69 @@ SPI_getrelname(Relation rel)
487489
return (pstrdup(rel->rd_rel->relname.data));
488490
}
489491

492+
void *
493+
SPI_palloc (Size size)
494+
{
495+
MemoryContext oldcxt = NULL;
496+
void *pointer;
497+
498+
if (_SPI_curid + 1 == _SPI_connected) /* connected */
499+
{
500+
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
501+
elog(FATAL, "SPI: stack corrupted");
502+
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
503+
}
504+
505+
pointer = palloc (size);
506+
507+
if (oldcxt)
508+
MemoryContextSwitchTo(oldcxt);
509+
510+
return (pointer);
511+
}
512+
513+
void *
514+
SPI_repalloc (void *pointer, Size size)
515+
{
516+
MemoryContext oldcxt = NULL;
517+
518+
if (_SPI_curid + 1 == _SPI_connected) /* connected */
519+
{
520+
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
521+
elog(FATAL, "SPI: stack corrupted");
522+
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
523+
}
524+
525+
pointer = repalloc (pointer, size);
526+
527+
if (oldcxt)
528+
MemoryContextSwitchTo(oldcxt);
529+
530+
return (pointer);
531+
}
532+
533+
void
534+
SPI_pfree (void *pointer)
535+
{
536+
MemoryContext oldcxt = NULL;
537+
538+
if (_SPI_curid + 1 == _SPI_connected) /* connected */
539+
{
540+
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
541+
elog(FATAL, "SPI: stack corrupted");
542+
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
543+
}
544+
545+
pfree (pointer);
546+
547+
if (oldcxt)
548+
MemoryContextSwitchTo(oldcxt);
549+
550+
return;
551+
}
552+
553+
/* =================== private functions =================== */
554+
490555
/*
491556
* spi_printtup --
492557
* store tuple retrieved by Executor into SPITupleTable

0 commit comments

Comments
 (0)