Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9afc648

Browse files
committed
Keep plperl's current_call_data record on the stack, instead of palloc'ing.
This at least saves some palloc overhead, and should furthermore reducethe risk of anything going wrong, eg somebody resetting the context thecurrent_call_data record was in.
1 parenta209936 commit9afc648

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,27 +1705,32 @@ plperl_call_handler(PG_FUNCTION_ARGS)
17051705
Datumretval;
17061706
plperl_call_data*save_call_data=current_call_data;
17071707
plperl_interp_desc*oldinterp=plperl_active_interp;
1708+
plperl_call_datathis_call_data;
1709+
1710+
/* Initialize current-call status record */
1711+
MemSet(&this_call_data,0,sizeof(this_call_data));
1712+
this_call_data.fcinfo=fcinfo;
17081713

17091714
PG_TRY();
17101715
{
1711-
current_call_data=NULL;
1716+
current_call_data=&this_call_data;
17121717
if (CALLED_AS_TRIGGER(fcinfo))
17131718
retval=PointerGetDatum(plperl_trigger_handler(fcinfo));
17141719
else
17151720
retval=plperl_func_handler(fcinfo);
17161721
}
17171722
PG_CATCH();
17181723
{
1719-
if (current_call_data&&current_call_data->prodesc)
1720-
decrement_prodesc_refcount(current_call_data->prodesc);
1724+
if (this_call_data.prodesc)
1725+
decrement_prodesc_refcount(this_call_data.prodesc);
17211726
current_call_data=save_call_data;
17221727
activate_interpreter(oldinterp);
17231728
PG_RE_THROW();
17241729
}
17251730
PG_END_TRY();
17261731

1727-
if (current_call_data&&current_call_data->prodesc)
1728-
decrement_prodesc_refcount(current_call_data->prodesc);
1732+
if (this_call_data.prodesc)
1733+
decrement_prodesc_refcount(this_call_data.prodesc);
17291734
current_call_data=save_call_data;
17301735
activate_interpreter(oldinterp);
17311736
returnretval;
@@ -1745,8 +1750,12 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
17451750
plperl_proc_descdesc;
17461751
plperl_call_data*save_call_data=current_call_data;
17471752
plperl_interp_desc*oldinterp=plperl_active_interp;
1753+
plperl_call_datathis_call_data;
17481754
ErrorContextCallbackpl_error_context;
17491755

1756+
/* Initialize current-call status record */
1757+
MemSet(&this_call_data,0,sizeof(this_call_data));
1758+
17501759
/* Set up a callback for error reporting */
17511760
pl_error_context.callback=plperl_inline_callback;
17521761
pl_error_context.previous=error_context_stack;
@@ -1777,14 +1786,15 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
17771786
desc.nargs=0;
17781787
desc.reference=NULL;
17791788

1789+
this_call_data.fcinfo=&fake_fcinfo;
1790+
this_call_data.prodesc=&desc;
1791+
/* we do not bother with refcounting the fake prodesc */
1792+
17801793
PG_TRY();
17811794
{
17821795
SV*perlret;
17831796

1784-
current_call_data= (plperl_call_data*)palloc0(sizeof(plperl_call_data));
1785-
current_call_data->fcinfo=&fake_fcinfo;
1786-
current_call_data->prodesc=&desc;
1787-
/* we do not bother with refcounting the fake prodesc */
1797+
current_call_data=&this_call_data;
17881798

17891799
if (SPI_connect()!=SPI_OK_CONNECT)
17901800
elog(ERROR,"could not connect to SPI manager");
@@ -2167,13 +2177,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
21672177
ReturnSetInfo*rsi;
21682178
ErrorContextCallbackpl_error_context;
21692179

2170-
/*
2171-
* Create the call_data before connecting to SPI, so that it is not
2172-
* allocated in the SPI memory context
2173-
*/
2174-
current_call_data= (plperl_call_data*)palloc0(sizeof(plperl_call_data));
2175-
current_call_data->fcinfo=fcinfo;
2176-
21772180
if (SPI_connect()!=SPI_OK_CONNECT)
21782181
elog(ERROR,"could not connect to SPI manager");
21792182

@@ -2286,13 +2289,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
22862289
HV*hvTD;
22872290
ErrorContextCallbackpl_error_context;
22882291

2289-
/*
2290-
* Create the call_data before connecting to SPI, so that it is not
2291-
* allocated in the SPI memory context
2292-
*/
2293-
current_call_data= (plperl_call_data*)palloc0(sizeof(plperl_call_data));
2294-
current_call_data->fcinfo=fcinfo;
2295-
22962292
/* Connect to SPI manager */
22972293
if (SPI_connect()!=SPI_OK_CONNECT)
22982294
elog(ERROR,"could not connect to SPI manager");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp