@@ -69,6 +69,8 @@ extern void ShowUsage(void);
69
69
70
70
#endif
71
71
72
+ /* =================== interface functions =================== */
73
+
72
74
int
73
75
SPI_connect ()
74
76
{
@@ -487,6 +489,69 @@ SPI_getrelname(Relation rel)
487
489
return (pstrdup (rel -> rd_rel -> relname .data ));
488
490
}
489
491
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
+
490
555
/*
491
556
* spi_printtup --
492
557
* store tuple retrieved by Executor into SPITupleTable
0 commit comments