mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 10:30:33 +03:00 
			
		
		
		
	+ SPI_palloc(), SPI_repalloc(), SPI_pfree() - for allocations
in upper Executor memory context.
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user